0

No Update when ESP.DeepSleep'ing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

No Update when ESP.DeepSleep'ing

by anthonyjclarke on Mon Oct 01, 2018 5:03 pm

*Newbie Alert*
Using the example DHT Temp logger, and all fine and working first time :)
However when I replace the Delay() with ESP.deepSleep(sleepSeconds * 1000000); the sketch continues to function (based on Serial monitor)
BUT there is no update to Adafruit.IO.... as soon as I switch back to Delay() its all working.

Here's my sketch,
Code: Select all | TOGGLE FULL SIZE
// Adafruit IO Temperature & Humidity Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016-2017 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
// v1.0 October 1 2018
// Want to get Sleep working / initial attempt works but does not update Adafruit despite log saying so.
//
//

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

// pin connected to DH22 data line
#define DATA_PIN D4 // Pin 2

// create DHT22 instance
DHT_Unified dht(DATA_PIN, DHT22);

// set up the 'temperature' and 'humidity' feeds
AdafruitIO_Feed *temperature = io.feed("temperature");
AdafruitIO_Feed *humidity = io.feed("humidity");

const int sleepSeconds = 60;    // 10 mins = 600 seconds

void setup() {

  // start the serial connection
  Serial.begin(115200);

  // Connect D0 to RST to wake up
  pinMode(D0, WAKEUP_PULLUP);

  // wait for serial monitor to open
  while(! Serial);

  // initialize dht22
  dht.begin();

  // connect to io.adafruit.com
  Serial.print("\n\nConnecting to Adafruit IO");
  io.connect();

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();
  //
  Serial.println("\nStart of Loop(),\nConnecting to AdafruitIO");
 
  // wait for a connection - Probably not necessary, trying to Debug!
 
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println(io.statusText());

  sensors_event_t event;
 
  dht.temperature().getEvent(&event);
  float celsius = event.temperature;

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");

  dht.humidity().getEvent(&event);

  Serial.print("humidity: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");

  // save celsius & humidity to Adafruit IO
  temperature->save(celsius);
  humidity->save(event.relative_humidity);

  // wait 5 seconds (5000 milliseconds == 5 seconds)
  delay(60000);

  Serial.println("\nSleeping now");

   // convert to microseconds
  // ESP.deepSleep(sleepSeconds * 1000000);

}
Last edited by brubell on Tue Oct 02, 2018 5:32 pm, edited 1 time in total.
Reason: Please use [code] tags for readability

anthonyjclarke
 
Posts: 9
Joined: Sun Jul 26, 2015 5:48 pm

Re: No Update when ESP.DeepSleep'ing

by brubell on Tue Oct 02, 2018 9:59 am

When using ESP.deepsleep with Adafruit IO, nothing should happen within the loop(), it should make a call to esp.deepsleep from within setup(): https://github.com/adafruit/Adafruit_IO ... ep.ino#L45

Here's a full example of Adafruit IO and ESP's DeepSleep: https://github.com/adafruit/Adafruit_IO ... psleep.ino

brubell
 
Posts: 185
Joined: Fri Jul 17, 2015 10:33 pm

Re: No Update when ESP.DeepSleep'ing

by anthonyjclarke on Tue Oct 02, 2018 4:07 pm

brubell wrote:When using ESP.deepsleep with Adafruit IO, nothing should happen within the loop(), it should make a call to esp.deepsleep from within setup(): https://github.com/adafruit/Adafruit_IO ... ep.ino#L45

Thanks!

Here's a full example of Adafruit IO and ESP's DeepSleep: https://github.com/adafruit/Adafruit_IO ... psleep.ino


Grr, lesson to self RTFM / examples and get to end before asking questions.

Really appreciate your help though!

anthonyjclarke
 
Posts: 9
Joined: Sun Jul 26, 2015 5:48 pm

Re: No Update when ESP.DeepSleep'ing

by anthonyjclarke on Tue Oct 02, 2018 5:14 pm

Sorry to be back, but adapted all the code (see below)....

