BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

OTA and Blynk on different Wifi networks not working

#1

I would like to use my phone with blynk and my home wifi for Over The Air updates, but the OTA part does not work.
Blynk connects without issues.
Arduino IDE does not connect and does not display the IP address.
If I leave out the Blynk parts, OTA works fine.
Is it possible to achieve this and if so, what is wrong with my code?


#define BLYNK_PRINT Serial

#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
    
char ssid[] = "MyPhoneHOTspot";
char pass[] = "XXXXX";
char ssidOTA[] = "MyHOMEwifi";
char passOTA[] = "XXXXXXX";

// Blynk
char auth[]   = "09be2b05000c462f81f0cc85d2a4d3e7";

void setup()
{
  // Debug console
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssidOTA, passOTA);
  ArduinoOTA.begin();
  // You can also specify server:
  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
}

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

0 Likes

#2

If they are on different networks you can’t use OTA. You can use the http updater as long as the device you want to update is accessible via the internet.

0 Likes

#3

The blynk app on my phone controls the esp01 with a ledstrip. Which I need to be able to do anywhere I can get 4g.
And when I am home I would like to be able to do over the air updates.

I would have to look into updating via the internet.

0 Likes

#4

It doesn’t make any difference which network your phone is on, it doesn’t play any part in the OTA process.
The NodeMCU being updated, and the computer running the Arduino IDE need to be on the same network.

However, you seem to be tryin* to get your NodeMCU to connect to two separate networks, with different SSIDs at the same time, which it can’t do.

Pete.

0 Likes

#5

I know it does not play any part in the OTA process.
What I did not know is that it cant connect to multiple networks at once, thanks for that :wink:

0 Likes

#6

I solved my issue with a button.

#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
    
char ssid[] = "Hannes";
char pass[] = "19811981";
char ssidOTA[] = "Ziggo7D69ADC";
char passOTA[] = "cpkessj8jbeK";

// Blynk
char auth[]   = "09be2b05000c462f81f0cc85d2a4d3e7";

#define buttonPin 0
boolean OTA = 1;

void setup()
{
  delay(2000);
  // Debug console
  pinMode(buttonPin, INPUT_PULLUP);
  int buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    OTA = 0;
  }
  delay(3000);
  if (OTA == 0)
  {
    // Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
    Blynk.begin(auth, ssid, pass);
  } else if (OTA == 1)
  {
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssidOTA, passOTA);
    ArduinoOTA.begin();
  }
}

void loop()
{
  if (OTA == 0)
  {
    Blynk.run();
  }  else if (OTA == 1)
  {
    ArduinoOTA.handle();
  }
}
1 Like

#7

@Hannes_Sapiens: for what I have monitored from my experiments recently. As long as in the loop() function you put the ArduinoOTA.handle(); after Blynk.run() then everything is ok. Can you try it? No need you revise the code as well as a physical button additionally. From my finding I did then all my boards are living well now.

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();
}
0 Likes