impossible to send variable in sms.send(n, var)

Hi every body
i’m a french beginner in arduino

i’ve make a project.
in it, i want to measure the 5v value of alimentation.
but i cannot send the variable versus sms
i’m not the only one it seems…
i try sprintf but it bug and send me a “?” in my string so i take dtostrf…
it’s make me crazy, println work well, my string write “5.00 Volts” but impossible to send it with sms.send
my matérial :
atmega2560+icomsat 1.1 (sim900) with sim900.h

tension5v is the float, tension_string, the convertion result

int valeurLue = 0 ;
float tension5v ;
int sensorPin5v = A0;

char message_temp_sms[30];
valeurLue = analogRead(sensorPin5v);
tension5v = valeurLue * 5/1023 ;
char tension_string[10];
dtostrf(tension5v,1,2,tension_string);
String sms_temp =String(tension_string) + String(" Volts");
Serial.println(sms_temp); // Serial.println schow correctly " 5.00 Volts"
if (sms.SendSMS(n, sms_temp)) // bug at each time ! impossible to know why !
Serial.println("\nSMS sent OK");

error written
mygsm33.ino: In function ‘void analyse_sms()’:
mygsm33:458: error: no matching function for call to ‘SMSGSM::SendSMS(char [20], String&)’
C:\Program Files\Arduino\libraries\Shield_from_icomsat/sms.h:9: note: candidates are: char SMSGSM::SendSMS(char*, char*)
C:\Program Files\Arduino\libraries\Shield_from_icomsat/sms.h:10: note: char SMSGSM::SendSMS(byte, char*)

thank you, i’ve do what i can
but i don’t find the solution of the error !!!

please, thank you for your help … actually, i send only the value 5.00 but it will be better like"5.00 Volts"

bruno from France

Sorry for the orthographic faults… :slight_smile:

From the error message it looks like the SendSMS function expects the second parameter to be a pointer to a C style string, ie a null terminated array of chars. You are using a String

String sms_temp =String(tension_string) + String(" Volts");
Serial.println(sms_temp);               // Serial.println schow correctly " 5.00 Volts"
if (sms.SendSMS(n, sms_temp))     // bug at each time ! impossible to know why !

You have the voltage in the tension_string variable so why not use it ? Use sprintf() to concatenate it with the text " Volts" then use the combined string in the sendSMS function.

As a quick test try using the tension_string array in the sendSMS() function to see whether it works.

Try this

char message_temp_sms[30];
valeurLue = analogRead(sensorPin5v);
tension5v = valeurLue * 5/1023 ;
sprintf(message_temp_sms,"%d Volts",tension5v);
Serial.println(message_temp_sms);   // Serial.println schow correctly " 5.00 Volts"
sms.beginSMS(n);
sms.print(message_temp_sms);
sms.endSMS();

HI KenF
thank you for helping me
i just try...
:wink:

it is not the first time that cde sms.begin... do not wok i think it depend shield's library;
icomsat is not the better at level compatibility of fer command

it stop on the line " sms.beginSMS(n);"
with error :"class SMSGSM" has no member named 'beginSMS'

mygsm34.ino: In function 'void analyse_sms()':
mygsm34:461: error: 'class SMSGSM' has no member named 'beginSMS'
mygsm34:462: error: 'class SMSGSM' has no member named 'print'
mygsm34:463: error: 'class SMSGSM' has no member named 'endSMS'

You need to post ALL of your code. I have been assuming you have something like this at the top of your code

#include <GSM.h>
GSM_SMS sms;

But you really should post your ENTIRE sketch within code tags

i use for information the IDE 1.05-r2
i try and find something…
with sprintf, i do not put the %s at the good place in the lin

work :
sprintf(message_temp_sms, “Valeur du 5V : %s”, tension_string);

not work !!! why ? pff i do not know !
sprintf(message_temp_sms, "Valeur du 5V : ", “%s”, tension_string);

incredible ! it make me crazy !
i will inspired by source find on the net… !!! perhaps with errors …

it smell good…

now … print correctly “Valeur du 5v: 5.0” but not Volts behind !