I am getting one variable written to IO, not the second.... am I missing something :(

When I switch around the writes, only the first gets written, is there a limitation here?

humid->save(event.relative_humidity);
temp->save(celsius);


Feeds.png
Feeds.png (39.47 KiB) Viewed 132 times



Code: Select all | TOGGLE FULL SIZE
// Adafruit IO Temperature & Humidity Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016-2017 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
// v1.0 October 1 2018
// Initial Release
// v1.1 October 3 2018
// Adapted after feedback from support to contain all writing in setup()
// Issue still is only writing one value....
//
//

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

// pin connected to DH22 data line
#define DATA_PIN D4 // Pin 2

// create DHT22 instance
DHT_Unified dht(DATA_PIN, DHT22);

const int sleepSeconds = 60;    // 10 mins = 600 seconds

void setup() {

  // start the serial connection
  Serial.begin(115200);

  // Connect D0 to RST to wake up
  pinMode(D0, WAKEUP_PULLUP);

  // wait for serial monitor to open
  while(! Serial);
  Serial.println("\nAdafruit IO + DeepSleep");

  // connect to the Adafruit IO Library
  connectAIO();

  // initialize dht22
  dht.begin();

  delay(500);
 
  // set up and write to feed
  feedWrite();

  // let's go back to sleep for DEEPSLEEP_DURATION seconds...
  Serial.println("sleeping...");
  // Put the ESP into deepsleep for DEEPSLEEP_DURATION
  // NOTE: Make sure Pin 16 is connected to RST
  // convert to microseconds
  ESP.deepSleep(sleepSeconds * 1000000);

}

// NOOP
void loop() {
}

void feedWrite(){

  // set up the 'temperature' and 'humid' feeds
  AdafruitIO_Feed *temp = io.feed("temperature");
  AdafruitIO_Feed *humid = io.feed("humidity");

  sensors_event_t event;
 
  dht.temperature().getEvent(&event);
  float celsius = event.temperature;

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");

  dht.humidity().getEvent(&event);

  Serial.print("humid: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");

  // save celsius & humidity to Adafruit IO
  Serial.println("Now writing to Adafruit IO");
  temp->save(celsius);
  humid->save(event.relative_humidity);
 
  io.run();

}

void connectAIO() {
  Serial.println("Connecting to Adafruit IO...");
  io.connect();

  // wait for a connection
  while (io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());
}

anthonyjclarke
 
Posts: 9
Joined: Sun Jul 26, 2015 5:48 pm

Re: No Update when ESP.DeepSleep'ing

by brubell on Wed Oct 03, 2018 9:48 am

Do you see both incoming values on your monitor when they're sent? https://io.adafruit.com/monitor

Try adding a print statement between the two to make sure they're executing in-order:

Code: Select all | TOGGLE FULL SIZE
  // save celsius & humidity to Adafruit IO
  Serial.println("Sending temp...");
  temperature->save(celsius);
  Serial.println("Sending Humid...");
  humidity->save(event.relative_humidity);

brubell
 
Posts: 185
Joined: Fri Jul 17, 2015 10:33 pm

Re: No Update when ESP.DeepSleep'ing

by anthonyjclarke on Wed Oct 03, 2018 6:19 pm

Thanks for ongoing support,

I modified the code (to do a serial print and introduce a "delay" in case that would help)

Code: Select all | TOGGLE FULL SIZE
dht.temperature().getEvent(&event);
  float celsius = event.temperature;
  dht.humidity().getEvent(&event);
 
  // save celsius & humidity to Adafruit IO
  Serial.println("Now writing to Adafruit IO");

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");
  temp->save(celsius);

  Serial.print("humid: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");
 
  humid->save(event.relative_humidity);
 
  io.run();


Looking at the Monitor, this is what I see, and I've shown the output from the Serial port

Monitor.png
Monitor.png (251.96 KiB) Viewed 114 times


If I change the sleep to a Delay in the loop() then this is what I see....

Monitor_Delay.png
Monitor_Delay.png (198.82 KiB) Viewed 114 times


Any suggestions? do you have any sample code where multiple values can be uploaded after a deep sleep?

anthonyjclarke
 
Posts: 9
Joined: Sun Jul 26, 2015 5:48 pm

Re: No Update when ESP.DeepSleep'ing

by brubell on Wed Oct 03, 2018 7:09 pm

Any suggestions? do you have any sample code where multiple values can be uploaded after a deep sleep?

Not that I know of, we'll go through it together though :)

Try moving io.run(); from the bottom of the function, to the top?

brubell
 
Posts: 185
Joined: Fri Jul 17, 2015 10:33 pm

Re: No Update when ESP.DeepSleep'ing

by anthonyjclarke on Wed Oct 03, 2018 8:12 pm

Made a change to the code, moving io.run to the top

Code: Select all | TOGGLE FULL SIZE
void feedWrite(){

  // set up the 'temperature' and 'humid' feeds
  AdafruitIO_Feed *temp = io.feed("temperature");
  AdafruitIO_Feed *humid = io.feed("humidity");

  sensors_event_t event;
 
  dht.temperature().getEvent(&event);

  delay(500);

  // read again

  dht.temperature().getEvent(&event);
  float celsius = event.temperature;
  dht.humidity().getEvent(&event);
   
  io.run();
 
  // save celsius & humidity to Adafruit IO
  Serial.println("Now writing to Adafruit IO");

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");
  temp->save(celsius);

  Serial.print("humid: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");
 
  humid->save(event.relative_humidity);

}


Monitor_DS2.png
Monitor_DS2.png (275.7 KiB) Viewed 108 times


Now no updates!

anthonyjclarke
 
Posts: 9
Joined: Sun Jul 26, 2015 5:48 pm

Re: No Update when ESP.DeepSleep'ing

by anthonyjclarke on Wed Oct 03, 2018 8:48 pm

Did some other testing, using the sample code #19 for Deep Sleep.
With one value written works.
With the addition of deepsleep2 this results in NO updates.

Code: Select all | TOGGLE FULL SIZE
void feedWrite(){
   // set up `deepsleep` feed
  AdafruitIO_Feed *deepsleep = io.feed("deepsleep");
  AdafruitIO_Feed *deepsleep2 = io.feed("deepsleep2");
  Serial.println("sending value to feed 'deepsleep");
  // send data to deepsleep feed
  deepsleep->save(1);
  deepsleep2->save(2);
  // write data to AIO
  io.run();


deepsleep1.png
deepsleep1.png (264.15 KiB) Viewed 103 times

anthonyjclarke
 
Posts: 9
Joined: Sun Jul 26, 2015 5:48 pm

Re: No Update when ESP.DeepSleep'ing

by anthonyjclarke on Wed Oct 10, 2018 5:40 pm

Just wondering if you / anyone had any suggestions here?

anthonyjclarke
 
Posts: 9
Joined: Sun Jul 26, 2015 5:48 pm

Please be positive and constructive with your questions and comments.