Hey,
so I got this function called "SendSMS" from a GSM Library:
char SMSGSM::SendSMS(char *number_str, char *message_str)
Now I have two floats from two water pressure sensors and I want to connect them with a string so that my SMS is:
Pressure Pump 1: 1.123 Bar, Pressure Pump 2: 4.456 Bar
where 1.123 and 4.456 are the float variables and the rest is plain text.
I've tried it like this but somehow it doesn't work..
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
float Pressure1, Pressure2
char sms_text_1[5];
char sms_text_2[5];
String sms_text_str;
char sms_text[150];
//Serial begin with sms module, left out
dtostrf(Pressure1, 5, 2,sms_text_1);
dtostrf(Pressure2, 5, 2,sms_text_2);
sms_text_str="Pressure Pump 1: "+(String)sms_text_1+" Bar, Pressure Pump 2: "+(String)sms_text_2+" Bar";
sms_text_str.toCharArray(sms_text, 50);
sms.SendSMS(phonenumber1, sms_text);
Can you help me?
blh64
June 23, 2020, 10:08pm
2
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
float Pressure1, Pressure2
char sms_text_1[5];
char sms_text_2[5];
String sms_text_str;
char sms_text[150];
//Serial begin with sms module, left out
dtostrf(Pressure1, 5, 2, sms_text_1);
dtostrf(Pressure2, 5, 2, sms_text_2);
strcpy(sms_txt, "Pressure Pump 1: ");
strcat(sms_txt, sms_text_1 );
strcat(sms_txt, " Bar, Pressure Pump 2: ");
strcat(sms_txt, sms_text_2 );
strcat(sms_txt, " Bar");
sms.SendSMS(phonenumber1, sms_text);
Avoid using the String class. As a further optimization, you don't need both sms_text_1 and _2 if you do the second conversion after copying the results.
gcjr
June 23, 2020, 10:54pm
3
why not send the pressure values as integers, milliBar = 1000 * Bar
So when I use Integer for the pressure, is the following code correct?
//PRESSURE AS INT
int P1,P2;
float V1, V2
P1=(V1-Offset1)*4000;
P2=(V2-Offset2)*4000;
strcpy(sms_text, "Pressure Pump 1: ");
strcat(sms_text, P1/1000);
strcat(sms_text, ".");
strcat(sms_text, P1%1000);
strcat(sms_text, " Bar, Pressure Pump 2: ");
strcat(sms_text, P2/1000);
strcat(sms_text, ".");
strcat(sms_text, P2%1000);
strcat(sms_text, " Bar");
The output should be:
Pressure Pump 1: 1.123 Bar, Presssure Pump 2: 4.456 Bar
And is it correct when I say that strcpy(var, "value") assigns the "value" to var, no matter what was assigned beforehand?
P1%1000
No.
Think about leading zeroes.
Just send it as an integer, just not necessarily as an "int"