To overcome this, the delay() needs to be replaced with a non-blocking solution. If there is no handshake from the device for some time (the default is 10 seconds) the Blynk server will regard the device as “Missing In Action” and will show it as disconnected and close the communication channel with the device. This only happens when n() is executed and adding the delay in the code prevents this happening. While this isn’t a problem in some cases, it is a problem when working with Blynk.įor Blynk to work effectively, the device needs to perform a handshake with the Blynk server as often as possible, preferably hundreds of times per second, so that it is aware of any user input in the app. The problem with this approach is that the delay() command is “blocking” – it blocks all code execution until the delay period has completed. Take_sensor_reading() // call the function which reads the sensorĭelay(5000) // do nothing for 5000ms (5 seconds)īn() // perform a handshake with the Blynk server There are a number of ways to do this, and the ‘lazy’ way is to do this: void loop() Let’s say that we have a project where we want to take readings from a sensor every 5 seconds. It’s rather long, as it attempts to explain the reasoning behind why and how we use timers, and covers some more advanced subjects, but I’ve tried to organise it in a way that helps people to find answers to specific questions… Why use a timer at all? Many users seem to struggle with the basic concepts of using BlynkTimer in their projects, despite the excellent discussions and tutorials that exist on this forum, so I thought I’d write a guide that will hopefully help clarify things.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |