Wdt reset . help me please to fix

after send sms "get" to Program:
it 's show on serial monitor
......
wdt reset
load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v00044e70
~ld
..........................code program.................
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

const String PHONE_NUMBER = "+66935474953";

// Define RX/TX pins for GSM Module
#define GSM_RX_PIN D5
#define GSM_TX_PIN D6
SoftwareSerial sim800(GSM_RX_PIN, GSM_TX_PIN);

// Define RX/TX pins for GPS Module
#define GPS_RX_PIN D7
#define GPS_TX_PIN D8
SoftwareSerial neogps(GPS_RX_PIN, GPS_TX_PIN);
TinyGPSPlus gps;

String receivedCommand = "";

void setup() {
Serial.println("Start of setup");

Serial.begin(115200);
Serial.println("Arduino serial initialize");

sim800.begin(9600);
Serial.println("SIM800L serial initialize");

neogps.begin(9600);
Serial.println("GPS serial initialize");

sim800.listen();
neogps.listen();

sim800.println("AT+CMGF=1\r"); // Set SMS mode to text
delay(1000);
Serial.println("Setup complete.");

Serial.println("End of setup");
}

void loop() {
ESP.wdtFeed(); // āļŦāļĢāļ·āļ­ ESP8266.wdtFeed()
while (sim800.available()) {
parseSMS(sim800.readString());
}

// āļĢāļ­āļĢāļąāļšāļ„āļģāļŠāļąāđˆāļ‡āļˆāļēāļāļœāļđāđ‰āđƒāļŠāđ‰
if (receivedCommand == "get") {
checkGPSCommand();
// āļĢāļĩāđ€āļ‹āđ‡āļ•āļ„āļģāļŠāļąāđˆāļ‡āļ—āļĩāđˆāđ„āļ”āđ‰āļĢāļąāļš
receivedCommand = "";
//delay(1000); // āļžāļąāļāđ€āļžāļ·āđˆāļ­āļ›āđ‰āļ­āļ‡āļāļąāļ™āļāļēāļĢāļ—āļģāļ‡āļēāļ™āđāļšāļšāđ„āļĄāđˆāļˆāļš
}
}

void parseSMS(String sms) {
Serial.println("Received SMS: " + sms); // Display the received SMS in Serial Monitor
sms.trim();
if (sms.startsWith("+CMTI")) {
int index = sms.indexOf(",");
String temp = sms.substring(index + 1);
temp.trim();
temp = "AT+CMGR=" + temp + "\r";
sim800.println(temp);
} else if (sms.startsWith("+CMGR")) {
extractSMS(sms);
}
}

void extractSMS(String sms) {
int index = sms.indexOf(",");
String senderNumber = sms.substring(index + 2, index + 15);
senderNumber.trim();

index = sms.indexOf("\n");
String message = sms.substring(index + 1);
message.trim();

Serial.println("Sender Number: " + senderNumber);
Serial.println("Message: " + message);

if (senderNumber == PHONE_NUMBER) {
processCommand(message);
}
}

void processCommand(String command) {
// āđƒāļŦāđ‰āļ—āļģāļāļēāļĢ trim() āļāđˆāļ­āļ™āđ€āļ›āļĢāļĩāļĒāļšāđ€āļ—āļĩāļĒāļš
command.trim();

if (command.equalsIgnoreCase("get")) {
receivedCommand = command;
Serial.println("Received command: " + receivedCommand);
}
}

void checkGPSCommand() {
Serial.println("Checking GPS Command");

// āļ•āļĢāļ§āļˆāļŠāļ­āļšāļ§āđˆāļēāļĄāļĩāļ„āļģāļŠāļąāđˆāļ‡ "get" āļ–āļđāļāļŠāđˆāļ‡āļĄāļēāļŦāļĢāļ·āļ­āđ„āļĄāđˆ
if (receivedCommand == "get") {
// āļĢāļĩāđ€āļ‹āđ‡āļ•āļ„āļģāļŠāļąāđˆāļ‡āļ—āļĩāđˆāđ„āļ”āđ‰āļĢāļąāļš
receivedCommand = "";

// āļ•āļĢāļ§āļˆāļŠāļ­āļš GPS Data āđāļĨāļ°āļŠāđˆāļ‡ SMS āļ—āļĩāđˆāļĄāļĩāļ‚āđ‰āļ­āļĄāļđāļĨāļ•āļģāđāļŦāļ™āđˆāļ‡ GPS
while (neogps.available()) {
  if (gps.encode(neogps.read())) {
    if (gps.location.isValid()) {
      Serial.println("Sending Location SMS");
      sendLocationSMS();
    } else {
      Serial.println("Invalid GPS Location");
    }
  } else {
    Serial.println("GPS Data Not Received");
  }
}

}
}

