ESP32 error with sim800l and deep sleep

Hello Forum!
this is the setup of my code I'll explain briefly what's my problem


when I send the esp32 into deep sleep (and then it restarts) the sim card stops working in fact normally I have as an answer
---> AT
<--- OK
etc.
after deep sleep I get only
---> AT
<----
----> AT
etc

do you know how I can "wake up" the sim?
Thanks in advance to everyone

Never, really never post text data (as code) as pictures!

Post complete code, usually the error is in that part of the code people are hiding from us.

When the ESP32 goes into deepsleep it is like the ESP32 is no longer there to the simcard. The simacard may need pull up or pull down resistors on the lines. Or a way to cause the simcard to power on reset with the ESP waking from sleep.

I'm sorry I didn't know. This is my first post here on the forum
Here my entire code:


#include "Adafruit_FONA.h"
#include "Adafruit_MAX31855.h"
#include <WiFi.h>



#define SIM800L_RX 27
#define SIM800L_TX 26
#define SIM800L_PWRKEY 4
#define SIM800L_RST 5
#define SIM800L_POWER 23
#define SIM800L_DTR 11

char replybuffer[150];
//per wi-fi
const char *SSID = "";  
const char *PWD = "";   


//per sim800
HardwareSerial *sim800lSerial = &Serial1;
Adafruit_FONA sim800l = Adafruit_FONA(SIM800L_PWRKEY);



uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

#define LED_BLUE 13

//definisco pin per temperatura
#define MAXDO 35
#define MAXCS 14
#define MAXCLK 19
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

// Your phone number to send SMS: + (plus sign) and country code
#define SMS_TARGET "+39xxxxxxxx"


//conversione in secondi
#define uS_TO_S_FACTOR 1000000UL
#define TIME_TO_SLEEP 60  //1 ora

int conteggio = 0;
int conteggioMax = 3;


String smsString = "";

char callerIDbuffer[32];  //we'll store the SMS sender number in here

double int_temp = thermocouple.readInternal();
double c = thermocouple.readCelsius();


String internalTemperature() {
  if (isnan(int_temp)) {
    Serial.println(F("Something wrong with internal temperature!"));
    return "";
  }

  String Internal_temp = ("Internal Temperature : " + String(int_temp) + " °C");
  delay(1000);

  Serial.println(Internal_temp);


  char tempInterna[50];
  char informazioni[30] = "Internal Temperature -> ";
  strcat(informazioni, itoa(int_temp, tempInterna, 10));
  strcat(informazioni, " C\n");
  return informazioni;
}


String thermocoupleTemperature() {
  if (isnan(c)) {
    Serial.println(F("Something wrong with thermocouple temperature!"));
    return "";
  }


  String Thermocouple_temp = "Thermocouple Temperature  " + String(c) + " °C";
  delay(1000);


  Serial.println(Thermocouple_temp);


  char tempTermo[50];
  char informazioni2[30] = "Thermocouple Temperature -> ";
  strcat(informazioni2, itoa(c, tempTermo, 10));
  strcat(informazioni2, " C\n");
  return informazioni2;
}


//connessione al wi-fi
void connectToWiFi() {
  Serial.print("Connecting to ");
  Serial.println(SSID);


  WiFi.begin(SSID, PWD);
  Serial.println("Connecting...");
  delay(20000);

  conteggio = 0;
  while (WiFi.status() != WL_CONNECTED && conteggio <= conteggioMax) {
    Serial.println("Not connected to wifi");
    delay(2000);
    Serial.println("Reconnecting..");
    WiFi.reconnect();
    delay(3000);
    conteggio++;
  }


  if (WiFi.status() != WL_CONNECTED || conteggio >= 3) {
    sim800l.sendSMS(SMS_TARGET, "Not connected to wifi");
  }


  if (WiFi.status() == WL_CONNECTED) {
    sim800l.sendSMS(SMS_TARGET, "Wi-Fi Available!");
    Serial.println("Wi-Fi Available!");
    Serial.print("Connected. IP: ");
    Serial.println(WiFi.localIP());
    delay(1000);
    Serial.print("WiFi RRSI: ");
    Serial.println("dBm");
    Serial.println(WiFi.RSSI());
  }
}


