Example http request code crashes after a few requests
Posted: Mon Mar 25, 2019 11:36 pm
Hi there,
I come from the web development world: php, javascript, python, etc but I've taken a love for IoT, and started a project that I've been thinking about for the last 3 years or so.
I've got my ESP8266 NodeMCU 0.9 ESP-12 module that has an attached SSD1306 OLED screen. I've been able to get the screen working and all that pretty smoothly but it's the HTTP transactions I'm having trouble with.
I grabbed some demo code, it seems to work but then after just a couple times through the loop it resets with this:
Decoding stack results
0x40202674: loop() at /Users/jminton/Desktop/esp/httpsTest/httpsTest.ino line 46
0x402040c8: loop_wrapper() at /Users/jminton/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/core_esp8266_main.cpp line 125
What am i doing wrong? what else do you need to help me?
Thanks!
I come from the web development world: php, javascript, python, etc but I've taken a love for IoT, and started a project that I've been thinking about for the last 3 years or so.
I've got my ESP8266 NodeMCU 0.9 ESP-12 module that has an attached SSD1306 OLED screen. I've been able to get the screen working and all that pretty smoothly but it's the HTTP transactions I'm having trouble with.
I grabbed some demo code, it seems to work but then after just a couple times through the loop it resets with this:
Decoding stack results
0x40202674: loop() at /Users/jminton/Desktop/esp/httpsTest/httpsTest.ino line 46
0x402040c8: loop_wrapper() at /Users/jminton/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/core_esp8266_main.cpp line 125
Code: Select all
#include <ESP8266WiFi.h>
const char* ssid = "ssid";
const char* password = "";
const char* host = "site.com";
const int port = 80;
const String url = "/api/temperatureAlarmMonitor.php";
WiFiClient client;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
WiFiClient client;
}
void loop() {
Serial.printf("\n[Connecting to %s ... ", host);
if (client.connect(host, port))
{
Serial.println("connected]");
Serial.println("[Sending a request]");
client.print(String("GET /api/temperatureAlarmMonitor.php") + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n" +
"\r\n"
);
Serial.println("[Response:]");
while (client.connected() || client.available()) //// <<< -----------------here line 46
{
if (client.available())
{
Serial.println(client.readStringUntil('\n'));
}
}
// client.stop();
Serial.println("\n[Disconnected]");
}
else
{
Serial.println("connection failed!]");
// client.stop();
}
delay(5000);
}
What am i doing wrong? what else do you need to help me?
Thanks!