ESP32 not updating ArduinoCloud after esp_deep_sleep


I am trying to set up an IoT showing the value of the outside temperature (measured with a Dallas temperature sensor) at regular intervals.

That works if I leave the ESP32 on, however battery does not last long, therefore I am trying to make it go in deep sleep mode between measurements & updates, and although the correct temperature measurement is still done (as visible on the Serial Monitor), the dashboard is not updated (and only the very first value is displayed).

Here is my code:

#include "thingProperties.h"
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 14 on the Arduino
#define ONE_WIRE_BUS 14

#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  10       /* Time ESP32 will go to sleep (in seconds) */

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

void setup() {
  // Initialize serial and wait for port to open:
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found

  // Defined in thingProperties.h

  // Connect to Arduino IoT Cloud
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  Serial.println("Setup ESP32 to sleep every " + String(TIME_TO_SLEEP) + "s");

void loop() {
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  celcius = sensors.getTempCByIndex(0);
  celcius = int(celcius*100.+0.5)/100.;

  Serial.print("Temperature for the device 1 (index 0) is: ");

What am I doing wrong?
Can someone help me sort this out?



Is there nobody here that has any clue?

I tried to move the section about //Connect to Arduino IoT Cloud from the setup to the loop so that it would try to connect every time, which it does, however there is still no update on the dashboard

Is there something incompatible between the arduino iot cloud and ESP32?

Am I the only one having these issues?

First thing you have to make sure that works is the ESP32 actually wakes up after you put it into sleep. Can you verify that the ESP32 wakes up?

Also, a deep sleep in ESP32 terms is almost the same as a RESET. So you might have to reconnect to Arduino Cloud after waking up, before you update the dashboard with new values

Hi @hzrnbgy

Yes, the ESP32 wakes up after deep sleep and does the temperature measurement correctly.
It also reconnects to my local network, so I thought it was connecting to the Arduino cloud also, but that obviously fails.
I have tried to add delays, thinking it had not had sufficient time, but without more success.
What can I do/test to further debug the problem?

Well, you could write code that instead of going to sleep, disconnects and reconnects to the WiFi things. That way you can simulate part of waking up and going to sleep by getting the connect and disconnect working.

You could try properly disconnecting before just shutting down.

You have these in setup()

Maybe, after waking up, you also need to execute the above. After all, your ESP32 has "resetted" after waking up

ESP32 DeepSleep is an almost reset of the ESP32. The preserved bits are any RTC RAM the programer has setup and the ULP processor code, if any. An ESP32 waking from deep sleep causes the setup() to be re-ran.