Arduino Uno + Gsm Shield issue: unresponsive
hi,
i'm using arduino uno + gsm shield in project that aims @ controlling instrument remotely. runs continuously without problems first week approximately, after uno seems unresponsive , not process sms received , looks unresponsive. way in order normal functioning pushing reset button on uno board.
i don't know whether can understand issue, when call mobile number, line ok.
thank help
the following code:
i'm using arduino uno + gsm shield in project that aims @ controlling instrument remotely. runs continuously without problems first week approximately, after uno seems unresponsive , not process sms received , looks unresponsive. way in order normal functioning pushing reset button on uno board.
i don't know whether can understand issue, when call mobile number, line ok.
thank help
the following code:
code: [select]
# www.biemmeitalia.net
#include <gsm.h>
#include <memoryfree.h> //library calculate free memory
#define watchdog 1 //commentare questa riga per disabilitare il watchdog
#ifdef watchdog
#include <avr/wdt.h> //watchdog library
#endif
//#define debug 1
#define soglia_memoria_disponibile 600
#define sendsms 1
#define pin_sondatemp 1
#define pincaldaia_on 8
#define pin_temp_minima 9
#define ledantigelo 4
#define pinalarm 10
//impostazione da pulsanti su box
#define pin_on 5
#define pin_off 6
//numero di campionamenti analogica
#define num_letture_an 30
#define set_temp 2.0
#define delta 5.0
// initialize library instances
gsm gsmaccess;
gsm_sms sms;
char sendernumber[20];
char remotenumm[20]="33912345678";
char remotenumcliente[20]="34712345677";
byte flagabilitalogica = 1;
byte flagsmsallarme = 0;
byte flagsmsricevutoon = 0;
byte flagsmsricevutooff= 0;
byte flagtempsottozero = 0;
byte flagtempnegativa = 0;
byte flagsmsdestinatariom = 0;
//stato letture pin digitali
byte statopinon = 0;
byte statopinoff = 0;
byte statopinalarm = 0;
//logica temperatura
int count = 0;
unsigned long cum = 0;
int reading;
double temp_avg = 150.0;
double temperaturec = 15.0;
void setup()
{
#ifdef debug
serial.begin(9600);
#endif
#ifdef debug
serial.println("init pins");
#endif
pinmode(pincaldaia_on, output);
pinmode(pin_temp_minima, output);
pinmode(pinalarm, input_pullup);
pinmode(ledantigelo,output);
pinmode(pin_on, input_pullup);
pinmode(pin_off,input_pullup);
digitalwrite(pincaldaia_on,low);
digitalwrite(pin_temp_minima,low);
// connection state
boolean notconnected = true;
// start gsm connection
while(notconnected)
{
if(gsmaccess.begin()==gsm_ready)
notconnected = false;
else
{
#ifdef debug
serial.println("not connected");
#endif
delay(1000);
logicatemperatura();
}
}
#ifdef debug
serial.println("gsm initialized");
serial.println("waiting messages");
#endif
delay(1000);
#ifndef watchdog
sendalarmsms("enel riattivato.");
#endif
#ifdef watchdog
wdt_enable(wdto_8s);
#endif
}
void loop()
{
string smstextreceived;
char c;
// if there smss available()
if (sms.available()){
serial.println("message received from:");
sms.remotenumber(sendernumber, 20);
#ifdef debug
serial.println(sendernumber);
#endif
smstextreceived="";
while(c=sms.read()){
smstextreceived+=c;
#ifdef debug
serial.print(c);
#endif
}
#ifdef debug
serial.println("\nend of message");
#endif
// delete message modem memory
sms.flush();
#ifdef debug
serial.println("message deleted");
#endif
//se ricevo un sms con il testo "on"
if (smstextreceived.equalsignorecase("on")){
flagsmsricevutoon = 1;
}
if (smstextreceived.equalsignorecase("off")){
flagsmsricevutooff = 1;
}
if (smstextreceived.equalsignorecase("mario")){
flagsmsdestinatariom = 1;
sendalarmsms_m("messaggi diretti m.");
}
if (smstextreceived.equalsignorecase("cliente")){
flagsmsdestinatariom = 0;
sendalarmsms_m("messaggi diretti al c.");
}
if (smstextreceived.equalsignorecase("temp")){
char messaggio[100];
string mess;
string str_intero;
string str_virgola;
int intero;
int virgola;
serial.println(temperaturec);
flagtempnegativa = 0;
if (temperaturec < 0){
flagtempnegativa = 1;
temperaturec = abs(temperaturec);
}
intero = (int)temperaturec;
virgola = (int)((temperaturec - (double)intero)*100.0);
#ifdef debug
serial.println(intero);
serial.println(virgola);
#endif
str_intero = string(intero);
str_virgola = string(virgola);
if (flagtempnegativa == 0){
mess = string("temperatura corrente: " + str_intero + "," + str_virgola);
}else{
mess = string("temperatura corrente: -" + str_intero + "," + str_virgola);
}
mess.tochararray(messaggio, mess.length());
sendalarmsms(messaggio);
delay(100);
}
}
statopinon = digitalread(pin_on);
statopinoff = digitalread(pin_off);
if ((flagsmsricevutoon) || (statopinon == low)){
#ifdef debug
serial.println("on");
#endif
digitalwrite(pincaldaia_on, high);
digitalwrite(pin_temp_minima, low);
digitalwrite(ledantigelo,low);
flagabilitalogica = 0;
sendalarmsms("caldaia attiva da termostato ambiente.");
}else{
if ((flagsmsricevutooff) || (statopinoff == low)){
#ifdef debug
serial.println("off");
#endif
digitalwrite(pincaldaia_on, low);
digitalwrite(ledantigelo,high);
cum = 0; //azzera la variabile per il calcolo delle temp medie
flagabilitalogica = 1;
count = 0;
sendalarmsms("abilitazione temperatura minima.");
}
}
logicatemperatura();
delay(10);
statopinalarm = digitalread(pinalarm);
if (statopinalarm == low){
if (!flagsmsallarme){
sendalarmsms("blocco.");
flagsmsallarme=!flagsmsallarme;
}
}else{
flagsmsallarme=0;
}
flagsmsricevutoon = 0;
flagsmsricevutooff = 0;
#ifdef watchdog
int mem = freememory();
if (mem > soglia_memoria_disponibile){
wdt_reset();
}
#endif
}
void logicatemperatura(){
if (count < num_letture_an){
count++;
reading = analogread(pin_sondatemp);
cum += reading;
}
else{
temp_avg = (double)cum/(double)num_letture_an;
double voltage = temp_avg * 5.0;
voltage /= 1024.0;
temperaturec = ((voltage - 0.5) * 100)-5.0 ;
#ifdef debug
serial.print(temperaturec);
serial.println(" degrees c");
#endif
if (flagabilitalogica){
if (temperaturec < set_temp){
#ifdef debug
serial.println("temp bassa");
#endif
digitalwrite(pin_temp_minima, high);
}else if (temperaturec > set_temp + delta){
#ifdef debug
serial.println("temp alta");
#endif
digitalwrite(pin_temp_minima, low);
}
}
count = 0;
cum = 0;
}
}
void sendalarmsms(char * txtmsg){
#ifdef sendsms
#ifdef debug
serial.println("spedisco:");
serial.println();
serial.println("il seguente messaggio:");
serial.println(txtmsg);
#endif
if (flagsmsdestinatariom){
sms.beginsms(remotenumm);
}else{
sms.beginsms(remotenumcliente);
}
sms.print(txtmsg);
sms.endsms();
#ifdef debug
serial.println("\nspedito!\n");
#endif
#endif
delay(10);
}
void sendalarmsms_m(char * txtmsg){
#ifdef sendsms
#ifdef debug
serial.println("spedisco:");
serial.println();
serial.println("il seguente messaggio:");
serial.println(txtmsg);
#endif
sms.beginsms(remotenumm);
sms.print(txtmsg);
sms.endsms();
#ifdef debug
serial.println("\nspedito!\n");
#endif
#endif
delay(10);
}
any ideas?
thanks
elle
thanks
elle
Arduino Forum > Products > Arduino GSM Shield (Moderator: fabioc84) > Arduino Uno + Gsm Shield issue: unresponsive
arduino
Comments
Post a Comment