The board goes to deep sleep for 20 minutes and wakes up, no problem, but power consumption in deepSleep is problem. Here is the code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include "ESP8266WiFi.h"
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
const char* ssid = "njka Local";
const char* password = "!3bNwjSf9";
const char* serverName = "http://controltemp.online/emmezeta/connect_dako.php";
String sensid = "dse1p2";
const int oneWireBus = 2;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("*");
}
sensors.begin();
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
http.begin(serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData = "&sensid=" + sensid + "&temp1=" +
String(temperatureC) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
//Send an HTTP POST request every 20 minutes
ESP.deepSleep(1200e6, WAKE_RF_DEFAULT);
}
void loop() {
}