Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By chamathkv
#79129 I am using a NodeMCU V3 (ESP8266) module. I tried to make a simple datalogger that connects to a WiFi and uploads data to ThingSpeak. Since the NodeMCU takes a lot of power and since it won't be used all the time, I wanted to put it to deepsleep until it is needed again. However, after it goes to sleep it doesn't seem to wake up again. I connected the GPIO16 to the RST pin as required. The code is given below.


Code: Select all#include <DallasTemperature.h>
#include <OneWire.h>
#include <DHT.h> 
#include <ESP8266WiFi.h> 
#include <WiFiClient.h> 
#include <ThingSpeak.h> 
#define LED_BULB 4
#define ONE_WIRE_BUS 0                          //D1 pin of nodemcu
#define DHTPIN 5 
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE); 

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

const char* ssid = "XXXXX"; 
const char* password = "XXXXX"; 
WiFiClient client; 
unsigned long myChannelNumber = XXXXX; 
const char * myWriteAPIKey = "XXXXX"; 
uint8_t temperature, humidity, dsb; 


void startup()
{
  pinMode(LED_BULB, OUTPUT);
  digitalWrite(LED_BULB, LOW);
  Serial.begin(115200); 
  dht.begin(); 
  delay(10); 
  // Connect to WiFi network 
  Serial.println(); 
  Serial.println(); 
  Serial.print("Connecting to "); 
  Serial.println(ssid); 
  WiFi.begin(ssid, password); 
  while (WiFi.status() != WL_CONNECTED) 
  { 
   delay(500); 
   Serial.print("."); 
  } 
  Serial.println(""); 
  Serial.println("WiFi connected"); 
  // Print the IP address 
  Serial.println(WiFi.localIP()); 
  ThingSpeak.begin(client); 
  sensors.begin(); 
}

void setup() 





void loop()   


  startup();
 
  Serial.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  sensors.requestTemperatures(); 
  Serial.print("DSB Temperature is: ");
  Serial.println(sensors.getTempCByIndex(0));
  dsb = sensors.getTempCByIndex(0);
 
  temperature = dht.readTemperature(); 
  humidity = dht.readHumidity(); 
  Serial.print("Temperature Value is :"); 
  Serial.print(temperature); 
  Serial.println("C"); 
  Serial.print("Humidity Value is :"); 
  Serial.print(humidity); 
  Serial.println("%"); 

  digitalWrite(LED_BULB, HIGH);
  Serial.println("Uploading DHT temp"); 
  ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);
  delay(30000); 
  Serial.println("Uploading DHT hum");
  ThingSpeak.writeField(myChannelNumber, 2, humidity, myWriteAPIKey); 
  delay(30000); 
  Serial.println("Uploading DS temp");
  ThingSpeak.writeField(myChannelNumber, 3, dsb, myWriteAPIKey); 
  Serial.println("Done uploading");
  delay(30000);
  digitalWrite(LED_BULB, LOW);
  delay(500);
  digitalWrite(LED_BULB, HIGH);
  delay(500);
  digitalWrite(LED_BULB, LOW);
  delay(500);
  digitalWrite(LED_BULB, HIGH);
  delay(500);
  digitalWrite(LED_BULB, LOW);
  delay(500);
 
  Serial.println("Sleeping");
  ESP.deepSleep(120000000); //sleeping for 120 seconds
  Serial.println("Waking up");
}



The output on the serial monitor is as shown below.


Code: Select allConnecting to XXXXX
..............................................................
WiFi connected
XXXXXX


DSB Temperature is: 26.56
Temperature Value is :25C
Humidity Value is :92%
Uploading DHT temp
Uploading DHT hum
Uploading DS temp
Done uploading
Sleeping


After printing 'sleeping', some mixed up jargon will be printed and that's it.
User avatar
By Pablo2048
#79130 Probably you have got wrong what deepsleep mean - the only exit from deepsleep is via reset so your Serial.println("Waking up"); will never execute. Also your startup() and loop() make no sense - if you want to do things this way, then everything should be done in setup(). This "mixed jargon" is probably boot message from ESP@76800bd.
User avatar
By chamathkv
#79174
Pablo2048 wrote:Probably you have got wrong what deepsleep mean - the only exit from deepsleep is via reset so your Serial.println("Waking up"); will never execute. Also your startup() and loop() make no sense - if you want to do things this way, then everything should be done in setup(). This "mixed jargon" is probably boot message from ESP@76800bd.


Wait, if deepsleep can only be exited via the reset pin, then why does it have a timer? What happens at the end of the timer?
User avatar
By schufti
#79175 it is a design flaw. w/o connecting gpio16-rst the esp wakes but will not start user code.
with gpio16-rst it behaves like regular reset and starts up like on reset (not power on).
startup reason can be checked in code.