#include <string.h>
#include “SIM900.h”
#include <SoftwareSerial.h>
#include “sms.h”
SMSGSM sms;

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

int GSMOnPIN = 9;
int valeurLue = 0;
float tension5v ;
int sensorPin5v = A0;

void setup()
{
powerUpOrDown();
pinMode (sensorPin5v, INPUT);
Serial.begin(9600);
Serial.println(“Init. GSM Shield”);
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
if(started)
{
// if (sms.SendSMS(“0677855000”, “Arduino SMS”))
// Serial.println("\nSMS sent OK");
}
delsms(); // delete sms in sim
}

void loop()
{
int pos=0;
if(started){
pos=sms.IsSMSPresent(SMS_ALL);
if(pos){
Serial.println("IsSMSPresent at pos ");
Serial.println(pos);
sms.GetSMS(pos,n,smsbuffer,100);
Serial.println(n);
Serial.println(smsbuffer);
analyse_sms();
}
else{
}
}
}

void analyse_sms()
{
if(!strcmp(smsbuffer,“tension 5v”)) {
Serial.println(“Value of the 5V power supply”);
valeurLue = analogRead(sensorPin5v);
tension5v = valeurLue * 5.0/1023; // 4.887585/1000; //produit en croix, donne un résultat en mV !
char message_temp_sms[30];
char message_temp_sms2[30];
char tension_string[10];
dtostrf(tension5v,1,2,tension_string); // float to string
String sms_temp[0]=0;
sprintf(message_temp_sms, “Valeur du 5V : %s”, tension_string, “%s”, " Volts");
Serial.println(message_temp_sms);
if (sms.SendSMS(n, message_temp_sms )) // print “Valeur du 5v: 5.0” but not Volts behind !
delay(2000);
Serial.println("\nSMS sent OK");
delsms();
}
else {
if (sms.SendSMS(n, “Unknow Command !”)) // ajout suite à correctif, avt c’etait ok
delay(2000);
delsms();
}
}

void powerUpOrDown()
{
Serial.println(“power on of shield gsm”);
pinMode(GSMOnPIN, OUTPUT);
digitalWrite(GSMOnPIN, HIGH); // sets the GSM on
delay(600);
digitalWrite(GSMOnPIN, LOW);
delay(10000);
}