void setup() {


  pinMode(LED_BLUE, OUTPUT);
  pinMode(SIM800L_POWER, OUTPUT);


  digitalWrite(LED_BLUE, HIGH);
  digitalWrite(SIM800L_POWER, HIGH);


  Serial.begin(115200);
  Serial.println(F("ESP32 with GSM SIM800L"));
  Serial.println(F("Initializing....(May take more than 10 seconds)"));
  delay(10000);



  while (!Serial) delay(1);
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");


  // Make it slow so its easy to read!
  sim800lSerial->begin(4800, SERIAL_8N1, SIM800L_TX, SIM800L_RX);
  if (!sim800l.begin(*sim800lSerial)) {
    Serial.println(F("Couldn't find GSM SIM800L"));
    while (1)
      ;
  }
  Serial.println(F("GSM SIM800L is OK"));


  char imei[16] = { 0 };  // MUST use a 16 character buffer for IMEI!
  uint8_t imeiLen = sim800l.getIMEI(imei);
  if (imeiLen > 0) {
    Serial.print("SIM card IMEI: ");
    Serial.println(imei);
  }

  //get rssi gsm
  uint8_t n = sim800l.getRSSI();
  int8_t r;
  Serial.print(F("GSM RSSI "));
  Serial.print(n);
  Serial.print(": ");
  r = map(n, 2, 30, -110, -54);
  Serial.print(r);
  Serial.println(F(" dBm"));

  // Set up the FONA to send a +CMTI notification
  // when an SMS is received
  sim800lSerial->print("AT+CNMI=2,1\r\n");
  Serial.println("GSM SIM800L Ready");
  connectToWiFi();

  
}


long prevMillis = 0;
int interval = 1000;
char sim800lNotificationBuffer[64];  //for notifications from the FONA
char smsBuffer[250];
boolean ledState = false;
int value = 0;


void loop() {

  delay(10000);



  if (millis() - prevMillis > interval) {
    ledState = !ledState;
    digitalWrite(LED_BLUE, ledState);

    prevMillis = millis();
  }


  char *bufPtr = sim800lNotificationBuffer;  //handy buffer pointer

  if (sim800l.available()) {
    int slot = 0;  // this will be the slot number of the SMS
    int charCount = 0;

    // Read the notification into fonaInBuffer
    do {
      *bufPtr = sim800l.read();
      Serial.write(*bufPtr);
      delay(1);
    } while ((*bufPtr++ != '\n') && (sim800l.available()) && (++charCount < (sizeof(sim800lNotificationBuffer) - 1)));

    //Add a terminal NULL to the notification string
    *bufPtr = 0;

    //Scan the notification string for an SMS received notification.
    //  If it's an SMS message, we'll get the slot number in 'slot'
    if (1 == sscanf(sim800lNotificationBuffer, "+CMTI: \"SM\",%d", &slot)) {
      Serial.print("slot: ");
      Serial.println(slot);


      // Retrieve SMS sender address/phone number.
      if (!sim800l.getSMSSender(slot, callerIDbuffer, 149)) {
        Serial.println("Didn't find SMS message in slot!");
      }
      Serial.print(F("FROM: "));
      Serial.println(callerIDbuffer);

      // Retrieve SMS value.
      uint16_t smslen;
      // Pass in buffer and max len!
      if (sim800l.readSMS(slot, smsBuffer, 250, &smslen)) {
        smsString = String(smsBuffer);
        Serial.println(smsString);
      }

      if (smsString == "State") {
        Serial.println("Current Temperature:");
        char invio[] = "Current Temperature:\n";
        char appoggio[50];
        char appoggio2[50];
        internalTemperature().toCharArray(appoggio, 100);
        strcat(invio, appoggio);
        Serial.println(invio);
        thermocoupleTemperature().toCharArray(appoggio2, 100);
        strcat(invio, appoggio2);
        Serial.println(invio);
        sim800l.sendSMS(callerIDbuffer, invio);
        internalTemperature();
        thermocoupleTemperature();
        delay(100);
      }

      if (smsString == "Connect") {
        Serial.println("Attempted wifi connection...");
        sim800l.sendSMS(callerIDbuffer, "Attempted wifi connection...");
        WiFi.reconnect();
        connectToWiFi();
      }


      while (1) {
        if (sim800l.deleteSMS(slot)) {
          Serial.println(F("OK!"));
          break;
        } else {
          Serial.print(F("Couldn't delete SMS in slot "));
          Serial.println(slot);
          sim800l.print(F("AT+CMGD=?\r\n"));
          delay(10000);
        }
      }
    }
   
  }

  Serial.println("sleep for 1 minute..");
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_deep_sleep_start();
}

