Blynk Library 0.6.1 appears to interfere with ArduinoOTA & thus breaks the WiFi connection (at least on Sonoff Basic)
I just finished killing a few hours on this one… I recently updated both my Sonoff projects with Library 0.6.1 (I had also updated to latest Local Server… but unsure how that could affect this), and suddenly neither Sonoff was online anymore… but still responding to my physical button code at least.
Despite the timing, I actually suspected something in the ESP Arduino Core files as Blynk worked just fine if I commented out the OTA commands (not a desired option with Sonoff)
But after much testing I was able to get full OTA functionality in my Sonoffs… if I commented out Blynk (including substituting BlynkTimer for SimpleTimer as needed when commenting out the Blynk library).
So I can have one or the other, but not both anymore
This is the modified code that now works (with commented out Blynk commands)… in case anyone else with a Sonoff Basic wishes to test with Library 0.6.1 and confirm or dispute my findings.
Library 0.6.1
Local Server 0.41.4 - Java 11
ESP Core 2.5.0
Android App (beta)
/*
Sonoff Basic
Generic ESP8266
1MB (No SPIFS) flash size
115200 BAUD
MUST USE DOUT for Flash Mode!!
sonoff header
1 - vcc 3v3
2 - rx
3 - tx
4 - gnd
5 - gpio 14 (Unused)
esp8266 connections
gpio 0 - button
gpio 12 - relay
gpio 13 - green led - active low
gpio 14 - pin 5 on header
*/
#include <SimpleTimer.h>
//#include <BlynkSimpleEsp8266.h> // for ESP8266
#include <ESP8266WiFi.h> // for ESP8266
#include <ESP8266mDNS.h> // For OTA w/ ESP8266
#include <WiFiUdp.h> // For OTA
#include <ArduinoOTA.h> // For OTA
SimpleTimer timer;
//BlynkTimer timer;
char auth[] = "xxxxxxxxxx"; // Sonoff I
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char server[] = "xxx.xxx.xxx.xxx";
int port = 8080;
int pinState = LOW;
int btnState = HIGH;
void setup() {
pinMode(0, INPUT); // Button
pinMode(12, OUTPUT); // Relay
pinMode(13, OUTPUT); // LED
for (int i = 0; i < 4; i++) {
digitalWrite(13, LOW); // Turn ON LED
delay(200);
digitalWrite(13, HIGH); // Turn OFF LED
delay(100);
}
timer.setInterval(250L, PhysButton); // Set Button Scan
WiFi.begin(ssid, pass);
//Blynk.config(auth, server, port);
//Blynk.connect();
ArduinoOTA.setHostname("Sonoff-I-Pigtail"); // For OTA - Use device identifying name
ArduinoOTA.begin(); // For OTA
}
void loop() {
//Blynk.run();
timer.run();
ArduinoOTA.handle(); // For OTA
}
/*
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0) { // Button Widget in switch mode
digitalWrite(12, param.asInt()); // Toggle relay
digitalWrite(13, !param.asInt()); // Toggle LED
}
*/
void PhysButton() {
if (digitalRead(0) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {
// Toggle LED state
pinState = !pinState;
digitalWrite(12, pinState);
digitalWrite(13, !pinState); // Toggle LED
// Update Button Widget
//Blynk.virtualWrite(V0, pinState);
}
btnState = LOW;
} else {
btnState = HIGH;
}
}