I've made a "weather station" using the ESP8622. To save battery I'm using sleep mode but still the battery is drained after a couple of days. According to this post it should last at least a year.
I haven't done any measurements yet, wanted to know if there's something obvious that I've missed that could explain why the battery is drained so quickly? Attaching code and an image showing the hardware setup.
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#define DHTPIN D2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "xxxx";
const char* password = "xxxx";
const char* host = "xxxx";
void setup() {
Serial.begin(115200);
dht.begin();
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
readSensorsAndPost();
ESP.deepSleep(18e8); //30 minutes
}
void readSensorsAndPost() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
char charVal[10];
dtostrf(t, 5, 2, charVal);
makeAnHttpRequest(charVal);
}
bool makeAnHttpRequest(String msg) {
//send the value
}
void loop() {
}