void sendLocationSMS() {
Serial.print("Sending Location SMS...");

if (gps.location.isValid()) {
sim800.print("AT+CMGS="" + PHONE_NUMBER + ""\r");
delay(1000);
sim800.print("Google Maps");
sim800.print(gps.location.lat(), 6);
sim800.print(",");
sim800.print(gps.location.lng(), 6);
sim800.write(0x1A); // āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āđƒāļŠāđ‰ delay āļŦāļĨāļąāļ‡āļˆāļēāļāļāļēāļĢāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ
unsigned long startMillis = millis();
while (millis() - startMillis < 10000) { // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
if (sim800.available()) {
String response = sim800.readString();
Serial.println("Response from GSM module: " + response);
break;
}
}
Serial.println("GPS Location SMS Sent Successfully.");
} else {
Serial.println("Invalid GPS data");
}
}

Hi @kruwanchai ,
Welcome to the forum..

try feeding the watchdog in this loop inside sendLocationSMS..

good luck.. ~q

How?

void sendLocationSMS() {
Serial.print("Sending Location SMS...");

if (gps.location.isValid()) {
sim800.print("AT+CMGS="" + PHONE_NUMBER + ""\r");
delay(1000);
sim800.print("Google Maps");
sim800.print(gps.location.lat(), 6);
sim800.print(",");
sim800.print(gps.location.lng(), 6);
sim800.write(0x1A); // āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āđƒāļŠāđ‰ delay āļŦāļĨāļąāļ‡āļˆāļēāļāļāļēāļĢāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ
unsigned long startMillis = millis();

while (millis() - startMillis < 10000) {  // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
  if (sim800.available()) {
    String response = sim800.readString();
    Serial.println("Response from GSM module: " + response);
    // Feed the watchdog here
    ESP.wdtFeed();  // āļŦāļĢāļ·āļ­ ESP8266.wdtFeed()
    break;
  }
}
Serial.println("GPS Location SMS Sent Successfully.");

} else {
Serial.println("Invalid GPS data");
}
}

same way you do at the start of your loop()..
it's the first command, looks like you were using ESP8266 then upgraded to ESP32..

~q

while (millis() - startMillis < 10000) {  // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
    // Feed the watchdog here
    ESP.wdtFeed();  // āļŦāļĢāļ·āļ­ ESP8266.wdtFeed()
  if (sim800.available()) {
    String response = sim800.readString();
    Serial.println("Response from GSM module: " + response);
    break;
  }
}

while (millis() - startMillis < 10000) { // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ

  if (sim800.available()) {
    String response = sim800.readString();
    Serial.println("Response from GSM module: " + response);
    ESP.wdtFeed(); 
    break;
  }
}

....................
No wdt reset, but still haven't received sms reply.
(void sendLocationSMS() )

good news,
you are looping for 10 seconds waiting for that reply, this is what i figured causes the dog to bark..
now figure out why no response..
do you still have the feed in the "if" or is it like i posted??

~q

All function...
void sendLocationSMS() {
Serial.print("Sending Location SMS...");

if (gps.location.isValid()) {
sim800.print("AT+CMGS="" + PHONE_NUMBER + ""\r");
delay(1000);
sim800.print("Google Maps");
sim800.print(gps.location.lat(), 6);
sim800.print(",");
sim800.print(gps.location.lng(), 6);
sim800.write(0x1A); // āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āđƒāļŠāđ‰ delay āļŦāļĨāļąāļ‡āļˆāļēāļāļāļēāļĢāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ
unsigned long startMillis = millis();

while (millis() - startMillis < 10000) {  // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
   
  if (sim800.available()) {
    String response = sim800.readString();
    Serial.println("Response from GSM module: " + response);
    ESP.wdtFeed(); 
    break;
  }
}
Serial.println("GPS Location SMS Sent Successfully.");

} else {
Serial.println("Invalid GPS data");
}
}

