Blynk Library 0.6.1 appears to interfere with ArduinoOTA & thus stop WiFi connection (at least on Sonoff Basic)

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 :thinking:

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;
  }
}

Dear @Gunner the ESP Core 2.5.0 seems quite buggy… If you can, throw it away and install the stagging, the Master Branch from GitHub. If you need further assistance don’t hesitate to ask me to help.

Best Regards,
Mike Kranidis

Perhaps… everything is a bit buggy it seems :stuck_out_tongue: But strange that it worked just fine until going from Blynk 0.6.0 to 0.6.1

Not sure your reference here… but I updated to 2_5_0_Beta3 with no improvements.

I might try dropping back to the previous Blynk Library and test again… however, I am also inclined to forgo a Blynk based sketch and start learning the MQTT/Node Red route for IoT control… after all it is just a simple button for ON/OFF (well, and a timer for one of them, but that also failed recently :thinking: )… we will see.

Well, 0.6.0 worked all so briefly on the first boot, then stopped connecting within a minute. Now refuses to connect after rebooting… as is the new normal :stuck_out_tongue: I have made too many changes to track what is causing what now.

EDIT - OK, a few “did you shut it off and on again” steps later :smiley: It is now back to working…ish with 0.6.0

The Ping is all over the map, and it is constantly reconnecting… but at least it is all working (Blynk and OTA - if you catch it on a connected state)

[19711] Connecting to 10.10.3.13:8080
[20006] Ready (ping: 243ms).
[33228] Connecting to 10.10.3.13:8080
[36010] Ready (ping: 2740ms).
[56708] Connecting to 10.10.3.13:8080
[56750] Ready (ping: 33ms).
[70195] Connecting to 10.10.3.13:8080
[71293] Ready (ping: 1089ms).
[83503] Connecting to 10.10.3.13:8080
[84530] Ready (ping: 1018ms).

The ping issue may be because I was powering the Sonoff via USB for the testing… but I needed to see the Serial Monitor. The connection/disconnection still happens (according to the App) even on AC power… but again, back to “normal?”

Now I have to tear apart my wall mounted Sonoff in order to “repair” the last screwed up Blynk Library update… argg…

I think the Beta 3 is actually an earlier version (i.e a beta of the final 2.5.0 release). Confused? I am!

Yay! at last, Sir Gunner is coming over to the dark side :partying_face:

Actually, I’m going (slightly) in the opposite direction.
I thought it would be handy to be able to have a Blynk serial monitor as an option for my MQTT devices that use OTA, so I’m playing with that as an option with my base code that I run on my devices.
It’s working okay, after a bit of faffing around with problems to do with the terminal widget output not matching the serial output, but increasing the serial RxBufferSize seems to have fixed that.

Whilst playing around with this setup, I’d been having some OTA issues, so had been using a serial connection to flash my test code (also handy to be able to compare the outputs), but it was on my list of things to look at. My problem was that I’d get an [ERROR]: No Answer message (twice). I was also having issues with the OTA ports not populating in the ports list of the IDE, which I was usually able to fix by launching Bonjour Browser and refreshing it a couple of times. Thanks to @Blynk_Coeur for putting me on to this utility.
Here’s a link if you don’t already use Bonjour Browser:

Because of these issues I thought it was probably a Python or Bonjor problem on my PC, so was planning on digging-out a laptop to try instead.

When I saw you post this morning I thought that maybe this was the answer to my problems, so here’s what I did:

