Variable in sendSms function

Hi there

I have this simple code:

#include<Sim800l.h>
Sim800l Sim800l;
int t;
void setup() {
  t=95;
  Sim800l.begin();
  Sim800l.sendSms("+1xxxxxx",t);
}
void loop() {
}

but my phone does not receive "95" ! but it receives some characters like "@"

please help me how to use a variable instead of the text of an sms in sendSms function!

try

String t="95";

won't work either

the library's API is (if working with GitHub - vittorioexp/Sim800L-Arduino-Library-revised: The SIM800L Arduino Library is a simple and easy-to-use library for the SIM800L module, allowing for quick and efficient communication with the module using the Arduino platform.)

bool Sim800L::sendSms(char* number,char* text)

so you need to pass a cString (null terminated char buffer)

either

#include<Sim800l.h>
Sim800l Sim800l;
char message[] = "42";
void setup() {
  t=95;
  Sim800l.begin();
  Sim800l.sendSms("+1xxxxxx", message);
}
void loop() {
}

or if you want to use the String class

#include<Sim800l.h>
Sim800l Sim800l;
String message = "42";
void setup() {
  Sim800l.begin();
  Sim800l.sendSms("+1xxxxxx", message.c_str()); // you might get a warning or error depending on the board you use as this is a const char* and the API expects char*
}
void loop() {
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.