Prevent ESP8266 send data

How can I prevent ESP 8266 from transmitting data when the Blynk App in my phone is not connected to the Blynk server.
My project is to control a heater in the summer cottage on the countryside via a Mobilrouter with prepaid card.
It feels unnecessary to send data when I don’t need to read the temperature and control the heater.
I hope someone can help a beginner

You could use BLYNK_APP_CONNECTED or BLYNK_APP_DISCONNECTED, but I don’t think that will help you…

The problem is that is you stop the ESP talking to the Blynk server when it detects that the app is disconnected from the Blynk server then (because the ESP is no longer connected to the Blynk server) it will not know when to re-connect again.

Personally, I’d code-in an ‘away’ mode where the ESP only connects to the server on an infrequent basis - maybe once per day. If, when it connects, it detects that the app has told it to go back into ‘normal’ mode then it stays connected as normal.


Thanks Pete!
It sounds interesting!
How did you do it?
Do you have an example of the code?
Is it possible to get esp8266 to stop / start sending data with a button in Blynappen?
I’m sorry if my English is not correct.
English is not my first language.
It is Swedish
/ Peter

Okay, let me try to explain more…
When your device is connected to the Blynk server it is constantly exchanging data with the server. This happens every time the command is executed, which could be hundreds of times per second. It has to be at least every 10 seconds, otherwise the server will flag your device as being offline.

When your device isn’t talking to the server then it doesn’t know about any changes to widgets in the app. It’s therefore impossible to instruct a device to connect to the server using the app, because the device needs to be connected to receive that instruction. What we call in English a “Chicken and Egg” problem.

What I’m proposing is that you use the Blynk.disconnect command to stop the device to server communication. You may also need to force your GPRS modem to close it’s connection, I don’t know.
You could then use the RTC to force a re-connection every so often at a certain time - let’s say every day at 4am. Or, you could use a timer to force a re-connection every 24 hours, but this will be at a random time if you don’t use the RTC.

When the re-connection occurs, the device could read the value of a virtual pin, which is connected to a switch widget in your app. Let’s say that this is a simple switch where off (0) represents offline mode and on (1) represents online mode.
When the device sees that the value of this switch is still 0 then it terminated the connection again and waits another 24 hours in disconnected mode.
When the device connects and sees that the switch is set to 1 then I’d stays connected, and operates in connected mode.

You can change the value of the switch widget in the app at any time, you don’t have to wait-up at 4am to change the switch value, the device will get the latest value from the server, which might have been updated 23 hours ago.
The process of forcing the device to get this latest value is done with the Blynk.syncVirtual(Vpin) command.

So, that’s the principal.
No, I don’t have any example code, but it shouldn’t be too difficult for you to write - with a little experimentation.


Thanks Pete!
Then I understand a little more :slight_smile:
Then it’s time for some expression!
/ Peter