void delsms(){
Serial.println(“delsms”);
for (int i=0; i<10; i++){ //do it max 10 times
int pos=sms.IsSMSPresent(SMS_ALL);
if (pos!=0){
Serial.print("\nFind SMS at the pos “);
Serial.println(pos);
if (sms.DeleteSMS(pos)==1){
Serial.print(”\nDeleted SMS at the pos “);
Serial.println(pos);
}
else
{
Serial.print(”\nCant del SMS at the pos ");
Serial.println(pos);
}
}
}
}

try this

#include <string.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

int GSMOnPIN = 9;
int valeurLue = 0;
float tension5v  ;
int sensorPin5v = A0;

void setup()
{
  powerUpOrDown();
  pinMode (sensorPin5v, INPUT);
  Serial.begin(9600);
  Serial.println("Init. GSM Shield");
  if (gsm.begin(2400)) {
    Serial.println("\nstatus=READY");
    started=true;
  }
  else Serial.println("\nstatus=IDLE");
  if(started)
  {
    //  if (sms.SendSMS("0677855000", "Arduino SMS"))
    // Serial.println("\nSMS sent OK");
  }
  delsms(); // delete sms in sim
}

void loop()
{
  int pos=0;
  if(started){
    pos=sms.IsSMSPresent(SMS_ALL);
    if(pos){
      Serial.println("IsSMSPresent at pos ");
      Serial.println(pos);
      sms.GetSMS(pos,n,smsbuffer,100);
      Serial.println(n);
      Serial.println(smsbuffer);
      analyse_sms();
    }
    else{   
    }
  }
}

void analyse_sms()
{
  if(!strcmp(smsbuffer,"tension 5v")) {
    Serial.println("Value of the 5V power supply");
    valeurLue = analogRead(sensorPin5v);
    tension5v = valeurLue * 5/1023; // 4.887585/1000; //produit en croix, donne un résultat en mV !
    int unites=tension5v;
    int dixiemes=(tension5v*10.0);
    dixiemes=dixiemes%10;

    char message_temp_sms[30];
    sprintf(message_temp_sms,"Valeur du 5V : %d.%d Volts", unites, dixiemes);
    Serial.println(message_temp_sms);
    if (sms.SendSMS(n, message_temp_sms ))   // print "Valeur du 5v: 5.0" but not Volts behind !
      delay(2000);
    Serial.println("\nSMS sent OK");
    delsms();
  }   
  else    {
    if (sms.SendSMS(n, "Unknow Command !")) // ajout suite à correctif, avt c'etait ok
      delay(2000);
    delsms();
  }
}

void powerUpOrDown() 
{ 
  Serial.println("power on of shield gsm");
  pinMode(GSMOnPIN, OUTPUT);
  digitalWrite(GSMOnPIN, HIGH);   // sets the GSM on
  delay(600);               
  digitalWrite(GSMOnPIN, LOW);   
  delay(10000);
}


void delsms(){
  Serial.println("delsms");
  for (int i=0; i<10; i++){  //do it max 10 times
    int pos=sms.IsSMSPresent(SMS_ALL);
    if (pos!=0){
      Serial.print("\nFind SMS at the pos ");
      Serial.println(pos);
      if (sms.DeleteSMS(pos)==1){   
        Serial.print("\nDeleted SMS at the pos ");
        Serial.println(pos);     
      }
      else
      {
        Serial.print("\nCant del SMS at the pos ");
        Serial.println(pos);         
      }
    }
  }
}

Hi KenF
So scriptf can work just like this .... only this !! lol

sprintf(message_temp_sms, "Valeur du 5V : %s Volts" , tension_string);

the party conversion float / string worked already well but by looking at the way you treat(manipulate) the sriptf with % I had the idea to modify simply mine without adding the part unité; dixieme because this part worl well, the float is correctly put in string.

thank you for your help which did well me to reflect and especially managed to run my script.

thank you for having set of your time(weather) to help me

Bruno

You’re welcome. :slight_smile:

hello !!! it's again me
i continue my little way...and what ? when i want to send 20.22 dégré of my tmp36... it bug again with same code
bug with your code also ;-(
roooooooo
the probleme is that there is no raz of variable
i put ...
char message_temp_sms[30]="";

instead of

char message_temp_sms[30];

and no more problem !!!

for the moment...

bye

:slight_smile:

Hi Bruno,

I am also trying to send a variable as sms.
I did try with above logic of yours, but it did not work.

Can you please share your arduino sketch and also the SIM900 Library which you used for this thing to work?

Thank you
Parma

Can you please share your arduino sketch

This thread has been idle for more than two years. Do you suppose that Bruno is still monitoring it?

Post YOUR code, and do a better job of explaining the problem than "it didn't work".

check my code, it is working

#include <SoftwareSerial.h>
#include <String.h>
#include <Wire.h>
#include “LowPower.h”
#include “RTClib.h”
#include “SIM900.h”
#include “sms.h”

SMSGSM sms;
RTC_DS1307 RTC;

//Sensor
#define MEDIA_VELOCIDAD_SONIDO 0.017175 // Mitad de la velocidad del sonido a 20 °C expresada en cm/µs
#define PIN_TRIGGER 5
#define PIN_ECHO 6
#define ESPERA_ENTRE_LECTURAS 1000 // tiempo entre lecturas consecutivas en milisegundos
#define TIMEOUT_PULSO 25000 // la espera máxima de es 30 ms o 30000 µs
float distancia;
unsigned long tiempo;
unsigned long cronometro;
unsigned long reloj=0;

//2G
byte counter = 1;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

//debug begin
char sms_position;
char phone_number[20]; // array for the phone number string
char sms_text[100]="";
int i;

//Bateria
const int bateria = 0; // analog 0 conectado a voltage de baterias
float voltimetro = 0;
int porcevolt = 0;

//Puerta electrica
const int sencender = 5; //encender sensores

//Tiempos
int dia = 0;
int mes = 0;

void setup()//-------------*******************************----------------------------------
{
Serial.begin(9600);
Wire.begin();
RTC.begin();

//descomentar ajusta la hora y la fecha con la del ordenador (se ajusta siempre que enciende el arduino)
//RTC.adjust(DateTime(DATE, TIME));

//encender SIM800L y sensor HY-SRF05
pinMode(sencender, OUTPUT);

//Sensor
pinMode(PIN_ECHO,INPUT);
pinMode(PIN_TRIGGER,OUTPUT);
digitalWrite(PIN_TRIGGER,LOW); // Para «limpiar» el pulso del pin trigger del módulo
delayMicroseconds(2);
}

void dormir (){
Serial.println(“A dormir…”);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}

void sensardistancia(){
cronometro=millis()-reloj;
if(cronometro>ESPERA_ENTRE_LECTURAS)
{
digitalWrite(PIN_TRIGGER,HIGH); // Un pulso a nivel alto…
delayMicroseconds(20); // …durante 10 µs y
digitalWrite(PIN_TRIGGER,LOW); // …volver al nivel bajo
tiempo=pulseIn(PIN_ECHO,HIGH,TIMEOUT_PULSO); // Medir el tiempo que tarda en llegar un pulso
distancia=MEDIA_VELOCIDAD_SONIDO*tiempo;
Serial.print(distancia);
Serial.println(" cm");
reloj=millis();
}
}

void medirvolt(){
voltimetro= analogRead(bateria);
voltimetro=voltimetro*5/1024;

Serial.print(voltimetro);
Serial.print(" Volts “);
/* porcevolt = (voltimetro / 4.2) * 100 + 3.3;
Serial.print(porcevolt);
Serial.print(”% de 5V");*/
Serial.println();
}

void imprimirdia(){
//imprimir tiempo
DateTime now = RTC.now();
//Imprimimos el dia
Serial.print(now.day(), DEC);
Serial.print(’/’);
//Imprimimos el mes
Serial.print(now.month(), DEC);
Serial.print(’/’);
//Imprimimos el año
Serial.print(now.year(), DEC);
Serial.print(’ ‘);
//Imprimimos la hora
Serial.print(now.hour(), DEC);
Serial.print(’:’);
//Imprimimos los minutos
Serial.print(now.minute(), DEC);
Serial.print(’:’);
//Imprimimos los segundos
Serial.print(now.second(), DEC);
Serial.println();
}

void enviarsms()
{
char distanciast[10];
char voltimetrost[10];
dtostrf(distancia,1,2,distanciast); // float to string
dtostrf(voltimetro,1,2,voltimetrost); // float to string
sprintf(sms_text,“Botellas: %s cm, baterias: %s v”, distanciast,voltimetrost);
sms.SendSMS("+56955147132",sms_text);
Serial.println(sms_text);
Serial.println("\nSMS sent OK");
}

void loop()//-------------*******************************----------------------------------
{
//digitalWrite(sencender,HIGH);
//digitalWrite(sencender,LOW);

//se sensó hoy? > leer epromm >
//SI > sleep 8s
//NO > encender sistemas> delay 2000 (esperar conectarse a la red) >
//medir distancia > medir voltaje > enviar SMS > escribir el dia en la epromm

if(counter==1){
Serial.println(“GSM Shield testing.”);
if (gsm.begin(4800))
{
Serial.println("\nstatus = READY");
//enviarsms();
}
// else
//Serial.println("\nstatus = IDLE");

// digitalWrite(sencender,HIGH);
//imprimirdia();
medirvolt();
sensardistancia();
enviarsms();
counter =0;
}
// digitalWrite(sencender,LOW);
//dormir();

imprimirdia();
medirvolt();
sensardistancia();

char distanciast[10];
char voltimetrost[10];
dtostrf(distancia,1,2,distanciast); // float to string
dtostrf(voltimetro,1,2,voltimetrost); // float to string
sprintf(sms_text,“Botellas: %s cm, baterias: %s v”, distanciast,voltimetrost);
Serial.println(sms_text);
delay(5000);
}