Way to recognize that a dashboard is displayed

Hi have we got a way to recognize on the device program that a dashboard is currently displayed?

I would like to optimize the data transmission and only feed some data at full speed whenever it is actually used.

How to sense on the device e.g. that a polled value is retrieved?

That requirement seems to make sense, isn’t it?

Hi @rin67630,

If you define resources on the device you can configure in the dashboard the update interval. This resource is only sent when a dashboard is active, so, if the dashboard is closed, the device stops itself the transmission. If this resource is actually used for storing in a bucket or something similar, you can define another resource only used in the dashboard.

Hope it helps!

Hi Alvaro,
thanks for the fast reply.
That is not what I meant.
I know that a polling resource will update only when the dashboard is active.

I would however love to be able to detect that update process running or not on the device, to prevent preparing the data on the device just for nothing if nobody looks at it, possibly dramatically slow down the device to save energy.
I know that would limit the reactivity for the first time, but running on batteries requires compromises.

The buckets are proactively fed, which is normal and should be also when nobody looks at them.

Hmmmm… What comes to my mind is to have a flag set to 0 after 5 seconds more than the update frequency of the dashboard, when this flag comes to 0 you slow down your device, and you reset the flag’s timer in the “thing” that the dashboard access.

But slowing down will not save too much battery, the fact to have the wifi on demands a lot of current compared with the clock speed of the uC, and there is no way you can predict with the wifi off when a device is required by a random access to a dashboard.

If you want to save battery what you can do is to communicate with another way that doesn’t demands a lot of energy as wifi does (for examply by zigbee), and make a gateway with wifi and unlimited power source that have no this limitation, to talk zigbee with the battery powered device and wifi to the platform.

Hope this helps.

But what will refresh the flag, only when the dashboard is active?

Slowing down the ESP8266 with delays() activates the light sleep, reducing the power by 90%. Every WiFi call wakes it up for 2 seconds. That is the reason for trying to run a WiFi transaction every minute to check if someone is active, then continue at full speed until the dashboard is left by the user.
Of course, the first call would be laggy, but the power advantage, especially on devices running solar powered is tremendous.

Of course, you are right with using power efficient radios like LoRa and involving a gateway, but that would be a next step in complexity…

You need to define a “thing” that is exclusively consulted by the dashboard, in that “thing” you can set a line of code that sets the flag, and in the loop to compare the last time that flag was set and if the amount of time is greater than a certain tolerance, enter into low power mode.

When the dashboard is not open, the code into the “thing” will not run and the flag will not be set.

Let me know if I did not explained myself.

Hope this helps.

I’m afraid that does not speak much to me.
Could you please return with a code example?
Do you mean a binary variable in my code?
How can this binary variable be automatically and periodically updated by the dashboard without a manual action?

In fact, I would like to sense if thinger polls my variables or not.
But that happens in the thinger code without any user interaction.

Oh sorry my bad, not a binary flag, a variable that stores for example millis value and you may know in principal loop when was last time it was consulted.

  thing["DashboardExclusive"] >> [](pson & out) {
    out["variable1"] = var1;
    out["Variable2"] = var2;
    lastAccess = millis();

And in loop something like this:

if(millis()-lastAccess > dashboardFrequencyUpdatet){
//do something and/or set a flag to enter low power mode
//do something to get out low power mode

Hope this helps.

Yes, that is the breakthrough…
Did I understand it right, that the code that is placed within the curly braces of a setup "Thing… >> [](Pson…
is executed whenever the variables are fetched by the host?
So I could place additional instructions there?
If that is the case, it could be worth to document that.
It is a bit unusual for regular users to see some code placed in setup to be executed cyclically.

Yes you may add code there, and it will be executed when the “thing” is called, and it is documented too, check this:


Hope this helps.

Just to be sure:
the code placed like that:
thing[“temperature”] >> [](pson& out){
out = dht.readTemperature();
//[my code placed here]
will also run whenever a widget reads “temperature”?

i.e. periodically at the refresh rate of the widget, despite the fact that the code is placed under void setup()?

Yes the thing is defined at the setup, but it runs always a dashboard makes a request, because it updates the variables, so every update executes the code into the “thing”

You can try by yourself by putting a "Serial.println("whatever"); into the “thing” and watch the serial console :wink:

Hope this helps.

1 Like