ESP8266 Iot shall execute web controled command after returning from deep sleep

my ESP8266 goes sucessfully into deepsleep mode.
It returns successfully from deepsleep mode.
It can then successfully stream a sensor value to a bucket.

Now I would like in addition that after returning from deepsleep mode, my ESP8266 executes or not a programmed command, depending on a toggle button of the dashboard.
Is this possible?

Hy @thingerfan!

I’m afraid that this is not possible, because the toggle button sends an http request when it’s clicked, not when the device executes the handle routine.

Hello jtrinc26, thanks for your answer.
I do not want an action of the device when I click on the website.
I know, most of the time my device is sleeping, so this is just not possible. But I know also that at a certain time it will wake up.
Then my device restarts from scratch (it’s a reset).
Then my device initiates some thinger objects and here is the problem: currently it sets those objects to their default value…that’s may be acceptable for objects that are not existing in the thinger.io-cloud. But for objects that are already existing in the thinger.io-cloud, my device shall be able NOT to set them to a default value, but instead to read their existing value in the cloud.
Is this so complicated to be done?

Hi @thingerfan it should be possible in the near future. It is planned a config feature, so the devices can store and retrieve configuration from the cloud, i.e., to be retrieved after a deep sleep. I think it is possible to map a device config to control widget, so let me add this feature to the TODO.

Okok @thingerfan, I understand… you want that, when the device wakes up, it read the values from the dashboard instead of its own values. But, like alvarolb has explained it´s not possible yet.

ok, thank you both for considering my issue.
In the meantime, I have found a solution for doing what I want through a stupid workaround: when the device wakes up it calls itself through an endpoint.
This endpoint needs a Device Access Token. If Device Access Token is right, then the thing can call itself and execute some command. If not, nothing is executed.
So for me as operator, I need to change the Device Access Token in order to execute or not the command.
That’s not optimal user interface and also the time for doing all those actions is long for the device so this is not optimal for battery consumption, but at least it works and this is a proof that at least the device is able to read “something” from the cloud even if it is done through “dirty” solution.

Hi thingerfan,
Could you please share your code showing how you manage to stream to a bucket before the esp goes into deepsleep.
I am trying to achieve this also.

I am basing my sketch on code that previously successfully streamed to a bucket, but when I add deepsleep the streaming to a bucket fails.

I assume that my issue is that the deepsleep kicks in before the streaming can complete. I’ve tried adding some delays, but this hasn’t helped.

My code in the Loop is below.
“TempHum” is a routine that collects the temperature and humidity from the DHT11.
The two streaming variables have been defined in the Setup.

Any advice appreciated…

void loop() {
  thing.handle();
//  timerPeriod(); // FOR NON DEEPSLEEP VERSION TO CALL "TempHum"
  TempHum();  // get temp and hum  //DS VERSION
  delay(2000);
  thing.stream(thing["Temp_push"]); //DS VERSION
  thing.stream(thing["Humid_push"]);  //DS VERSION
  delay(5000);                        //DS VERSION
  ESP.deepSleep(SLEEP_MS*1000, WAKE_RF_DEFAULT);  //DS VERSION
}
1 Like

Hi @shean,

this solution will not work correctly, as for the stream method, the device should be connected to the platform, and “something” listening at the other side for this stream (a bucket, a dashboard, etc). So, the server should be subscribed to this stream, and the device notified, which will take some loops to be completed (so, adding delays will not work). For this specific use case, we have another function (released this week and still not documented, but you can take a look at our device that uses this function http://docs.thinger.io/hardware/climaStick/). The new function, write_bucket, allows just writing to the bucket you specify. So, in order to use this new function, change in the console your bucket source to “From Write Call”

Then, your code now can be like this:


void setup(){
     thing["TempHum"] >> outputValue(pson& out){
         out["temperature"] = dht.readTemperature();
         out["humidity"] = dht.readHumidity();
     };
}

void loop() {
  thing.handle();
  thing.write_bucket("bucketId", "TempHum");
  ESP.deepSleep(SLEEP_MS*1000, WAKE_RF_DEFAULT); 
}

Notice that I have created just a single resource for both temp & humidity values, so you get one record in the bucket for both values.

Bests! Hope this help!

1 Like

Thank you Alvaro - this works now. :smiley:
And your example of how to set up a single resource for multiple streaming variables has helped me understand this better.

I did have to modify your suggested code to make it work as follows:

 thing["TempHum"] >> [](pson& out){ 
         out["temperature"] = dht.readTemperature();
         out["humidity"] = dht.readHumidity();
     };