Greetings,
I was trying to learn some IOT stuff, for which I was trying out the code from circuits4you.com The code runs fine (on ESP-01) if it is compiled and uploaded through Arduino IDE . But if the same code is compiled and uploaded via VS Code using PlatformIO plugin , it uploads successfully but crashes when the client tries to connect to the server on esp-01…
Code is:
#include <Arduino.h> //NB: Not used in Arduino IDE Code
#include <pgmspace.h> //NB: Not used in Arduino IDE Code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//---------------------------------------------------------------------
// HTML webpage in program memory
const char MAIN_page[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<body>
<center>
<h1>WiFi LED on off demo: 1</h1><br>
<p>Ciclk to turn <a href="ledOn">LED ON</a></p>
<p>Ciclk to turn <a href="ledOff">LED OFF</a></p>
<hr>
</center>
</body>
</html>
)=====";
//-----------------------------------------------------------------------
// On board LED Connected to GPIO2
#define LED 2
// SSID and Password of your WiFi router
const char *ssid = "Crystals";
const char *password = "123456";
ESP8266WebServer server(80); // Server on port 80
//-------------------------------------------------------------------------
void handleRoot()
{
Serial.println("You called root page");
String s = MAIN_page; // Read HTML contents
server.send(200, "text/html", s); // Send web page
}
void handleLEDon()
{
Serial.println("LED on page");
digitalWrite(LED, LOW); // LED is connected in reverse
server.send(200, "text/html", "LED is ON"); // Send ADC value only to client ajax request
}
void handleLEDoff()
{
Serial.println("LED off page");
digitalWrite(LED, HIGH); // LED off
server.send(200, "text/html", "LED is OFF"); // Send ADC value only to client ajax request
}
/-----------------------------------------------------------------------------------------------------------------------
// SETUP
//----------------------------------------------------------------------------------------------------------------------
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password); // Connect to your WiFi router
Serial.println("");
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/ledOn", handleLEDon); // as Per <a href="ledOn">, Subroutine to be called
server.on("/ledOff", handleLEDoff);
server.begin(); // Start server
Serial.println("HTTP server started");
}
//----------------------------------------------------------------------------------------------------------------------
// LOOP
//----------------------------------------------------------------------------------------------------------------------
void loop()
{
server.handleClient(); // Handle client requests
}
Serial Monitor Output of VS Code :
--- Miniterm on COM5 115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
.........
Connected to Crystals
IP address: 192.168.18.77
HTTP server started
New client
request: GET /readRELAYState HTTP/1.1
method: GET url: /readRELAYState search:
headerName: Host
headerValue: 192.168.18.77
headerName: Connection
headerValue: keep-alive
headerName: User-Agent
headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
headerName: DNT
headerValue: 1
headerName: Accept
headerValue: */*
headerName: sec-gpc
headerValue: 1
headerName: Referer
headerValue: http://192.168.18.77/
headerName: Accept-Encoding
headerValue: gzip, deflate
headerName: Accept-Language
headerValue: en-US,en;q=0.9
args:
args count: 0
args:
args count: 0
Request: /readRELAYState
Arguments:
final list of key/value pairs:
request handler not found
New client
request: GET /readRELAYState HTTP/1.1
method: GET url: /readRELAYState search:
headerName: Host
headerValue: 192.168.18.77
headerName: Connection
headerValue: keep-alive
headerName: User-Agent
headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
headerName: DNT
headerValue: 1
headerName: Accept
headerValue: */*
headerName: sec-gpc
headerValue: 1
headerName: Referer
headerValue: http://192.168.18.77/
headerName: Accept-Encoding
headerValue: gzip, deflate
headerName: Accept-Language
headerValue: en-US,en;q=0.9
args:
args count: 0
args:
args count: 0
Request: /readRELAYState
Arguments:
final list of key/value pairs:
request handler not found
New client
request: GET / HTTP/1.1
method: GET url: / search:
headerName: Host
headerValue: 192.168.18.77
headerName: Connection
headerValue: keep-alive
headerName: Cache-Control
headerValue: max-age=0
headerName: DNT
headerValue: 1
headerName: Upgrade-Insecure-Requests
headerValue: 1
headerName: User-Agent
headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
headerName: Accept
headerValue: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
headerName: sec-gpc
headerValue: 1
headerName: Accept-Encoding
headerValue: gzip, deflate
headerName: Accept-Language
headerValue: en-US,en;q=0.9
args:
args count: 0
args:
args count: 0
Request: /
Arguments:
final list of key/value pairs:
You called root page
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4023dc01 depc=0x00000000
LoadStoreError: Processor internal physical address or data error during load or store
excvaddr=0x4023dc01 in sleep_reset_analog_rtcreg_8266 at ??:?
>>>stack>>>
ctx: cont
sp: 3ffffd00 end: 3fffffc0 offset: 0190
3ffffe90: 00000001 00000001 4023dc01 40205def
3ffffea0: 3ffefbf0 00000001 3ffef9ec 4020349e
3ffffeb0: 3fffff00 3fffff10 80fffef0 40201bc0
3ffffec0: 00000001 402088dc 3ffffef0 402088aa
3ffffed0: 3fffff10 3ffee558 3ffef9ec 401000e1
3ffffee0: 3ffef9ec 3ffee558 3ffef9ec 40201bf8
3ffffef0: 3ffe0000 00000000 8030000a 80207ad9
3fffff00: 3ffef9ec 3ffee558 3ffee518 40203501
3fffff10: 0000002f 80000000 81ff0000 0000008f
3fffff20: 80005054 3ffee634 4010021c 0000a8e5
3fffff30: 3ffee558 00000001 3ffe876f 402056b5
3fffff40: 00000001 00000001 0000000f 40205874
3fffff50: 3fffdad0 00000000 3ffee518 3ffee6b0
3fffff60: 00000001 3ffee53c 3ffee518 4020393b
3fffff70: 40208d18 00000000 00001388 80efeffe
3fffff80: 00000000 3fff0004 00000001 40100170
3fffff90: 3fffdad0 00000000 3ffee670 402039dc
3fffffa0: 3fffdad0 00000000 3ffee670 40206d34
3fffffb0: feefeffe feefeffe 3ffe84ec 40100c49
<<<stack<<<
0x4023dc01 in sleep_reset_analog_rtcreg_8266 at ??:?
0x40205def in String::String(char const*) at ??:?
0x4020349e in handleRoot() at ??:?
0x40201bc0 in esp8266webserver::FunctionRequestHandler<WiFiServer>::handle(esp8266webserver::ESP8266WebServerTemplate<WiFiServer>&, HTTPMethod, String) at ??:?
0x402088dc in esp8266webserver::FunctionRequestHandler<WiFiServer>::canHandle(HTTPMethod, String) at ??:?
0x402088aa in std::_Function_handler<void (), void (*)()>::_M_invoke(std::_Any_data const&) at ??:?
0x401000e1 in std::function<void ()>::operator()() const at ??:?
0x40201bf8 in esp8266webserver::FunctionRequestHandler<WiFiServer>::handle(esp8266webserver::ESP8266WebServerTemplate<WiFiServer>&, HTTPMethod, String) at ??:?
0x40203501 in esp8266webserver::ESP8266WebServerTemplate<WiFiServer>::_handleRequest() at ??:?
0x4010021c in millis at ??:?
0x402056b5 in Print::write(char const*) at ??:?
0x40205874 in Print::println() at ??:?
0x4020393b in esp8266webserver::ESP8266WebServerTemplate<WiFiServer>::handleClient() at ??:?
0x40208d18 in precache at ??:?
0x40100170 in ets_post at ??:?
0x402039dc in loop at ??:?
0x40206d34 in loop_wrapper() at core_esp8266_main.cpp:?
0x40100c49 in cont_wrapper at ??:?
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
platformio.ini file
[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
monitor_speed = 115200
board_build.flash_mode = dout
monitor_filters = esp8266_exception_decoder
build_flags = -DDEBUG_ESP_HTTP_SERVER
Thanks