try..

void sendLocationSMS() {
Serial.print("Sending Location SMS...");

if (gps.location.isValid()) {
sim800.print("AT+CMGS="" + PHONE_NUMBER + ""\r");
delay(1000);
sim800.print("Google Maps");
sim800.print(gps.location.lat(), 6);
sim800.print(",");
sim800.print(gps.location.lng(), 6);
sim800.write(0x1A); // āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āđƒāļŠāđ‰ delay āļŦāļĨāļąāļ‡āļˆāļēāļāļāļēāļĢāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ
unsigned long startMillis = millis();

while (millis() - startMillis < 10000) {  // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
    ESP.wdtFeed(); //feed dog
    yieldIfNecessary();//allow other tasks
  if (sim800.available()) {
    String response = sim800.readString();
    Serial.println("Response from GSM module: " + response);
    break;
  }
}
Serial.println("GPS Location SMS Sent Successfully.");

} else {
Serial.println("Invalid GPS data");
}
}

no function yieldIfNecessary in the Arduino Core library for ESP8266. Right?
I use yield();

while (millis() - startMillis < 10000) { // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
ESP.wdtFeed(); //feed dog
yield();//allow other tasks
if (sim800.available()) {
String response = sim800.readString();
Serial.println("Response from GSM module: " + response);
break;
}
}

1 Like

Haven't received a reply to SMS yet.

do you receive the sms??
~q

No sir.

I have this program code that can send SMS as a link or Google Maps, but it sends automatically and in a loop. So I adjusted it to wait to receive the "get" command from the "PHONE_NUMBER" The results showed that there was an error as posted above.
///code program///
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

const String PHONE_NUMBER = "+66935xxxxxx";

// Define RX/TX pins for GSM Module
#define GSM_RX_PIN D5
#define GSM_TX_PIN D6
SoftwareSerial sim800(GSM_RX_PIN, GSM_TX_PIN);

// Define RX/TX pins for GPS Module
#define GPS_RX_PIN D7
#define GPS_TX_PIN D8
SoftwareSerial neogps(GPS_RX_PIN, GPS_TX_PIN);
TinyGPSPlus gps;

void setup() {
Serial.begin(115200);
sim800.begin(9600);
neogps.begin(9600);
sim800.listen();
neogps.listen();

sim800.println("AT+CMGF=1\r"); // Set SMS mode to text
delay(1000);
Serial.println("Setup complete.");
}

void loop() {
while (sim800.available()) {
parseSMS(sim800.readString());
}

checkGPSCommand();
}

void parseSMS(String sms) {
Serial.println("Received SMS: " + sms); // Display the received SMS in Serial Monitor
sms.trim();
if (sms.startsWith("+CMTI")) {
int index = sms.indexOf(",");
String temp = sms.substring(index + 1);
temp.trim();
temp = "AT+CMGR=" + temp + "\r";
sim800.println(temp);
} else if (sms.startsWith("+CMGR")) {
extractSMS(sms);
}
}

void extractSMS(String sms) {
int index = sms.indexOf(",");
String senderNumber = sms.substring(index + 2, index + 15);
senderNumber.trim();

index = sms.indexOf("\n");
String message = sms.substring(index + 1);
message.trim();

if (senderNumber == PHONE_NUMBER) {
if (message == "get location") {
sendLocationSMS();
}
}
}

void checkGPSCommand() {
Serial.println("Checking GPS Command");

while (neogps.available()) {
if (gps.encode(neogps.read())) {
if (gps.location.isValid()) {
Serial.println("Sending Location SMS");
sendLocationSMS();
} else {
Serial.println("Invalid GPS Location");
}
} else {
Serial.println("GPS Data Not Received");
}
}
}

