Closed kruwanchai closed 11 months ago
.........after send sms to system... it 's show ... User 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.........
const String PHONE_NUMBER = "+669xxxxxxxx";
// Define RX/TX pins for GSM Module
SoftwareSerial sim800(GSM_RX_PIN, GSM_TX_PIN);
// Define RX/TX pins for GPS Module
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); 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) { // ... command.trim();
if (command.equalsIgnoreCase("get")) { receivedCommand = command; Serial.println("Received command: " + receivedCommand); } }
void checkGPSCommand() { Serial.println("Checking GPS Command");
// ... if (receivedCommand == "get") { // ... receivedCommand = "";
// ... 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("http://maps.google.com/maps?q="); sim800.print(gps.location.lat(), 6); sim800.print(","); sim800.print(gps.location.lng(), 6); sim800.write(0x1A); // ... sim800.flush(); unsigned long startMillis = millis(); while (millis() - startMillis < 10000) { // .... 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"); } }
.........after send sms to system... it 's show ... User 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
include <TinyGPS++.h>
const String PHONE_NUMBER = "+669xxxxxxxx";
// 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); 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) { // ... command.trim();
if (command.equalsIgnoreCase("get")) { receivedCommand = command; Serial.println("Received command: " + receivedCommand); } }
void checkGPSCommand() { Serial.println("Checking GPS Command");
// ... if (receivedCommand == "get") { // ... receivedCommand = "";
} }
void sendLocationSMS() { Serial.print("Sending Location SMS...");
if (gps.location.isValid()) { sim800.print("AT+CMGS=\"" + PHONE_NUMBER + "\"\r"); delay(1000); sim800.print("http://maps.google.com/maps?q="); sim800.print(gps.location.lat(), 6); sim800.print(","); sim800.print(gps.location.lng(), 6); sim800.write(0x1A); // ... sim800.flush(); unsigned long startMillis = millis(); while (millis() - startMillis < 10000) { // .... 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"); } }