Hello good afternoon community, I have a problem that is really driving me crazy.
The following code processes a sms, separates it and saves it, then I need to read it and here is the problem, which is checked when the eeprom.get is called and does not return to the loop (). If in the code I cancel the line of eeprom.get the program finishes saving the data and returns to the loop ().
The truth is that I do not know where the error is. Any help more than appreciated.
#include <EEPROM.h>
#include <Separador.h>
#include <Sim800l.h>
#include <SoftwareSerial.h>
Sim800l Sim800l;
Separador S;
String textSms, numberSms;
bool error;
////////////////////////////////// Estructura para agendar administradores (Max 3 usuarios) //////////////////////////////////
struct Administradores
{ String aDnumero1 ;
String aDnumero2 ;
String aDnumero3 ;
} ;
////////////////////////////////////// Estructura para agendar avisos (Max 5 usuarios) //////////////////////////////////////
struct Avisos
{ String aVnumero1 ;
String aVnumero2 ;
String aVnumero3 ;
String aVnumero4 ;
String aVnumero5 ;
} ;
void setup() {
Serial.begin(9600);
Sim800l.begin();
Sim800l.reset();
error=Sim800l.delAllSms();
}
void loop() {
Serial.println("Esta el bucle en funcionamiento a la espera de otro msj");
textSms = Sim800l.readSms(1);
if (textSms.length() > 7)
{
numberSms = Sim800l.getNumberSms(1);
textSms.toUpperCase();
if (textSms.indexOf("ATC") != -1) {
Serial.println("Se recibio el comando para agregar administradores");
delay(500);
agenAdm();
}
else if (textSms.indexOf("ATA") != -1) {
Serial.println("Se recibio el comando para agregar numeros de avisos");
delay(50);
agenAvi();
}
else {
Serial.println("Comando no compatible");
}
Sim800l.delAllSms();
}
}
void agenAdm() {
String datosRecibidos = Sim800l.readSms(1);
String elemento1 = S.separa(datosRecibidos, ',', 5);
String elemento2 = S.separa(datosRecibidos, ',', 6);
String elemento3 = S.separa(datosRecibidos, ',', 7);
delay(500);
Serial.println("Numero 1 recibido: " + elemento1);
Serial.println("Numero 2 recibido: " + elemento2);
Serial.println("Numero 3 recibido: " + elemento3);
Administradores datosVarADM;
{
Administradores Datos ;
datosVarADM.aDnumero1 = elemento1 ;
datosVarADM.aDnumero2 = elemento2 ;
datosVarADM.aDnumero3 = elemento3 ;
};
Serial.print("Esto se grabara en numero 1: "); Serial.print(datosVarADM.aDnumero1) ;
Serial.println("");
Serial.print("Esto se grabara en numero 2: "); Serial.print(datosVarADM.aDnumero2) ;
Serial.println("");
Serial.print("Esto se grabara en numero 3: "); Serial.print(datosVarADM.aDnumero3) ;
Serial.println("");
int eeAddress = 0;
EEPROM.put(eeAddress, datosVarADM);
Serial.println("Se han guardado los numeros!\n");
delay(500);
Serial.println("Ahora leo la agenda!");
eeAddress = 0;
Administradores leoDatosADM;
EEPROM.get(eeAddress, leoDatosADM);
Serial.println("Agenda de administradores:\n");
Serial.print("Numero 1:"); Serial.println(leoDatosADM.aDnumero1);
Serial.print("Numero 2:"); Serial.println(leoDatosADM.aDnumero2);
Serial.print("Numero 3:"); Serial.println(leoDatosADM.aDnumero3);
Sim800l.delAllSms();
//Env();
}
void agenAvi() {
String datosRecibidos = Sim800l.readSms(1);
String elemento1 = S.separa(datosRecibidos, ',', 5);
String elemento2 = S.separa(datosRecibidos, ',', 6);
String elemento3 = S.separa(datosRecibidos, ',', 7);
String elemento4 = S.separa(datosRecibidos, ',', 8);
String elemento5 = S.separa(datosRecibidos, ',', 9);
Serial.println("Numero 1 recibido: " + elemento1);
Serial.println("Numero 2 recibido: " + elemento2);
Serial.println("Numero 3 recibido: " + elemento3);
Serial.println("Numero 4 recibido: " + elemento4);
Serial.println("Numero 5 recibido: " + elemento5);
Avisos datosVarAVI;
{
Avisos Datos ;
datosVarAVI.aVnumero1 = elemento1 ;
datosVarAVI.aVnumero2 = elemento2 ;
datosVarAVI.aVnumero3 = elemento3 ;
datosVarAVI.aVnumero4 = elemento4 ;
datosVarAVI.aVnumero5 = elemento5 ;
};
Serial.print("Esto se grabara en numero 1: "); Serial.print(datosVarAVI.aVnumero1) ;
Serial.println("");
Serial.print("Esto se grabara en numero 2: "); Serial.print(datosVarAVI.aVnumero2) ;
Serial.println("");
Serial.print("Esto se grabara en numero 3: "); Serial.print(datosVarAVI.aVnumero3) ;
Serial.println("");
Serial.print("Esto se grabara en numero 4: "); Serial.print(datosVarAVI.aVnumero4) ;
Serial.println("");
Serial.print("Esto se grabara en numero 5: "); Serial.print(datosVarAVI.aVnumero5) ;
Serial.println("");
int eeAddress = 45;
EEPROM.put(eeAddress, datosVarAVI);
Serial.println("Se han guardado los numeros!\n");
delay(500);
Serial.println("Ahora leo la agenda!");
Avisos leoDatosAVI;
eeAddress = 45;
EEPROM.get(eeAddress, leoDatosAVI);
Serial.println("Agenda de avisos:\n");
Serial.print("Numero 1:"); Serial.println(leoDatosAVI.aVnumero1);
Serial.print("Numero 2:"); Serial.println(leoDatosAVI.aVnumero2);
Serial.print("Numero 3:"); Serial.println(leoDatosAVI.aVnumero3);
Serial.print("Numero 4:"); Serial.println(leoDatosAVI.aVnumero4);
Serial.print("Numero 5:"); Serial.println(leoDatosAVI.aVnumero5);
Sim800l.delAllSms();
//Env();
}
Greetings.