It seems that you connect the SIM800L reset pin but you don't use it. Reset the module in setup as after deep sleep the ESP32 will do a reset and start over again. The SIM800 doesn't know that but by resetting it you can enforce a consistent state.

the fact is that I tried to search online for a way to do it but I couldn't find anything :frowning:

"SIM800L reset" were the words I used to find

Which has this, Reset pin, pull low for 100ms to perform hard reset

which means

voiding setup()
{
pinMode(SIM800L_RST, OUTPUT);
Digitialwrites( SIM800L_RST, LOW);
delay(100);
Digitialwrites( SIM800L_RST, HIGH);

really it was an easy search to find the info. And, of course, you'll need to fix the typos.

Doesn't work :frowning:

Show your revised code

What does "doesn't work" mean? Did you happen to post the code that "doesn't work"? Did you ever post a schematic or an image of your project?


#include "Adafruit_FONA.h"
#include "Adafruit_MAX31855.h"
#include <WiFi.h>



#define SIM800L_RX 27
#define SIM800L_TX 26
#define SIM800L_PWRKEY 4
#define SIM800L_RST 5
#define SIM800L_POWER 23
#define SIM800L_DTR 11

char replybuffer[150];
//per wi-fi
const char *SSID = "";  
const char *PWD = "";   


//per sim800
HardwareSerial *sim800lSerial = &Serial1;
Adafruit_FONA sim800l = Adafruit_FONA(SIM800L_PWRKEY);



uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

#define LED_BLUE 13

//definisco pin per temperatura
#define MAXDO 35
#define MAXCS 14
#define MAXCLK 19
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

// Your phone number to send SMS: + (plus sign) and country code
#define SMS_TARGET "+39xxxxxxxx"


//conversione in secondi
#define uS_TO_S_FACTOR 1000000UL
#define TIME_TO_SLEEP 60  //1 ora

int conteggio = 0;
int conteggioMax = 3;


String smsString = "";

char callerIDbuffer[32];  //we'll store the SMS sender number in here

double int_temp = thermocouple.readInternal();
double c = thermocouple.readCelsius();


String internalTemperature() {
  if (isnan(int_temp)) {
    Serial.println(F("Something wrong with internal temperature!"));
    return "";
  }

  String Internal_temp = ("Internal Temperature : " + String(int_temp) + " °C");
  delay(1000);

  Serial.println(Internal_temp);


  char tempInterna[50];
  char informazioni[30] = "Internal Temperature -> ";
  strcat(informazioni, itoa(int_temp, tempInterna, 10));
  strcat(informazioni, " C\n");
  return informazioni;
}


String thermocoupleTemperature() {
  if (isnan(c)) {
    Serial.println(F("Something wrong with thermocouple temperature!"));
    return "";
  }


  String Thermocouple_temp = "Thermocouple Temperature  " + String(c) + " °C";
  delay(1000);


  Serial.println(Thermocouple_temp);


  char tempTermo[50];
  char informazioni2[30] = "Thermocouple Temperature -> ";
  strcat(informazioni2, itoa(c, tempTermo, 10));
  strcat(informazioni2, " C\n");
  return informazioni2;
}


//connessione al wi-fi
void connectToWiFi() {
  Serial.print("Connecting to ");
  Serial.println(SSID);


  WiFi.begin(SSID, PWD);
  Serial.println("Connecting...");
  delay(20000);

  conteggio = 0;
  while (WiFi.status() != WL_CONNECTED && conteggio <= conteggioMax) {
    Serial.println("Not connected to wifi");
    delay(2000);
    Serial.println("Reconnecting..");
    WiFi.reconnect();
    delay(3000);
    conteggio++;
  }


  if (WiFi.status() != WL_CONNECTED || conteggio >= 3) {
    sim800l.sendSMS(SMS_TARGET, "Not connected to wifi");
  }


  if (WiFi.status() == WL_CONNECTED) {
    sim800l.sendSMS(SMS_TARGET, "Wi-Fi Available!");
    Serial.println("Wi-Fi Available!");
    Serial.print("Connected. IP: ");
    Serial.println(WiFi.localIP());
    delay(1000);
    Serial.print("WiFi RRSI: ");
    Serial.println("dBm");
    Serial.println(WiFi.RSSI());
  }
}


void setup() {


  pinMode(LED_BLUE, OUTPUT);
  pinMode(SIM800L_POWER, OUTPUT);
  pinMode(SIM800L_RST, OUTPUT);

  digitalWrite(SIM800L_RST, LOW);
  delay(100);
  digitalWrite(SIM800L_RST, HIGH);

  digitalWrite(LED_BLUE, HIGH);
  digitalWrite(SIM800L_POWER, HIGH);


  Serial.begin(115200);
  Serial.println(F("ESP32 with GSM SIM800L"));
  Serial.println(F("Initializing....(May take more than 10 seconds)"));
  delay(10000);



  while (!Serial) delay(1);
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");


  // Make it slow so its easy to read!
  sim800lSerial->begin(4800, SERIAL_8N1, SIM800L_TX, SIM800L_RX);
  if (!sim800l.begin(*sim800lSerial)) {
    Serial.println(F("Couldn't find GSM SIM800L"));
    while (1)
      ;
  }
  Serial.println(F("GSM SIM800L is OK"));


  char imei[16] = { 0 };  // MUST use a 16 character buffer for IMEI!
  uint8_t imeiLen = sim800l.getIMEI(imei);
  if (imeiLen > 0) {
    Serial.print("SIM card IMEI: ");
    Serial.println(imei);
  }

  //get rssi gsm
  uint8_t n = sim800l.getRSSI();
  int8_t r;
  Serial.print(F("GSM RSSI "));
  Serial.print(n);
  Serial.print(": ");
  r = map(n, 2, 30, -110, -54);
  Serial.print(r);
  Serial.println(F(" dBm"));

  // Set up the FONA to send a +CMTI notification
  // when an SMS is received
  sim800lSerial->print("AT+CNMI=2,1\r\n");
  Serial.println("GSM SIM800L Ready");
  connectToWiFi();

  
}


long prevMillis = 0;
int interval = 1000;
char sim800lNotificationBuffer[64];  //for notifications from the FONA
char smsBuffer[250];
boolean ledState = false;
int value = 0;


void loop() {

  delay(10000);



  if (millis() - prevMillis > interval) {
    ledState = !ledState;
    digitalWrite(LED_BLUE, ledState);

    prevMillis = millis();
  }


  char *bufPtr = sim800lNotificationBuffer;  //handy buffer pointer

  if (sim800l.available()) {
    int slot = 0;  // this will be the slot number of the SMS
    int charCount = 0;

    // Read the notification into fonaInBuffer
    do {
      *bufPtr = sim800l.read();
      Serial.write(*bufPtr);
      delay(1);
    } while ((*bufPtr++ != '\n') && (sim800l.available()) && (++charCount < (sizeof(sim800lNotificationBuffer) - 1)));

    //Add a terminal NULL to the notification string
    *bufPtr = 0;

    //Scan the notification string for an SMS received notification.
    //  If it's an SMS message, we'll get the slot number in 'slot'
    if (1 == sscanf(sim800lNotificationBuffer, "+CMTI: \"SM\",%d", &slot)) {
      Serial.print("slot: ");
      Serial.println(slot);


      // Retrieve SMS sender address/phone number.
      if (!sim800l.getSMSSender(slot, callerIDbuffer, 149)) {
        Serial.println("Didn't find SMS message in slot!");
      }
      Serial.print(F("FROM: "));
      Serial.println(callerIDbuffer);

      // Retrieve SMS value.
      uint16_t smslen;
      // Pass in buffer and max len!
      if (sim800l.readSMS(slot, smsBuffer, 250, &smslen)) {
        smsString = String(smsBuffer);
        Serial.println(smsString);
      }

      if (smsString == "State") {
        Serial.println("Current Temperature:");
        char invio[] = "Current Temperature:\n";
        char appoggio[50];
        char appoggio2[50];
        internalTemperature().toCharArray(appoggio, 100);
        strcat(invio, appoggio);
        Serial.println(invio);
        thermocoupleTemperature().toCharArray(appoggio2, 100);
        strcat(invio, appoggio2);
        Serial.println(invio);
        sim800l.sendSMS(callerIDbuffer, invio);
        internalTemperature();
        thermocoupleTemperature();
        delay(100);
      }

      if (smsString == "Connect") {
        Serial.println("Attempted wifi connection...");
        sim800l.sendSMS(callerIDbuffer, "Attempted wifi connection...");
        WiFi.reconnect();
        connectToWiFi();
      }


      while (1) {
        if (sim800l.deleteSMS(slot)) {
          Serial.println(F("OK!"));
          break;
        } else {
          Serial.print(F("Couldn't delete SMS in slot "));
          Serial.println(slot);
          sim800l.print(F("AT+CMGD=?\r\n"));
          delay(10000);
        }
      }
    }
   
  }

  Serial.println("sleep for 1 minute..");
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_deep_sleep_start();
}

i tried to implement the reset but the sim still doesn't work after deep sleep

Looks like its time to contact the sim people as to why their product is not working.

Did you try the other way?

voiding setup()
{
pinMode(SIM800L_RST, OUTPUT);
Digitialwrites( SIM800L_RST, HIGH);
delay(100);
Digitialwrites( SIM800L_RST, LOW);

???????

but without the deep sleep the sim works perfectly :smiling_face_with_tear:

yes this is my code now:


#include "Adafruit_FONA.h"
#include "Adafruit_MAX31855.h"
#include <WiFi.h>



#define SIM800L_RX 27
#define SIM800L_TX 26
#define SIM800L_PWRKEY 4
#define SIM800L_RST 5
#define SIM800L_POWER 23
#define SIM800L_DTR 11

char replybuffer[150];
//per wi-fi
const char *SSID = "";  
const char *PWD = "";   


//per sim800
HardwareSerial *sim800lSerial = &Serial1;
Adafruit_FONA sim800l = Adafruit_FONA(SIM800L_PWRKEY);



uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

#define LED_BLUE 13

//definisco pin per temperatura
#define MAXDO 35
#define MAXCS 14
#define MAXCLK 19
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

// Your phone number to send SMS: + (plus sign) and country code
#define SMS_TARGET "+39xxxxxxxx"


//conversione in secondi
#define uS_TO_S_FACTOR 1000000UL
#define TIME_TO_SLEEP 60  //1 ora

int conteggio = 0;
int conteggioMax = 3;


String smsString = "";

char callerIDbuffer[32];  //we'll store the SMS sender number in here

double int_temp = thermocouple.readInternal();
double c = thermocouple.readCelsius();


String internalTemperature() {
  if (isnan(int_temp)) {
    Serial.println(F("Something wrong with internal temperature!"));
    return "";
  }

  String Internal_temp = ("Internal Temperature : " + String(int_temp) + " °C");
  delay(1000);

  Serial.println(Internal_temp);


  char tempInterna[50];
  char informazioni[30] = "Internal Temperature -> ";
  strcat(informazioni, itoa(int_temp, tempInterna, 10));
  strcat(informazioni, " C\n");
  return informazioni;
}


String thermocoupleTemperature() {
  if (isnan(c)) {
    Serial.println(F("Something wrong with thermocouple temperature!"));
    return "";
  }


  String Thermocouple_temp = "Thermocouple Temperature  " + String(c) + " °C";
  delay(1000);


  Serial.println(Thermocouple_temp);


  char tempTermo[50];
  char informazioni2[30] = "Thermocouple Temperature -> ";
  strcat(informazioni2, itoa(c, tempTermo, 10));
  strcat(informazioni2, " C\n");
  return informazioni2;
}


//connessione al wi-fi
void connectToWiFi() {
  Serial.print("Connecting to ");
  Serial.println(SSID);


  WiFi.begin(SSID, PWD);
  Serial.println("Connecting...");
  delay(20000);

  conteggio = 0;
  while (WiFi.status() != WL_CONNECTED && conteggio <= conteggioMax) {
    Serial.println("Not connected to wifi");
    delay(2000);
    Serial.println("Reconnecting..");
    WiFi.reconnect();
    delay(3000);
    conteggio++;
  }


  if (WiFi.status() != WL_CONNECTED || conteggio >= 3) {
    sim800l.sendSMS(SMS_TARGET, "Not connected to wifi");
  }


  if (WiFi.status() == WL_CONNECTED) {
    sim800l.sendSMS(SMS_TARGET, "Wi-Fi Available!");
    Serial.println("Wi-Fi Available!");
    Serial.print("Connected. IP: ");
    Serial.println(WiFi.localIP());
    delay(1000);
    Serial.print("WiFi RRSI: ");
    Serial.println("dBm");
    Serial.println(WiFi.RSSI());
  }
}


void setup() {


  pinMode(LED_BLUE, OUTPUT);
  pinMode(SIM800L_POWER, OUTPUT);
  pinMode(SIM800L_RST, OUTPUT);

  digitalWrite(SIM800L_RST, LOW);
  delay(100);
  digitalWrite(SIM800L_RST, HIGH);

  digitalWrite(LED_BLUE, HIGH);
  digitalWrite(SIM800L_POWER, HIGH);


  Serial.begin(115200);
  Serial.println(F("ESP32 with GSM SIM800L"));
  Serial.println(F("Initializing....(May take more than 10 seconds)"));
  delay(10000);



  while (!Serial) delay(1);
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");


  // Make it slow so its easy to read!
  sim800lSerial->begin(4800, SERIAL_8N1, SIM800L_TX, SIM800L_RX);
  if (!sim800l.begin(*sim800lSerial)) {
    Serial.println(F("Couldn't find GSM SIM800L"));
    while (1)
      ;
  }
  Serial.println(F("GSM SIM800L is OK"));


  char imei[16] = { 0 };  // MUST use a 16 character buffer for IMEI!
  uint8_t imeiLen = sim800l.getIMEI(imei);
  if (imeiLen > 0) {
    Serial.print("SIM card IMEI: ");
    Serial.println(imei);
  }

  //get rssi gsm
  uint8_t n = sim800l.getRSSI();
  int8_t r;
  Serial.print(F("GSM RSSI "));
  Serial.print(n);
  Serial.print(": ");
  r = map(n, 2, 30, -110, -54);
  Serial.print(r);
  Serial.println(F(" dBm"));

  // Set up the FONA to send a +CMTI notification
  // when an SMS is received
  sim800lSerial->print("AT+CNMI=2,1\r\n");
  Serial.println("GSM SIM800L Ready");
  connectToWiFi();

  
}


long prevMillis = 0;
int interval = 1000;
char sim800lNotificationBuffer[64];  //for notifications from the FONA
char smsBuffer[250];
boolean ledState = false;
int value = 0;


void loop() {

  delay(10000);



  if (millis() - prevMillis > interval) {
    ledState = !ledState;
    digitalWrite(LED_BLUE, ledState);

    prevMillis = millis();
  }


  char *bufPtr = sim800lNotificationBuffer;  //handy buffer pointer

  if (sim800l.available()) {
    int slot = 0;  // this will be the slot number of the SMS
    int charCount = 0;

    // Read the notification into fonaInBuffer
    do {
      *bufPtr = sim800l.read();
      Serial.write(*bufPtr);
      delay(1);
    } while ((*bufPtr++ != '\n') && (sim800l.available()) && (++charCount < (sizeof(sim800lNotificationBuffer) - 1)));

    //Add a terminal NULL to the notification string
    *bufPtr = 0;

    //Scan the notification string for an SMS received notification.
    //  If it's an SMS message, we'll get the slot number in 'slot'
    if (1 == sscanf(sim800lNotificationBuffer, "+CMTI: \"SM\",%d", &slot)) {
      Serial.print("slot: ");
      Serial.println(slot);


      // Retrieve SMS sender address/phone number.
      if (!sim800l.getSMSSender(slot, callerIDbuffer, 149)) {
        Serial.println("Didn't find SMS message in slot!");
      }
      Serial.print(F("FROM: "));
      Serial.println(callerIDbuffer);

      // Retrieve SMS value.
      uint16_t smslen;
      // Pass in buffer and max len!
      if (sim800l.readSMS(slot, smsBuffer, 250, &smslen)) {
        smsString = String(smsBuffer);
        Serial.println(smsString);
      }

      if (smsString == "State") {
        Serial.println("Current Temperature:");
        char invio[] = "Current Temperature:\n";
        char appoggio[50];
        char appoggio2[50];
        internalTemperature().toCharArray(appoggio, 100);
        strcat(invio, appoggio);
        Serial.println(invio);
        thermocoupleTemperature().toCharArray(appoggio2, 100);
        strcat(invio, appoggio2);
        Serial.println(invio);
        sim800l.sendSMS(callerIDbuffer, invio);
        internalTemperature();
        thermocoupleTemperature();
        delay(100);
      }

      if (smsString == "Connect") {
        Serial.println("Attempted wifi connection...");
        sim800l.sendSMS(callerIDbuffer, "Attempted wifi connection...");
        WiFi.reconnect();
        connectToWiFi();
      }


      while (1) {
        if (sim800l.deleteSMS(slot)) {
          Serial.println(F("OK!"));
          break;
        } else {
          Serial.print(F("Couldn't delete SMS in slot "));
          Serial.println(slot);
          sim800l.print(F("AT+CMGD=?\r\n"));
          delay(10000);
        }
      }
    }
   
  }

  Serial.println("sleep for 1 minute..");
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_deep_sleep_start();
}

That's all I got for you. Good luck.

This doesn't implement idahowalker's last suggestion.

Can you help me please? :pray:

Did you try the suggestion of post #14?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.