Run a code after every time try to connect to server by hardware

Hi Blynkers
I have a simple code for control a led(with a button on/off) that the code placed in loop of Arduino sketch so when my hardware don’t be connected to server it’s not possible run my code because sketch try to connecting to server but my code is a manual control of the led(just on/off) and i want to do it even when the hardware don’t connected to server.
in general i want do a code even when hardware don’t be connected to the server.
Where is Best place for my code?
is it tru? --> it’s better that i add my code to BlynkSimpleEsp8266.h file.

put it in a Blynk timer.

Also change this entry in loop():;


if(Blynk.connected()){  // not to be confused with BLYNK_CONNECTED();

Normally you would have a timer checking at intervals, say every minute, to see if you are connected to the Blynk server and if you are not reconnect.

You don’t give many details but it looks like you are using an ESP.

Consider Blynk.config() in setup() as it bypasses the blocking routine of Blynk.begin().

1 Like

In the past few topics, it has seemed that you use direct pin control and not vpin… so are your referring to writing actual code this time? How are you controlling the LED - Widget button or Physical button? or other timer methods?

Reason asking is that WITHOUT a connection to the server, neither direct pin control from the App, or any timer function will work… however with the methods @Costas referred to, you can make a sketch that will allow a physical button to control LED even without connection to the the Blynk Server.

Not sure where you read this… “add your code” is referring to editing your sketch… not editing a library, that is a bit more advanced.

1 Like

Sorry for my bad English i try to learn more it however thank you so much.
You are the Best.