-1

I'm trying to save my received SMS into a string but it doesn't work. This is my error message :

recive_0_1:50:28: error: invalid conversion from 'int' to 'char' [-fpermissive] exit status 1 invalid conversion from 'int' to 'char' [-fpermissive] This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.**

#include <SoftwareSerial.h>
#include <string.h>

char message[160];  // max size of an SMS
char* text;
String data;


//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(4, 5); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM800L
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  
  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}

void loop()
{
  updateSerial();
  
}

void updateSerial()
{
 // char c;
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
    //char data=Serial.read();
    //Serial.println(data,DEC);
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
        text=mySerial.read();
      Serial.print(text);
    //}
  }

}
Puck
  • 2,080
  • 4
  • 19
  • 30
meital
  • 9

1 Answers1

0

It looks like you're running into problems from trying to convert integers to characters. I use the below code to read from my SIM card to my SIM900 device:

1st: my software serial is defined and my setup script run:

SoftwareSerial gprsSerial(7, 8);

void setup()
{
  pinMode(13, OUTPUT);
  gprsSerial.begin(19200);
  Serial.begin(19200);
  delay(200);
  // set up your AT COMMANDS HERE - I HAVE NOT INCLUDED THESE
}

Then I run my loop function as follows, calling the additional functions specified thereafter, :

void loop() {
readSMS();
delay(2000);

}

void toSerial(){
  delay(200);
  if(gprsSerial.available()>0){
    textMessage = gprsSerial.readString();
    delay(100);
    Serial.print(textMessage);    
  }
}

void readSMS() {
  textMessage = ""; 
  gprsSerial.print("AT+CSQ\r");
  toSerial();
  gprsSerial.print("AT+CMGF=1\r");
  toSerial();
  gprsSerial.println("AT+CNMI=2,2,0,0,0\r");  
  delay(2000);
  toSerial();
}

With the above you should not get any data type conversion hassles.

Hayden Eastwood
  • 928
  • 2
  • 10
  • 20