I'm new to Arduino , using an Arduino UNO
I'm connecting a temperature detector to one arduino UNO and SIM808 .
The point of the ^program is that when he receives an SMS command "T?" , he analyses the temperature ans send back the information.
My program is working but not as I would like, because it is sending back a weird message: " D","+3376852 " which is the beginning of the number it's sending to.
I think it's a problem of compatibility between the two libraries. Could someone help me please ?
Here is my program:
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#include<String.h>
#define PHONE_NUMBER "+33768522026"
//variable analysant temperature espace
float temp;
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0; //initialisation de l'index des messages Ă 0 (entier)
char phone[16];
char datetime[24];
String msg; //introduction de la variable msg en tant que chaîne
#define PIN_TX 10 //les branchements nécessaires sur la UNO
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial); //pareillement pour la SIM808
//DFRobot_SIM808 sim808(&Serial);
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
while(!sim808.init()) { //tant que la sim n'est pas initialisee renvoi de "error"
Serial.print("Sim808 init error\r\n");
delay(1000); //laps de temps pour ne pas que le programme s'emballe trop vite
}
delay(3000);
Serial.println("Init Success, please send me an SMS"); //si initialisation effective renvoie de l'info
}
void loop() {
//Analyse de la température de l'espace
temp = analogRead(1)*5*100/1024.00;
Serial.print("The temperature is ");
Serial.println(temp);
int TEMPERATURE;
TEMPERATURE = temp ;
int x;
//detecting unread sms command
messageIndex = sim808.isSMSunread(); //affiche le nbr de messages s'il y en a un non lu, sinon affiche 0
Serial.print("Nombre de SMS non lus : ");
Serial.println(messageIndex);
//si commande reçue
if (messageIndex > 0) { //si index != 0 (index forcement positif)
sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime); //envoi des infos du SMS sur le moniteur série
Serial.println(datetime);
Serial.println("Sim808 read success");
Serial.println("Start to send message ...");
msg = message;
//check si Température demandée "T?"
x = msg.indexOf("T?");
Serial.println("T = "+String(x));
if (x>=0) {
sim808.sendSMS(PHONE_NUMBER, TEMPERATURE);
}
}
sim808.deleteSMS(messageIndex);
}
//delay(1000);
The copy of the library I found on GitHub sends an SMS message using a C string, you're passing an int instead. Does the compiler show a warning?
When I put ' string' instead it says that it's not in the library DFRobot
Post the code that gives you that error.
#include <DHTStable.h>
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#include<String.h>
#define PHONE_NUMBER "+33768522026"
//variable analysant temperature espace
char TEMPERATURE ;
char HUMIDITE ;
DHTStable DHT;
#define DHT11_PIN 5
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0; //initialisation de l'index des messages Ă 0 (entier)
char phone[16];
char datetime[24];
String msg; //introduction de la variable msg en tant que chaîne
#define PIN_TX 10 //les branchements nécessaires sur la UNO
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial); //pareillement pour la SIM808
//DFRobot_SIM808 sim808(&Serial);
void setup() {
pinMode(5,INPUT);
mySerial.begin(9600);
Serial.begin(9600);
while(!sim808.init()) { //tant que la sim n'est pas initialisee renvoi de "error"
Serial.print("Sim808 init error\r\n");
delay(1000); //laps de temps pour ne pas que le programme s'emballe trop vite
}
delay(3000);
Serial.println("Init Success, please send me an SMS"); //si initialisation effective renvoie de l'info
}
void loop() {
//Analyse de la température de l'espace
int x;
//detecting unread sms command
messageIndex = sim808.isSMSunread(); //affiche le nbr de messages s'il y en a un non lu, sinon affiche 0
Serial.print("Nombre de SMS non lus : ");
Serial.println(messageIndex);
//si commande reçue
if (messageIndex > 0) { //si index != 0 (index forcement positif)
sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime); //envoi des infos du SMS sur le moniteur série
Serial.println(datetime);
Serial.println("Sim808 read success");
Serial.println("Start to send message ...");
msg = message;
//check si Température demandée "T?"
x = msg.indexOf("T?");
Serial.println("T = "+String(x));
if (x>=0) {
TEMPERATURE = (DHT.getTemperature(),5);
Serial.println(TEMPERATURE);
sim808.sendSMS(PHONE_NUMBER, TEMPERATURE);
}
else {
//Check si Humidité demandée
x = msg.indexOf("Hr?");
Serial.println("Hr = "+String(x));
if (x>=0) {
HUMIDITE = (DHT.getHumidity(),5);
Serial.println(HUMIDITE);
sim808.sendSMS(PHONE_NUMBER,HUMIDITE);
}
}
}
sim808.deleteSMS(messageIndex);
}
//delay(1000);
I tried with char instead but I got empty sms in return
The version of the library I looked at expects a null terminated array of char. You're trying to give it a single char instead, so I expect the compiler barfed.
1 Like
Okay thanks, but what shall I put instead?
Eventually, you will need to use sprintf or dtostrf to get a string to send. But for an initial test you can use a fixed string:
sim808.sendSMS(PHONE_NUMBER, "25.6");
okay thanks, the initial test works , so I put sim808.sendSMS(dtostrf(TEMPERATURE)) is that right? Or I initialize TEMPERATURE with this function? I'm not sure to understand
An example/explanation of how to use it is here.
2 Likes
system
Closed
October 29, 2021, 12:57pm
11
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.