Hello guys,
i'm trying to make my GSM module send SMS to the user with the temperature value gotten from a sensor but i'm having issues with my code.
i tried to concatenate a char* with a string but its giving me this error: " unable to find string literal operator 'operator""String' with 'const char [52]', 'unsigned int' arguments
"
This is the code below:
#define DHTPIN 3 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11
#define PIN_TX 8 //pin TX for GSM module
#define PIN_RX 7 //pin RX for GSM module
#define BAUDRATE 9600
#define PHONE_NUMBER "+2349**23130**" //defining phone number of the user
//initial message sent to user after initialization is successfully completed.
#define MESSAGE "System is online...\n Temperatue and Heat index:32.20°C +"temp"+ \n SELECT CROP TYPE \n 1: BEANS \n 2: RICE \n 3: YAM"
#define MESSAGE_LENGTH 5
char message[MESSAGE_LENGTH];
int messageIndex = 0;
int crops=0;
int flag=0;
char phone[16];
char datetime[24];
char temp[6];
temp is the string, I converted a temperature value from float to string using dtostrf function and the value was saved in "temp".
it does actually.
The main reason why I need to concatenate char* is because the GSM library I am using only allows char* to be sent as a text message to the user.
And the value of temperature is in float, I had to convert it to string using dtostrf function and save it to a char*.
Then I needed to concatenate it with another char* message, so the message can be sent together on the same line.
char temp[6];
dtostrf(t,6,2,temp);
//using strcpy & strcat function to concatenate char* array (//buf is the initial message sent to user after initialization is successfully completed.)
char buf[42];
const char *first = "System is online...\nTemperature:";
const char *second = temp;
strcpy(buf,first);
strcat(buf,second);
Serial.println("start to send message ..."); //GSM module has initialized sucessfully, and will attempt to send a message.
if (gprs.sendSMS(PHONE_NUMBER, buf)) { //define phone number and text
gprs.sendSMS(PHONE_NUMBER, MESSAGE2);
Serial.print("Send SMS Succeed!\r\n");
} else {
Serial.print("Send SMS failed!\r\n");
delay(2000);
}
Yes, you're right, but how to concatenate/convert char* ("C strings") and "String"s it's a general programming question, even if in this specific case you're applying it to GSM.
Anyway, I'm happy to see you solved it. HGC (Have a Good Coding)!