ESP8266 รีเซ็ตเสมอหลังจากทำงาน 65 วินาที

Oct 11 2020

ฉันมีรหัสง่ายๆที่ ESP8266 ถามฐานข้อมูล MySQL เกี่ยวกับสถานะจริงของ LED (ไม่ว่าจะเป็น 1 หรือ 0) และเมื่อ DB มี 1 ESP8266 เปิด LED ... แต่ปัญหาของฉันคือหลังจากเซิร์ฟเวอร์ทำงาน 65-66 วินาทียังคงถูกรีเซ็ต .. โปรแกรมจะทำในสิ่งที่ควรทำ แต่หลังจาก 65-66 วินาทีจะรีเซ็ตและพยายามเชื่อมต่อ wifi อีกครั้ง

---- แก้ไข -----

หลังจากการทดลองบางอย่างกับโค้ดที่ฉันพบมันไม่สำคัญว่าเวลาทำงาน แต่จำนวนรอบการวนซ้ำ ... ทุกครั้งไม่ว่าจะล่าช้าหรือความเร็วในการประมวลผลมันจะพังหลังจาก 48 รอบ ....

.ino รหัส

// Load Wi-Fi library
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

// Replace with your network credentials
const char* ssid     = "XXXX";
const char* password = "XXXX";
const char* host = "http://www.XXXX.XX/arduino_PHP/post_data.php"; 

// Set web server port number to 80
WiFiServer server(80);
HTTPClient http; 

// Variable to store the HTTP request
String header;

// Auxiliar variables to store the current output state
String output5State = "off";
String output4State = "off";

// Assign output variables to GPIO pins
const int output5 = 5;
const int output4 = 4;
byte green, red= 0;

void setup() {
 Serial.begin(115200);
 // Initialize the output variables as outputs
  WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
  WiFi.mode(WIFI_STA);        //This line hides the viewing of ESP as wifi hotspot
 delay(1000);
 pinMode(output5, OUTPUT);
 pinMode(output4, OUTPUT);
 // Set outputs to LOW
 digitalWrite(output5, LOW);
 digitalWrite(output4, LOW);

 // Connect to Wi-Fi network with SSID and password
 Serial.print("Connecting to ");
 Serial.println(ssid);
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 // Print local IP address and start web server
 Serial.println("");
 Serial.println("WiFi connected.");
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP());
 server.begin();
}

void loop(){
delay(500);
DB_state("Green",green);
DB_state("Red",red);
delay(500);
}

void DB_state(String component,int state){
 String postData =("component=" + String(component) + "&state=" + String(state));
 Serial.println(postData);
  http.begin("http://www.XXXX.XX/arduino_PHP/DB_state.php"); 
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
 http.POST(postData);   //Send the request
 String payload = http.getString();    //Get the response payload
 Serial.println(payload);
 http.end();  //Close connection
 state_LED(payload,component);
 }

void state_LED(String str, String led){ 
 int x; 
   if (led== "Green") {
     x = 4;}
   else if (led== "Red") {
      x = 5;}
   if (str == "State: 1") {
     digitalWrite(x, HIGH);}
   else if (str == "State: 0") {
     digitalWrite(x, LOW);}
 }
 

ESP8266 สแต็กดีบัก

Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
PC: 0x4020744a: ClientContext::state() const at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WiFi\src/include/ClientContext.h line 364
EXCVADDR: 0x00000184

Decoding stack results
0x40203f10: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/HardwareSerial.h line 164
0x40203f1c: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/HardwareSerial.h line 165
0x40207512: HTTPClient::connected() at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 475
0x40202d24: HTTPClient::disconnect(bool) at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 434
0x40203ac8: HTTPClient::end() at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp line 425
0x402012ba: DB_State(String, int) at C:\Users\XXXX\Documents\Arduino\ESP8266_php_DB_control/ESP8266_php_DB_control.ino line 87
0x40201334: loop() at C:\Users\XXXX\Documents\Arduino\ESP8266_php_DB_control/ESP8266_php_DB_control.ino line 73
0x40100175: esp_schedule() at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 125
0x40205628: loop_wrapper() at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266\core_esp8266_main.cpp line 197

ขอบคุณสำหรับคำแนะนำใด ๆ

คำตอบ

1 Sahasrar Oct 11 2020 at 16:34

ฉันไม่รู้วิธี แต่ในที่สุดฉันก็พบโซลูชันที่ใช้งานได้ ... ฉันเพิ่มHTTPClient http;ที่ด้านบนของฟังก์ชั่นและใช้งานได้ ...

void DB_state(String component,int state){
HTTPClient http; // THIS IS ADDED
 String postData =("component=" + String(component) + "&state=" + String(state));
 Serial.println(postData);
  http.begin("http://www.XXXX.XX/arduino_PHP/DB_state.php"); 
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
 http.POST(postData);   //Send the request
 String payload = http.getString();    //Get the response payload
 Serial.println(payload);
 http.end();  //Close connection
 state_LED(payload,component);
 }

ใครช่วยอธิบายหน่อยว่ามันเป็นไปได้อย่างไร เพราะฉันไม่เข้าใจขั้นตอนนี้ทั้งหมด