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

Updating OTA is amazing

I just got OTA updates working with my project and omg it is so great. It updates so much faster than using FTDI. I used this tutorial. https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/readme.md

I’m really excited about all this.

5 Likes

Game changer! Gonna try and get this working tonight

EDIT: Skip to here to see key steps to making it work: Updating OTA is amazing

1 Like

Just realised I have a test ESP8266 plugged in to my PC … so gonna remote in and give it a shot!

1 Like

Running in to issues with Python. I installed 3.5.x but later read that i should have installed 2.7… not that I did that… it will no longer update OTA… trying to reinstall Python and do a reboot to see if it sorts it.

Yeah. You have to make sure to click add python.exe to path as well or it won’t work. Also you have to put OTA handlers into your sketch if you want to continuously update ota.

Could you please explain this? I read it in the help file but dont fully understand.

Post edited to correct erroneous info.

yeah. So the ota handlers do a couple things. They broadcast that this is a device that can be updated ota and they process the whole thing. So the basic ota sketch in the examples have the handlers that you need to include.

This one is simple. It’s the library.

#include <ArduinoOTA.h>

This needs to be in the setup loop.

  ArduinoOTA.begin();

You also need to put something in the main loop. I know the loop should only have the blynk.run(); but it’s working for me. Maybe it could be on a timer instead.

In main loop.

ArduinoOTA.handle();

I think that’s it.

So I just include all that then put my own code in there too?
I ran the BasicOTA example and it worked… so I just need to add those lines to my own program then upload it via SERIAL first then OTA?

Yup. You could upload the basicota example then upload your sketch with the needed bits OTA if you want and you are off to the races. Maybe someone can chime in on the absolute bare minimum that is needed and also if having the ArduinoOTA.handle(); in the main loop is an issue and should be on a timer instead. Like I said it is working for me so I’m leaving it.

I have a feeling that the only important bit in the setup is the ArduinoOTA.begin(); The other bits I think are just giving you feedback. I left most of it in.

Im still having issues but not sure where the problem is.

I have uploaded this program:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <ArduinoOTA.h>
/****************************************************************************/
SimpleTimer timer_sendUptime;
SimpleTimer timer_sendSensors;
WidgetTerminal terminal(V1);
WidgetRTC rtc;
BLYNK_ATTACH_WIDGET(rtc, V6);
/****************************************************************************/
String extraZeroH;
String extraZeroM;
String extraZeroS;
/****************************************************************************/
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";
/****************************************************************************/
void sendUptime() {
  if (hour() < 10)    { extraZeroH = '0'; }
  if (minute() < 10)  { extraZeroM = '0'; }
  if (second() < 10)  { extraZeroS = '0'; }
  String currentTime = String(extraZeroH + hour()) + ':' + extraZeroM + minute() + ':' + extraZeroS + second();
  String currentDate = String(day()) + '-' + monthShortStr(month()) + '-' + year();
  Blynk.virtualWrite(V22, currentTime);
  long rssi = WiFi.RSSI();
  Blynk.virtualWrite(V21, rssi);
}
/****************************************************************************/
void sendSensors() {
  int moistureSensor = analogRead(A0);
  moistureSensor = map(moistureSensor,0,1024,0,100);
  Blynk.virtualWrite(V20, moistureSensor );
}
/****************************************************************************/
void setup() {
  pinMode(A0, INPUT);
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  WiFi.mode(WIFI_STA);
  Blynk.begin(auth, "xxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx", IPAddress(192, 168, 1, 2));
  while (Blynk.connect() == false) {
    // Wait until connected
  }

  // Hostname defaults to esp8266-[ChipID]
  ArduinoOTA.setHostname("Garduino-Sensor-M1");

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r\n", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();
  terminal.println(F("Blynk v" BLYNK_VERSION ": Sensor 1 started"));
  terminal.flush();
  rtc.begin();
  timer_sendUptime.setInterval(1000L, sendUptime);
  timer_sendSensors.setInterval(1000L, sendSensors);
}
/****************************************************************************/
void loop() {
  ArduinoOTA.handle();
  Blynk.run();
  timer_sendUptime.run();
  timer_sendSensors.run();
}
/****************************************************************************/

via COM/SERIAL connection… and the program runs fine… Serial outputs:

Connecting to PrettyFlyForAWiFi
[21714] Connected to WiFi
[21714] IP: 192.168.1.37
[21714] Blynk v0.3.8 on ESP-12
[21714] Connecting to 192.168.1.2
[21722] Ready (ping: 1ms).
[21783] Time sync: OK

So all looks good. Can see the Uptime and sensor data in Blynk app.

Then I simply switch the COM port to the Network COM port (192.168.1.37) and upload.
I can see in the SERIAL window the following:

Start
Progress: 0%
Progress: 0%
Progress: 1%
Progress: 1%
Progress: 2%
Progress: 2%
...(skip the middle part)
Progress: 99%
Progress: 100%
End

But then the ESP doesnt connect to Blynk and cannot see the data.

I don’t know. The only big difference is the serial speed. I’m using Serial.begin(115200); Could that have anything to do with it? Doesn’t seem likely.

It could also be an issue with storage. I think you need to have enough space to fit you sketch twice for OTA to work. What flavor or esp are you using? Some have more flash than others.

Trying the 115200 baud rate now.

Sketch uses 252,787 bytes (24%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 35,608 bytes (43%) of dynamic memory, leaving 46,312 bytes for local variables. Maximum is 81,920 bytes.

Plenty of memory storage? Im using the LoLin NodeMCU v3

That’s plenty. I’m using a adafruit Huzzah which has similar and my sketch is bigger.

Im using the HUZZAH board too.

I might trying to go a few steps back and remove Blynk from the code and do something really simple with the serial monitor… like just report a sensor over and over and see if I can get it to update OTA.

Yeah or blink an led or something.

1 Like

Hmm seems to just give me this error after uploading OTA:

End

 ets Jan  8 2013,rst cause:2, boot mode:(1,7)


 ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset


Keep it up!

Gonna try this tonight!

I have 5 esps around my house, i hate having to get to them physically! (Especially the subfloor ones)

1 Like

I’ve confirmed that the only thing that you need in the setup loop is the ArduinoOTA.begin(); All the rest is not needed. Shouldn’t mess anything up though.