void sendLocationSMS() {
Serial.print("Sending Location SMS...");

if (gps.location.isValid()) {
sim800.print("AT+CMGS="" + PHONE_NUMBER + ""\r");
delay(1000);
sim800.print("Google Maps");
sim800.print(gps.location.lat(), 6);
sim800.print(",");
sim800.print(gps.location.lng(), 6);
delay(100);
sim800.write(0x1A);
delay(1000);
Serial.println("GPS Location SMS Sent Successfully.");
} else {
Serial.println("Invalid GPS data");
}
}

once more try..

void sendLocationSMS() {
Serial.println("entering: sendLocationSMS...");

if (gps.location.isValid()) {
  Serial.println("location is valid");

sim800.print("AT+CMGS=\"" + PHONE_NUMBER + "\"\r");
delay(1000);
sim800.print("Google Maps");
sim800.print(gps.location.lat(), 6);
sim800.print(",");
sim800.print(gps.location.lng(), 6);
sim800.println((char)26);
//sim800.write(0x1A); // āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āđƒāļŠāđ‰ delay āļŦāļĨāļąāļ‡āļˆāļēāļāļāļēāļĢāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ
unsigned long startMillis = millis();
bool timedOut = true;

while (millis() - startMillis < 10000) {  // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
    ESP.wdtFeed(); //feed dog
    yield();//allow other tasks
  if (sim800.available()) {
    Serial.println("Response available..");
    String response = sim800.readString();
    Serial.println("Response from GSM module: " + response);
    timedOut = false;
    break;
  }
}
if (!timedOut){
Serial.println("GPS Location SMS Sent Successfully."); } else
Serial.println("Response timed out..");

} else {
Serial.println("Invalid GPS data");
}
}

pretty sure it was the dialing string was bad..

good luck.. ~q

when you post code hit that little code button and paste it in..

sim800.print("AT+CMGS="" + PHONE_NUMBER + ""\r");

i would have caught the coloring, it would have helped..
try this..

Serial.print("AT+CMGS="" + PHONE_NUMBER + ""\r");

you'll see what i mean..

happy holidays.. ~q

Thank you.

///update code///
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

const String PHONE_NUMBER = "+66935xxxxxx";

// Define RX/TX pins for GSM Module
#define GSM_RX_PIN D5
#define GSM_TX_PIN D6
SoftwareSerial sim800(GSM_RX_PIN, GSM_TX_PIN);

// Define RX/TX pins for GPS Module
#define GPS_RX_PIN D7
#define GPS_TX_PIN D8
SoftwareSerial neogps(GPS_RX_PIN, GPS_TX_PIN);
TinyGPSPlus gps;

String receivedCommand = "";

void setup() {
Serial.begin(115200);
Serial.println("Checking Network Registration...");
sim800.println("AT+CREG?");

Serial.println("Start of setup");

Serial.begin(115200);
Serial.println("Arduino serial initialize");

sim800.begin(9600);
Serial.println("SIM800L serial initialize");

neogps.begin(9600);
Serial.println("GPS serial initialize");

sim800.listen();
neogps.listen();

sim800.println("AT+CMGF=1\r"); // Set SMS mode to text
delay(1000);
Serial.println("Setup complete.");

Serial.println("End of setup");
}

void loop() {
ESP.wdtFeed(); // āļŦāļĢāļ·āļ­ ESP8266.wdtFeed()
while (sim800.available()) {
parseSMS(sim800.readString());
}
while (sim800.available()) {
Serial.write(sim800.read());
}
// āļĢāļ­āļĢāļąāļšāļ„āļģāļŠāļąāđˆāļ‡āļˆāļēāļāļœāļđāđ‰āđƒāļŠāđ‰
if (receivedCommand == "get") {
checkGPSCommand();
// āļĢāļĩāđ€āļ‹āđ‡āļ•āļ„āļģāļŠāļąāđˆāļ‡āļ—āļĩāđˆāđ„āļ”āđ‰āļĢāļąāļš
receivedCommand = "";
//delay(1000); // āļžāļąāļāđ€āļžāļ·āđˆāļ­āļ›āđ‰āļ­āļ‡āļāļąāļ™āļāļēāļĢāļ—āļģāļ‡āļēāļ™āđāļšāļšāđ„āļĄāđˆāļˆāļš
}
}