1 Disable the Blynk part of my MQTT code (easy as I have a #include switch)
2 Upload the code via serial to my test device (a Wemos D1 Mini)
3 Ran Bonjour Browser until the test device appeared in my list of ports
4 Tried an OTA update - this still failed in the usual way - [ERROR]: No Answer
5 About to give-up and pull-out the laptop I decided top power-cycle the Wemos
6 Tried the OTA update again - this time it worked - Yay!

Okay, I thought, it’s that pesky Blynk 0.6.1 library - I knew there was a reason why I didn’t use this stuff. Just to prove it, I’ll re-enable my Blynk code and do another upload, then try another OTA update - which should fail.

The weird thing is, it didn’t fail. I can now do OTA updates to this device. I can now do OTA updates to this device with Blynk enabled.

The odd thing is that I have another device, which is a Sonoff S20, that I was using for my testing of this code before, That has to be updated via OTA, because I’m feeling too lazy to get a screwdriver and FTDI adapter, and I still can’t update this via OTA. It’s an earlier version of my code, but runs Blynk and OTA, plus my standard MQTT code.
(And yes, I have changed the compile settings from, the Sonoff to the Generic ESP8266 with the correct memory and flash mode).
I have a feeling that if I flash this with with a serial connection using the same steps as I did before that OTA will be available again, but I’m not in the mood for that tonight.

I’m not getting the Wi-Fi disconnections that you’re seeing, but I do have a a check in my void loop that calls the Wi-Fi re-connect routine if it’s not connected.

Food for thought?
I’ll update you when I try re-flashing the S20.

Pete.

Yep, me too… at first the betas looked to show as a “later” addition… but I think you are correct and I actually downgraded :stuck_out_tongue:

So I upgraded back to 2_5_0 and back to working more often than not :smiley: (still frequent disconnection/reconnections… but for a simple switch, that is OK for now)

@PeteKnight What really adds a twist to my issue, is that I only saw this “loss of WiFi connection” issue on the Sonoff basics… my Wemos D1 Mini is running fine with Blynk 0.6.1, ESP Core 2.5.0 and OTA.

Issue is something between Blynk 0.6.1, ArduinoOTA and Sonoff (Generic ESP8266)

1 Like

Dear @Gunner ,
I have not access to my laptop and I wrote this comment from my smartphone. I believe that you need to delete your 2.5.0 installation that was coming from board manager and then to install from git the master branch. 2.5.0 has significant problem and the underlined nonos-sdk pre-3 has more problems… after upgrade in the board menu, one new entry permits to select Espressif firmware. Try it.

1 Like

Okay, Mrs K was watching some crap on TV, so curiosity got the better of me…

I re-flashed the Sonoff S20 via the FTDI, with my latest code. I thought I’d try it first of all with Blynk enabled, and after doing a wired flash I can now do OTA updates without any problems.

When you flash your Sonoff, what settings are you using?
Here’s what I used for my S20…

image

Pete.

Same settings, but at the time with IDE 1.8.8

However, following the time tested scientificalish method of changing all the things at once :crazy_face:… I downgraded to Core 2_4_2, upgraded to IDE 1.8.9, installed the latest beta App for Android and reflashed both Sonoffs with Blynk 0.6.0.

Now the Sonoffs work stably again… dare I try Blynk 0.6.1 again :thinking:

I have the same situation as @Gunner … checked carefully nothing changes much … then I just swapped Blynk.run(); before ArduinoOTA.handle(): then everything is back as nothing happens. … no further investigation but should you try this.

This way is ok

void loop()
{
    Blynk.run();
    ArduinoOTA.handle();
}

This way is ok for first booting then if the power off the board rebooting then it is stuck there = your case facing?

void loop()
{
    ArduinoOTA.handle();
    Blynk.run();
}

As per my posted code above, this was already set that way (when not commented out :wink: ) … I learned this one (having all the OTA stuff last) long ago.

1 Like

OK, so far so good with ESP core 2_4_2 and Blynk 0.6.1…

No idea why Blynk 0.6.0 & 0.6.1 had the sensitivity in the first place with Core 2_5_0 and why only on my Sonoff Basics… but now that they are again working I shall refrain from updating them unnecessarily :stuck_out_tongue:

Marking this one “solved…ish”

I think you should go to 2.5.0 again and try re-flashing on of the Sonoffs. I think it will work.

BTW, my void loop looks like this…

void loop()
{
  // All we really do in void loop is to check that we're still connected to Wi-Fi and feed the libraries that are hungry ...
  
  if(WiFi.status() != WL_CONNECTED)
  {
    WiFi_Connect(); 
  }  
  
  ArduinoOTA.handle();
  timer.run();
  MQTTclient.loop();
  #ifdef UseBlynk
    Blynk.run();
  #endif
}

Pete.

1 Like