Ive just updated my arduino ide support for the ESP8266 to the latest stable version.
But a previously working program using the sleep timers is now playing up.
Im using an ESP8266-12 on a breadboard exactly as I did when it was working under the previous Stable version.
Usually I use the board definition for the Nodemcu for the esp8266-12.
I have also tried the generic definition but it still fails.
I notice that the board definitions now mentions spiffs does this reduce the memory available?
Im getting what seems to be a stack overflow after it connects to the wifi router.
This will happen after a couple of sleep and restarts
The ESP then reboots and can no longer connect to the wifi router.
I get this in the serial monitor:
ctx: cont
sp: 3ffea830 end: 3ffeaa90 offset: 01b0
>>>stack>>>
3ffea9e0: 40208d19 3ffe9a44 3ffeaad0 42020000
3ffea9f0: 41ae6666 3ffe9778 3ffe9a44 3ffe9728
3ffeaa00: 3ffe9728 00000000 00000000 3ffe9728
3ffeaa10: 3ffe9728 4020234c 3ffe9a44 3ffe9778
3ffeaa20: 42020000 3ffe9778 3ffe9a44 40202347
3ffeaa30: 00000000 00000000 00000000 00000000
3ffeaa40: 00000000 00000000 00000000 00000000
3ffeaa50: 00000000 00000000 00000000 00000000
3ffeaa60: 00000000 00000000 00000000 3ffeaabc
3ffeaa70: 3fffdc20 00000000 3ffeaab4 4020183f
3ffeaa80: 00000000 00000000 3ffe9a70 40100378
<<<stack<<<
i�߈�
JZ�!!)���Zn�����DnZ��*��Xj(ȽC����H �ܿHn:���O��d
Ive added a count into the loop waiting for the connection so that the ESP restarts after 20 iterations of the loop. As previously it would have connected by then. Hoping that a restart would clear whatever is causing the problem.
But it hasnt helped.
Heres my code:
#include <DHT.h>
#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
uint16 readvdd33(void);
}
// replace with your channel's thingspeak API key,
String apiKey = "N33F4IRBI8EI8K8J";
const char* ssid = "ThisOldHouse";
const char* password = "thingstodoinalandrover";
const char* server = "api.thingspeak.com";
#define DHTPIN 2 // what pin we're connected to
//const unsigned long SLEEP_INFTERVAL = 10 * 60 * 1000 * 1000; // 10 minutes
const unsigned long SLEEP_INFTERVAL = 30 * 1000 * 1000; // 30 seconds
DHT dht(DHTPIN, DHT22,15);
WiFiClient client;
void setup() {
Serial.begin(57600);
delay(10);
dht.begin();
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
int c = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
c++;
if (c > 20){ESP.restart();}
}
Serial.println("");
Serial.println("WiFi connected");
// ################################ get and send reading
float h = dht.readHumidity();
float t = dht.readTemperature();
float vdd = readvdd33() / 1000.0;
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.println();
Serial.print("Temperature: ");
Serial.print(t);
Serial.print("c - Humidity: ");
Serial.print(h);
Serial.print("% - Voltage: ");
Serial.print(vdd);
Serial.println("v ");
Serial.println();
Serial.println("Send to Thingspeak");
Serial.println();
while (!client.connect(server, 80)) {
Serial.println("connection failed, retrying...");
}
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr +="&field3=";
postStr += String(vdd);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
// wait for response
while(!!!client.available()) {
delay(10);
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("Response: ");
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
client.stop();
Serial.print("up time: ");
Serial.print(millis());
Serial.print(", deep sleep for ");
Serial.print(SLEEP_INFTERVAL / 1000000);
Serial.println(" secs...");
system_deep_sleep_set_option(0);
system_deep_sleep(SLEEP_INFTERVAL - micros());
}
void loop() {
}
Ill leave this posted here in case anyone else is having problems and can point me to a solution or tell me what the message in the serial monitor means.
If I dont get much response Ill raise it on the ESP8266 Arduino GitHub project.
Thanks
Gordon