Reputation: 1
I tried to get data from the database mysql using http protocol in esp32 using arduino IDE there is no error but the monitor show this behavior This is the error i had when i run the serial monitor:
Core 0 register dump:
PC : 0x4014fd01 PS : 0x00060030 A0 : 0x80005fdd A1 : 0x3ffcaa60
A2 : 0x3ffcaa92 A3 : 0x3ffcaa90 A4 : 0x00000000 A5 : 0x00001ffe
A6 : 0x00000000 A7 : 0x3ffc8d37 A8 : 0x00001ffe A9 : 0x00000fff
A10 : 0x3ffcaa70 A11 : 0x00006bf5 A12 : 0x00000fff A13 : 0x00000fff
A14 : 0x24221f1c A15 : 0x2e2c2927 SAR : 0x00000000 EXCCAUSE: 0x0000001c
EXCVADDR: 0x80005fe1 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000 ``
this is the code :
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Test Database Access
//======================================== Including the libraries.
#include <WiFi.h>
#include <Arduino.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
//========================================
// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED 2
//======================================== SSID and Password of your WiFi router.
//const char* ssid = "hola";
//const char* password = "12345678";
//========================================
//======================================== Variables for HTTP POST request data.
String postData = ""; //--> Variables sent for HTTP POST request data.
String payload = ""; //--> Variable for receiving response from HTTP POST.
//========================================
//_____________________ Subroutine to control LEDs after successfully fetching data from database.
void control_LEDs() {
Serial.println();
Serial.println("---------------control_LEDs()");
JSONVar myObject = JSON.parse(payload);
// JSON.typeof(jsonVar) can be used to get the type of the var
if (JSON.typeof(myObject) == "undefined") {
Serial.println("Parsing input failed!");
Serial.println("---------------");
return;
}
if (myObject.hasOwnProperty("Name")) {
Serial.print("myObject[\"Name\"] = ");
Serial.println(myObject["Name"]);
}
if (myObject.hasOwnProperty("RFID")) {
Serial.print("myObject[\"RFID\"] = ");
Serial.println(myObject["RFID"]);
}
Serial.println("---------------");
}
//________________________________________________________________________________
//______________________________ VOID SETUP()
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); //--> Initialize serial communications with the PC.
pinMode(ON_Board_LED,OUTPUT); //--> On Board LED port Direction output.
delay(2000);
//---------------------- Make WiFi on ESP32 in "STA/Station" mode and start connecting to WiFi Router/Hotspot.
WiFi.mode(WIFI_STA);
WiFi.begin("hola", "12345678");
//----------------------------------------
Serial.println();
Serial.println("-------------");
Serial.print("Connecting");
//------------------------- The process of connecting the WiFi on the ESP32 to the WiFi Router/Hotspot.
// The process timeout of connecting ESP32 with WiFi Hotspot / WiFi Router is 20 seconds.
// If within 20 seconds the ESP32 has not been successfully connected to WiFi, the ESP32 will restart.
// I made this condition because on my ESP32, there are times when it seems like it can't connect to WiFi, so it needs to be restarted to be able to connect to WiFi.
int connecting_process_timed_out = 20; //--> 20 = 20 seconds.
connecting_process_timed_out = connecting_process_timed_out * 2;
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
//................... Make the On Board Flashing LED on the process of connecting to the wifi router.
/*digitalWrite(ON_Board_LED, HIGH);
delay(250);
digitalWrite(ON_Board_LED, LOW);
delay(250);*/
//........................................
//........................................ Countdown "connecting_process_timed_out".
if(connecting_process_timed_out > 0) connecting_process_timed_out--;
if(connecting_process_timed_out == 0) {
delay(1000);
ESP.restart();
}
//........................................
}
//----------------------------------------
//digitalWrite(ON_Board_LED, LOW); //--> Turn off the On Board LED when it is connected to the wifi router.
//---------------------------------------- If successfully connected to the wifi router, the IP Address that will be visited is displayed in the serial monitor
Serial.println();
Serial.print("Successfully connected to : ");
//Serial.print("IP address: ");
//Serial.println(WiFi.localIP());
Serial.println("-------------");
//----------------------------------------
}
//________________________________________________________________________________
//________________________________________________________________________________ VOID LOOP()
void loop() {
// put your main code here, to run repeatedly
//---------------------------------------- Check WiFi connection status.
if(WiFi.status()== WL_CONNECTED) {
HTTPClient http; //--> Declare object of class HTTPClient.
int httpCode; //--> Variables for HTTP return code.
//........................................ Process to get LEDs data from database to control LEDs.
postData = "id=200035";
payload = "";
digitalWrite(ON_Board_LED, HIGH);
Serial.println();
Serial.println("---------------getdata.php");
// In this project I use local server or localhost with XAMPP application.
// So make sure all PHP files are "placed" or "saved" or "run" in the "htdocs" folder.
// I suggest that you create a new folder for this project in the "htdocs" folder.
// The "htdocs" folder is in the "xampp" installation folder.
// The order of the folders I recommend:
// xampp\htdocs\your_project_folder_name\phpfile.php
//
// ESP32 accesses the data bases at this line of code:
// http.begin("http://REPLACE_WITH_YOUR_COMPUTER_IP_ADDRESS/REPLACE_WITH_PROJECT_FOLDER_NAME_IN_htdocs_FOLDER/getdata.php");
// REPLACE_WITH_YOUR_COMPUTER_IP_ADDRESS = there are many ways to see the IP address, you can google it.
// But make sure that the IP address used is "IPv4 address".
// Example : http.begin("http://192.168.0.0/ESP32_MySQL_Database/Test/getdata.php");
http.begin("http://192.168.43.88/Mysql_database/Test/getRFIDdata.php"); //--> Specify request destination
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //--> Specify content-type header
httpCode = http.POST(postData); //--> Send the request
payload = http.getString(); //--> Get the response payload
Serial.print("httpCode : ");
Serial.println(httpCode); //--> Print HTTP return code
Serial.print("payload : ");
Serial.println(payload); //--> Print request response payload
http.end(); //--> Close connection
Serial.println("---------------");
digitalWrite(ON_Board_LED, LOW);
//........................................
// Calls the control_LEDs() subroutine.
control_LEDs();
delay(1000);
}
}
Upvotes: 0
Views: 534
Reputation: 17278
You should use https://github.com/me-no-dev/EspExceptionDecoder to decode the stack trace. The tool presents a window where you can paste the exception stack (the line in the core dump that starts with Backtrace
) and creates an user-readable stack dump. That should help you to get an idea where things went wrong.
Upvotes: 0