I am a very beginner and now trying to control LED using Blynk LoT in my Android smartphone and an ESP8600 connected to my mobile Wifi router. After struggling I somehow succeeded to turn the LED on, but the response is slow. The time lag seems to be random, and between 0–10sec, so I suspect it is an issue of the communication interval between Blynk and ESP8600. Please give me some solutions or suggestions. My code is as following:
@Shin-Ichiro_Nakayama please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
Here, what I want to make is:
The LED turns on for 0.5sec and the turns off only when the safety is unlocked and the trigger is pushed.
A button (A) with Switch control data stream, push mode is assigned to V0 virtual pin. This button is the trigger.
A button (B) with Switch value data stream, switch mode is assigned to V1 virtual pin. This button is the safety.
In addition, the massage “Signal Received!” comes also with lags, in a same pattern to the LED.
The two issues that I can see is that I can see are:
The BLYNK_WRITE(V0) (Trigger) function has no test to see if the incoming value (param.asInt()) is a 1 or a 0. This means that the routine will trigger on both a press and release if the button widget attached to pin V0
Which is related to the first issue - The timeout timer that you are using is non-blocking, which is good from a Blynk point of view, but could lead to issues if the trigger is actuated whilst the timer is executing.
One solution to this is to add a flag to the timer routine, which is set when the timer begins and cleared when the timer is completed. You could then check that this flag is not set (no timer currently executing) before re-triggering the next timer.
I’m not sure that these issues add-up to a 10 second lack of responsiveness though, even if the trigger button is pressed and released repeatedly in a short space of time.
When your device connects to the Blynk server, what sort of ping time is it showing?
And, is this consistent if you repeatedly reboot the device and monitor the ping results?
Ideally, you should be seeing pings of below 100ms. If I try this I get…
I’m embarrassed that I didn’t know the BLYNK_WRITE() function works also when the button is released. and,
Can this be solved by simply inserting delay() in the switch_off() function? I read that delay() is usually not recommended in this kind of coding, but in this case it seems to be suitable??? Anyway, I rewrite my code as follows:
And the last point… How can I check the ping speed?
It appears on the serial monitor every time I push the reset button of ESP8622. For now, I have observed it five times and the values were 101, 117, 102, 152, and 97ms. It is obviously larger than yours. Are there any solutions for this?
I have confirmed mine is connecting to SGP server. I don’t know if the server trouble has been fixed, but the delay still occurs.
Anyway, thank you very much for your great advise! That helped me so much!
I think you need to start from the simplest sketch possible, with a single VIRTUAL_WRITE method and single digitalWrite. So you can make sure the problem is in the network or in your code. When you narrow down this main question we can move in the next direction.
Thank you Dmitriy for your advice, and accordingly I have tested. As a result, it occurred again. Then I changed my mobile router to a stationary (means not a “mobile” one, sorry for my poor english) one and it reacted immediately. So, the problem seems to be the connection between ESP8622 and the router or the router and server.
Any reason that mobile router leads to the delay?