void parseSMS(String sms) {
Serial.println("Received SMS: " + sms); // Display the received SMS in Serial Monitor
sms.trim();
if (sms.startsWith("+CMTI")) {
int index = sms.indexOf(",");
String temp = sms.substring(index + 1);
temp.trim();
temp = "AT+CMGR=" + temp + "\r";
sim800.println(temp);
sim800.flush();
} else if (sms.startsWith("+CMGR")) {
extractSMS(sms);
}
}

void extractSMS(String sms) {
int index = sms.indexOf(",");
String senderNumber = sms.substring(index + 2, index + 15);
senderNumber.trim();

index = sms.indexOf("\n");
String message = sms.substring(index + 1);
message.trim();

Serial.println("Sender Number: " + senderNumber);
Serial.println("Message: " + message);

if (senderNumber == PHONE_NUMBER) {
processCommand(message);
}
}

void processCommand(String command) {
// āđƒāļŦāđ‰āļ—āļģāļāļēāļĢ trim() āļāđˆāļ­āļ™āđ€āļ›āļĢāļĩāļĒāļšāđ€āļ—āļĩāļĒāļš
command.trim();

if (command.equalsIgnoreCase("get")) {
receivedCommand = command;
Serial.println("Received command: " + receivedCommand);
}
}

void checkGPSCommand() {
Serial.println("Checking GPS Command");

// āļ•āļĢāļ§āļˆāļŠāļ­āļšāļ§āđˆāļēāļĄāļĩāļ„āļģāļŠāļąāđˆāļ‡ "get" āļ–āļđāļāļŠāđˆāļ‡āļĄāļēāļŦāļĢāļ·āļ­āđ„āļĄāđˆ
if (receivedCommand == "get") {
// āļĢāļĩāđ€āļ‹āđ‡āļ•āļ„āļģāļŠāļąāđˆāļ‡āļ—āļĩāđˆāđ„āļ”āđ‰āļĢāļąāļš
receivedCommand = "";

// āļ•āļĢāļ§āļˆāļŠāļ­āļš GPS Data āđāļĨāļ°āļŠāđˆāļ‡ SMS āļ—āļĩāđˆāļĄāļĩāļ‚āđ‰āļ­āļĄāļđāļĨāļ•āļģāđāļŦāļ™āđˆāļ‡ GPS
while (neogps.available()) {
  if (gps.encode(neogps.read())) {
    if (gps.location.isValid()) {
      Serial.println("Sending Location SMS");
      sendLocationSMS();
    } else {
      Serial.println("Invalid GPS Location");
    }
  } else {
    Serial.println("GPS Data Not Received");
  }
  ESP.wdtFeed(); 
}

}
}

void sendLocationSMS() {
Serial.println("entering: sendLocationSMS...");

if (gps.location.isValid()) {
Serial.println("location is valid");

sim800.print("AT+CMGS="" + PHONE_NUMBER + ""\r");
delay(1000);
sim800.print("Google Maps");
sim800.print(gps.location.lat(), 6);
sim800.print(",");
sim800.print(gps.location.lng(), 6);
sim800.println((char)26);
//sim800.write(0x1A); // āđ„āļĄāđˆāļ•āđ‰āļ­āļ‡āđƒāļŠāđ‰ delay āļŦāļĨāļąāļ‡āļˆāļēāļāļāļēāļĢāļŠāđˆāļ‡āļ‚āđ‰āļ­āļĄāļđāļĨ
unsigned long startMillis = millis();
bool timedOut = true;

while (millis() - startMillis < 10000) { // āļĢāļ­āļāļēāļĢāļ•āļ­āļšāļāļĨāļąāļšāļˆāļēāļāđ‚āļĄāļ”āļđāļĨ GSM āļ āļēāļĒāđƒāļ™ 10 āļ§āļīāļ™āļēāļ—āļĩ
ESP.wdtFeed(); //feed dog
yield();//allow other tasks
if (sim800.available()) {
Serial.println("Response available..");
String response = sim800.readString();
Serial.println("Response from GSM module: " + response);
timedOut = false;
break;
}
}
if (!timedOut){
Serial.println("GPS Location SMS Sent Successfully."); } else
Serial.println("Response timed out..");

} else {
Serial.println("Invalid GPS data");
}
}