ESP8266-01 Module Deep Sleep Questions
Posted: Sun Mar 04, 2018 9:04 pm
Hi all,
Im working on a simple temperature and humidity logger for monitoring my beehive. Im having a hard time figuring out why the deep sleep function is not working correctly with my project. The following is a summary of what is happening.
My circuit is as follows.
I also have an external connection between the RST pin and GPIO16 on the actual ESP8266 chip
My code is flashed with Adruino IDE using a USB to TTL converter. When the code boots, it connects to Wi-Fi, takes and posts a sample to ThingSpeak and enters deep sleep. However after the specified time has elapsed, the device does not successfully re-execute the code. The RST pin is high (3.3V) when in deepSleep and drops low (0V) after the RTC has counted one minute. After this happens GPIO 0 is measured to be ~1.5V with a DMM and GPIO 2 is measured to be high. I have done quite a bit of experimenting with software and circuit changes to no avail. Any thought or guidance would be very appreciated
Thank you.
Code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <DHT.h>
#define DHTtype DHT11
DHT dht(2, DHTtype, 11);
const char* ssid = "XXXX";
const char* password = "XXXXX";
float temp,humidity;
WiFiClient client;
const int channelID = 392543;
String APIkey = "XXXXXXXXXXXXXXXX";
const char* server = "api.thingspeak.com";
const int sleepDuration = 1; //Deep Sleep Duration in minutes
void setup() {
Serial.begin(115200);
Serial.println("Serial Test"); //Test Serial Output
dht.begin();
WiFi.begin(ssid, password);
Serial.print("\n\r \n\rWorking to connect");
while (WiFi.status() != WL_CONNECTED) { //Wait for connectiom
delay(500);
Serial.print(".");
}
//Serial Output
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (client.connect(server, 80)) {
delay(2000);
readDHT();//collect humidity and temperature data
// Construct API request body
String body = "field1=";
body += String(temp);
body += "&field2=";
body += String(humidity);
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(body.length());
client.print("\n\n");
client.print(body);
client.print("\n\n");
}
client.stop();
// pinMode(0, OUTPUT);
// digitalWrite(0, HIGH);
// digitalWrite(0, LOW);
Serial.println("sleeping");
delay(15000);
ESP.deepSleep(sleepDuration*60000000,WAKE_RF_DEFAULT);//Enter deep sleep, code executes from beginning on reboot
}
void loop() {
}
void readDHT(){
humidity = dht.readHumidity(); // Read humidity (percent)
temp = dht.readTemperature(0); // Read temperature as Fahrenheit
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp)) {
delay(2000);
Serial.println("Failed to read from DHT sensor");
readDHT();
}
}
Serial Output Generated
⸮Serial Test
Working to connect......Connected to Fletcher_2.4G
IP address: 192.168.50.8
Failed to read from DHT sensor
sleeping
Im working on a simple temperature and humidity logger for monitoring my beehive. Im having a hard time figuring out why the deep sleep function is not working correctly with my project. The following is a summary of what is happening.
My circuit is as follows.
I also have an external connection between the RST pin and GPIO16 on the actual ESP8266 chip
My code is flashed with Adruino IDE using a USB to TTL converter. When the code boots, it connects to Wi-Fi, takes and posts a sample to ThingSpeak and enters deep sleep. However after the specified time has elapsed, the device does not successfully re-execute the code. The RST pin is high (3.3V) when in deepSleep and drops low (0V) after the RTC has counted one minute. After this happens GPIO 0 is measured to be ~1.5V with a DMM and GPIO 2 is measured to be high. I have done quite a bit of experimenting with software and circuit changes to no avail. Any thought or guidance would be very appreciated
Thank you.
Code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <DHT.h>
#define DHTtype DHT11
DHT dht(2, DHTtype, 11);
const char* ssid = "XXXX";
const char* password = "XXXXX";
float temp,humidity;
WiFiClient client;
const int channelID = 392543;
String APIkey = "XXXXXXXXXXXXXXXX";
const char* server = "api.thingspeak.com";
const int sleepDuration = 1; //Deep Sleep Duration in minutes
void setup() {
Serial.begin(115200);
Serial.println("Serial Test"); //Test Serial Output
dht.begin();
WiFi.begin(ssid, password);
Serial.print("\n\r \n\rWorking to connect");
while (WiFi.status() != WL_CONNECTED) { //Wait for connectiom
delay(500);
Serial.print(".");
}
//Serial Output
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (client.connect(server, 80)) {
delay(2000);
readDHT();//collect humidity and temperature data
// Construct API request body
String body = "field1=";
body += String(temp);
body += "&field2=";
body += String(humidity);
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(body.length());
client.print("\n\n");
client.print(body);
client.print("\n\n");
}
client.stop();
// pinMode(0, OUTPUT);
// digitalWrite(0, HIGH);
// digitalWrite(0, LOW);
Serial.println("sleeping");
delay(15000);
ESP.deepSleep(sleepDuration*60000000,WAKE_RF_DEFAULT);//Enter deep sleep, code executes from beginning on reboot
}
void loop() {
}
void readDHT(){
humidity = dht.readHumidity(); // Read humidity (percent)
temp = dht.readTemperature(0); // Read temperature as Fahrenheit
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temp)) {
delay(2000);
Serial.println("Failed to read from DHT sensor");
readDHT();
}
}
Serial Output Generated
⸮Serial Test
Working to connect......Connected to Fletcher_2.4G
IP address: 192.168.50.8
Failed to read from DHT sensor
sleeping