Hi all,
Just starting out with Blynk and loving it so far, except for this issue I’ve encountered.
I’m using an ESP8266 (Sonoff TH16 to be exact).
I tried to use virtualWrite() in my sketch to sync hardware button and app button, but am receiving a “cmd error” (and then a reconnect).
While debugging, I tried to run some of Blynk’s examples, and found out that ButtonInterrupt has the exact same issue for me. So I’ll be using that instead of my sketch for simplicity. The only thing I needed to change was button pin to 0.
(Also, please note that other examples, such as ButtonPoll, worked perfectly for me!)
Code and log below.
Any thoughts or suggestions? What am I missing?
My only guess as to what’s happening is that virtualWrite() doesn’t work if called inside an interrupt (pin interrupt in the example and timer interrupt in my original sketch). Is it a known issue? Did anyone else have success with ButtonInterrupt on the ESP8266?
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
WidgetLED led1(V1);
void checkPin()
{
// Invert state, since button is "Active LOW"
if (digitalRead(0)) {
led1.off();
} else {
led1.on();
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Make pin 0 HIGH by default
pinMode(0, INPUT_PULLUP);
// Attach INT to our handler
attachInterrupt(digitalPinToInterrupt(0), checkPin, CHANGE);
}
void loop()
{
Blynk.run();
}
[31617] Connected to WiFi
[31618] IP: 192.168.1.140
[31618]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.4.6 on ESP8266
[31691] Free RAM: 45648
[31717] Connecting to blynk-cloud.com:8442
[32102] <[02|00|01|00] <AUTH TOKEN HERE>
[32422] >[00|00|01|00|C8]
[32422] Ready (ping: 1ms).
[32422] <[11|00|01|00]Hver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]ESP8266[00]build[00]Mar 23 2017 14:28:42[00]
[32794] >[00|00|01|00|C8]
[42794] <[06|00|02|00|00]
[43124] >[00|00|02|00|C8]
[53125] <[06|00|03|00|00]
[53468] >[00|00|03|00|C8]
[56497] <[14|00|04|00|08]vw[00]1[00]255
[61498] Cmd error
[61498] Cmd skipped:20
[61499] Connecting to blynk-cloud.com:8442
[61832] <[02|00|01|00] <AUTH TOKEN HERE>
[62151] >[00|00|01|00|C8]
[62151] Ready (ping: 1ms).
[62151] <[11|00|06|00]Hver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]ESP8266[00]build[00]Mar 23 2017 14:28:42[00]
[62579] >[14|00|01|00|02]