- Wed Jan 04, 2017 10:41 am
#60384
Dear chupo_cro,
Thank you for our answer, I didn't see it until now! Sorry! I must say that the ESP8266 I was using worked pretty fine during 17 days without any crash, sending MAC, temperature and voltage to a server every two minutes. It was working pretty good, but in the day 17 (although having 4.0V in the battery, a 7600mAh LiPo one) it crashed and never woke up again until I forced a reset. I don't really know why, nothing changed all this time (no Wifi or battery or whatever).
By the way, I was here again to tell you about the performance of the device. I have included the WiFi.forceSleepWake() before the WiFi.begin() and also I have closed the WiFiClient and the WiFi connection before going to DeepSleep, but not sure if it is needed:
Code: Select all WiFi.forceSleepWake();
if(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, password);
}
int j = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
j++;
if (j == 50) {
break;
}
//Serial.print(".");
}
//Serial.println(WiFi.localIP());
//Serial.println(WiFi.status());
if (WiFi.status() == WL_CONNECTED) {
mac = WiFi.macAddress();
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
client.stop();
delay(100);
WiFi.disconnect();
delay(100);
ESP.deepSleep(120000000, WAKE_RF_DEFAULT);
delay(1000);
//return;
}
if ((err = dht11.read(hum, temp)) == 0) /
{
}
else
{
temp = 99;
}
int vcc = ESP.getVcc();
String vc;
vc = String((int)vcc);
webString = String((int)temp); // Arduino has a hard time with float to string
String url = whatever;
client.print(String("GET ") + url + webString + String("&mac=") + mac + String("&vc=") + vc + " HTTP/1.1\r\n" + "Host:" + host + "\r\n" + "Connection: close\r\n\r\n");
delay(100);
client.stop();
delay(100);
//1200000000us son 20 minutos
}
if(WiFi.status() == WL_CONNECTED){
WiFi.disconnect();
}
delay(1000);
ESP.deepSleep(120000000, WAKE_RF_DEFAULT);
delay(100);
I will see what happens now. I am not sure if I can do the client.close() statement if the client doesn't connect to the host, but it is working fine by now... Do you see anything wrong in it?