Blynk.Air OTA minimal code

After I updated ESP8266 board to 3.0.2 (still use Arduino 1.8.8), the error has changed to this command line.

17:27:15.884 -> overTheAirURL = http://sgp1.blynk.cloud/static/fw_15028989384836929779_-838595071.bin?token=9vUHQAe-qkEJTtyZ2M0RfAqqirmaUt0I
17:27:16.024 -> httpCode = 200
17:27:16.024 -> contentLength = 303360
17:27:16.024 -> canBegin = 1
17:27:16.024 -> written = 0
TEST SWITCH update details
Download Failure 5:27:15 PM Today
Firmware Shipment Process Started 5:27:14 PM Today
Request sent 5:27:14 PM Today
New Firmware Requested 5:27:14 PM Today
Firmware Shipment Process Started 5:26:33 PM Today

Hi Peter. Thank you for your help.
Hi everybody.

I think I solved it, using another update code.

Arduino 1.8.19. ESP8266 board 3.0.2. BlynkSimpleEsp8266.h.

I was able to update via BlynkAir, even with the option of Lower Firmware version or No condition.

And here is the code I used, and the details of the results.

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN "X8q5lh0pfypriO7b5zAFNEiJoi1_S6zb"

#define BLYNK_FIRMWARE_VERSION "9.4.0"

#define BLYNK_PRINT Serial



//ESP32
//#include <Update.h>
//#include <HTTPClient.h>

//ESP8266
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266Ping.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <ESP8266HTTPUpdateServer.h>
#include <WiFiClient.h>

//________________________________________________________________
String overTheAirURL = "";

#define WIFI_SSID "HIEU VAI  THANH"                      //Enter Wifi Name
#define WIFI_PASS "passathai96"                    //Enter wifi Password


boolean setBlynk = 0;

void setup() {
  Serial.begin(115200);
  Serial.print("BLYNK_FIRMWARE_VERSION = ");
  Serial.println(BLYNK_FIRMWARE_VERSION);
  checkConnection();
  checkInternet();
  pinMode(D4,OUTPUT);
}

boolean checkConnection() {
  Serial.print("Check connecting to ");
  Serial.println(WIFI_SSID);
  WiFi.disconnect();
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(WIFI_SSID,WIFI_PASS);

  int count=0;
  while(count < 20){
    if(WiFi.status() == WL_CONNECTED){
      Serial.print("Connected to ");
      Serial.println(WIFI_SSID);
      Serial.print("Web Server IP Address: ");
      Serial.println(WiFi.localIP());
      Serial.println("");
      return true;
    }
    delay(5000);
    Serial.print(".");
    count++;
  }
  Serial.println("Timed out........ hiddenAP = 0;");
  Serial.println("");
  return false;
}


void checkInternet(){
  Serial.println("");
  bool ret = Ping.ping("www.google.com");
  if(ret){
    if(setBlynk == 0){
            Serial.println("ket noi NEW BLYNK NEW");
            Blynk.config(BLYNK_AUTH_TOKEN);
      setBlynk = 1;
    }
      if(!Blynk.connected()){
        Serial.println("Not connected to Blynk server");
        Blynk.connect(); // try to connect to server with default timeout
      }else{
        Serial.println("Connected to Blynk server");
      }
  Serial.println("");
}
}

void loop(){
  Blynk.run();
    if(!Blynk.connected()){
      int count=0;
      while(count < 3){//5 lan chay 6s Blynk.run la 30s
        Blynk.run();//thoi gian chay 6s
        if(Blynk.connected()){
          Serial.println("!Blynk.connected(); Blynk.connected())");Serial.println("");
          delay(500);
          return;
        }
        delay(1000);
        Serial.print(".");
        count++;
      }
      Serial.println("!Blynk.connected(); internetState = 0;");Serial.println("");
      delay(500);
   }
}



BLYNK_CONNECTED() {
  // Request the latest state from the server
  Blynk.syncVirtual(V4);
}

BLYNK_WRITE(V4) {
  int stateD4 = param.asInt();
  digitalWrite(D4, stateD4);
}

BLYNK_WRITE(InternalPinOTA) {
 Serial.println("OTA Started"); 
  overTheAirURL = param.asString();
 Serial.print("overTheAirURL = ");  
 Serial.println(overTheAirURL);  

 //HTTPClient http;
 //http.begin(overTheAirURL);

 
  WiFiClient my_wifi_client;
  HTTPClient http;
  http.begin(my_wifi_client, overTheAirURL);


t_httpUpdate_return ret = ESPhttpUpdate.update(my_wifi_client, overTheAirURL);
switch(ret) {
    case HTTP_UPDATE_FAILED:
        Serial.println("[update] Update failed.");
        break;
    case HTTP_UPDATE_NO_UPDATES:
        Serial.println("[update] Update no Update.");
        break;
    case HTTP_UPDATE_OK:
        Serial.println("[update] Update ok."); // may not be called since we reboot the ESP
        break;
}
}
21:38:25.739 -> .Connected to HIEU VAI  THANH
21:38:25.739 -> Web Server IP Address: 192.168.1.21
21:38:25.739 -> 
21:38:25.739 -> 
21:38:30.801 -> ket noi NEW BLYNK NEW
21:38:30.801 -> [10165] 
21:38:30.801 ->     ___  __          __
21:38:30.801 ->    / _ )/ /_ _____  / /__
21:38:30.847 ->   / _  / / // / _ \/  '_/
21:38:30.847 ->  /____/_/\_, /_//_/_/\_\
21:38:30.847 ->         /___/ v1.1.0 on ESP8266
21:38:30.847 -> 
21:38:30.847 ->  #StandWithUkraine    https://bit.ly/swua
21:38:30.847 -> 
21:38:30.847 -> 
21:38:30.847 -> Not connected to Blynk server
21:38:30.847 -> [10175] Connecting to blynk.cloud:80
21:38:31.081 -> [10403] Ready (ping: 63ms).
21:38:31.174 -> 
21:39:44.176 -> OTA Started
21:39:44.176 -> overTheAirURL = http://sgp1.blynk.cloud/static/fw_8861998046749586401_-838595071.bin?token=EWvl4L6F4FuusgoQ79c0J8YD_zBXIKl0
21:39:56.983 -> 
21:39:56.983 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
21:39:56.983 -> 
21:39:56.983 -> load 0x4010f000, len 3460, room 16 
21:39:56.983 -> tail 4
21:39:56.983 -> chksum 0xcc
21:39:56.983 -> load 0x3fff20b8, len 40, room 4 
21:39:56.983 -> tail 4
21:39:56.983 -> chksum 0xc9
21:39:56.983 -> csum 0xc9
21:39:56.983 -> v0004ced0
21:39:56.983 -> @cp:B0
21:40:02.268 -> ld
21:40:02.348 -> Check connecting to HIEU VAI  THANH
21:40:07.359 -> .Connected to HIEU VAI  THANH
21:40:07.359 -> Web Server IP Address: 192.168.1.21
21:40:07.359 -> 
21:40:07.359 -> 
21:40:11.559 -> ket noi NEW BLYNK NEW
21:40:11.559 -> [14574] 
21:40:11.559 ->     ___  __          __
21:40:11.559 ->    / _ )/ /_ _____  / /__
21:40:11.559 ->   / _  / / // / _ \/  '_/
21:40:11.559 ->  /____/_/\_, /_//_/_/\_\
21:40:11.559 ->         /___/ v1.1.0 on ESP8266
21:40:11.559 -> 
21:40:11.559 ->  #StandWithUkraine    https://bit.ly/swua
21:40:11.559 -> 
21:40:11.559 -> 
21:40:11.559 -> Not connected to Blynk server
21:40:11.598 -> [14585] Connecting to blynk.cloud:80
21:40:11.729 -> [14717] Ready (ping: 36ms).
21:40:11.846 -> 
21:45:19.424 -> OTA Started
21:45:19.424 -> overTheAirURL = http://sgp1.blynk.cloud/static/fw_14483877767671016810_-838595071.bin?token=4gCroqeGQShaN-HW3uwnraMoguXYDh_O
21:45:34.288 -> 
21:45:34.288 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
21:45:34.288 -> 
21:45:34.288 -> load 0x4010f000, len 3460, room 16 
21:45:34.288 -> tail 4
21:45:34.288 -> chksum 0xcc
21:45:34.288 -> load 0x3fff20b8, len 40, room 4 
21:45:34.288 -> tail 4
21:45:34.288 -> chksum 0xc9
21:45:34.288 -> csum 0xc9
21:45:34.288 -> v0004ced0
21:45:34.288 -> @cp:B0
21:45:39.588 -> ld
21:45:39.638 -> Check connecting to HIEU VAI  THANH
21:45:44.668 -> .Connected to HIEU VAI  THANH
21:45:44.668 -> Web Server IP Address: 192.168.1.21
21:45:44.668 -> 
21:45:44.668 -> 
21:45:48.818 -> ket noi NEW BLYNK NEW
21:45:48.818 -> [14541] 
21:45:48.818 ->     ___  __          __
21:45:48.818 ->    / _ )/ /_ _____  / /__
21:45:48.818 ->   / _  / / // / _ \/  '_/
21:45:48.818 ->  /____/_/\_, /_//_/_/\_\
21:45:48.818 ->         /___/ v1.1.0 on ESP8266
21:45:48.818 -> 
21:45:48.818 ->  #StandWithUkraine    https://bit.ly/swua
21:45:48.858 -> 
21:45:48.858 -> 
21:45:48.858 -> Not connected to Blynk server
21:45:48.858 -> [14552] Connecting to blynk.cloud:80
21:45:48.973 -> [14707] Ready (ping: 38ms).
21:45:49.128 -> 
21:49:32.571 -> OTA Started
21:49:32.571 -> overTheAirURL = http://sgp1.blynk.cloud/static/fw_5800073477836424206_-838595071.bin?token=-J3KrC3e9FTBYDhIhGNUq3wxmTKfOi6Q
21:49:46.868 -> 
21:49:46.868 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
21:49:46.868 -> 
21:49:46.868 -> load 0x4010f000, len 3460, room 16 
21:49:46.908 -> tail 4
21:49:46.908 -> chksum 0xcc
21:49:46.908 -> load 0x3fff20b8, len 40, room 4 
21:49:46.908 -> tail 4
21:49:46.908 -> chksum 0xc9
21:49:46.908 -> csum 0xc9
21:49:46.908 -> v0004ccc0
21:49:46.908 -> @cp:B0
21:49:52.208 -> ld
21:49:52.248 -> BLYNK_FIRMWARE_VERSION = 9.4.1
21:49:52.248 -> Check connecting to HIEU VAI  THANH
21:49:57.248 -> .Connected to HIEU VAI  THANH
21:49:57.248 -> Web Server IP Address: 192.168.1.21
21:49:57.288 -> 
21:49:57.288 -> 
21:50:02.398 -> ket noi NEW BLYNK NEW
21:50:02.398 -> [15505] 
21:50:02.398 ->     ___  __          __
21:50:02.398 ->    / _ )/ /_ _____  / /__
21:50:02.398 ->   / _  / / // / _ \/  '_/
21:50:02.398 ->  /____/_/\_, /_//_/_/\_\
21:50:02.398 ->         /___/ v1.1.0 on ESP8266
21:50:02.398 -> 
21:50:02.398 ->  #StandWithUkraine    https://bit.ly/swua
21:50:02.398 -> 
21:50:02.398 -> 
21:50:02.398 -> Not connected to Blynk server
21:50:02.438 -> [15515] Connecting to blynk.cloud:80
21:50:02.638 -> [15731] Ready (ping: 39ms).
21:50:02.770 -> 

And the error “Firmware type mismatch”, because i used the same code for the next shipping. We must edit just a little before creating the bin file.

1 Like

I have solved the error “Firmware type mismatch”, by typing once the Space key in the space at this line of code.

#define BLYNK_FIRMWARE_VERSION      "22.09.11"

I don’t know the reason for this error, but with such a simple operation, I solved the above error.

@nlqt2022
I am seeing this error “Compilation error: ESP8266Ping.h: No such file or directory”
Can you please guide how to solve

Do you have the ESP8266Ping library installed ?

I would take the code from post #1 of this topic, not one where someone is attempting to add the OTA code into the rest of their sketch.

The ping library isn’t needed for the OTA to work.

Pete.

Thanks so much; that sketch was very helpful and minimised too much work.

@Ibrahim_Roshdy
Thank you for sharing these steps to update the ESP32 OTA without needing EDGE. I tried it, and it worked very well. There is only one problem the device is not shown on the APP, I can find it in developing mode, so I can’t read or write from a mobile or tablet. Would you please advise?
Thanks.

@Hayderismal this sounds unrelated to this minimal OTA topic.
Rather than cluttering this topic up with unrelated issues I’d suggest that you start a new topic.

Pete.

Thanks, @PeteKnight, for your swift reply. It is related to the topic. I used the sketch on the first post by @Ibrahim_Roshdy to upgrade the Firework OTA without using Edgent.h. it worked very well, except the device disappeared from the list on the mobile app and only shown in developer mode. I then removed the mini sketch and reuploaded my code; I could see the device. By the way, I can read my data on the web dashboard, but not on the mobile dashboard.

I’d still suggest that you start a new topic and post all of the relevant info including your sketch, screenshots, Blynk.Air logs, details of all the steps etc etc.

Pete.

Hi Pete,

I’m trying to use this example (with ESP32 and includes for it), but I couldn’t make it work.
The result of the serial is the following:

overTheAirURL = http://ny3.blynk.cloud/static/fw_6815324747163453176_-838595071.bin?token=2utwGZ8DHBSKbtGjGZGjYYZqnl-dP8CT
[79242] Disconnected
httpCode = 200
contentLength = 913728
canBegin = 1
E (104223) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (104223) task_wdt:  - loopTask (CPU 1)
E (104223) task_wdt: Tasks currently running:
E (104223) task_wdt: CPU 0: IDLE
E (104223) task_wdt: CPU 1: loopTask
E (104223) task_wdt: Aborting.
abort() was called at PC 0x400e5af5 on core 0


Backtrace:0x40083701:0x3ffbea8c |<-CORRUPTED


ELF file SHA256: 0000000000000000
Rebooting...

Can you give me an idea where I might be going wrong?

Which example are you referring to?

What hardware and ESP32 core are you using?
What device type have you used in the IDE?

Also, when you post serial data or code to the forum please don’t use Blockquotes, use triple backticks at the beginning and end instead.

Pete.

Which example are you referring to? Your example with ESP8266, but configured to ESP32.

What hardware and ESP32 core are you using? DEVKIT 1.0 with ESP32

What device type have you used in the IDE? DOIT ESP32 DEVKIT V1

I found my mystake: I was enable WDT for 20s (part of enother code).
This time was not enough for the update and it restarted ESP32.

Now it’s working great.
Sorry for this fail.

12 posts were split to a new topic: Problems getting Blynk.Air minimal code to work

Hi, I’m using the ESP32 DOIT DEV KITV1 and the Wiznet Ethernet W5500 module. Using the libraries below:

#include <EthernetUdp.h>
#include <BlynkSimpleEthernet.h>
#include <Update.h>
#include <HTTPClient.h>

Blynk works very well without any problems. Once the firmware is provisioned on Blynk.Air, the process starts, but always returns http.code=-1;
 If you copy the URL received by ESP32 in the browser, the file is downloaded correctly. What could be happening?

Code used, extracted, is:

void reboot() 
{
  ESP.restart();
}

BLYNK_WRITE(InternalPinOTA) 
{
  String overTheAirURL = param.asString();
  HTTPClient http;
  http.begin(overTheAirURL);
  int httpCode = http.GET();
  if (httpCode != HTTP_CODE_OK) {return;}
  int contentLength = http.getSize();
  if (contentLength <= 0) {return;}
  bool canBegin = Update.begin(contentLength);
  if (!canBegin) {return;}
  Client& client = http.getStream();
  int written = Update.writeStream(client);
  if (written != contentLength) {return;}
  if (!Update.end()) {return;}
  if (!Update.isFinished()) {return;}
reboot();
}

@ALEXFISHERMAN please edit your last two posts and add triple backticks at the beginning and end of your code snippets so that they display correctly.

Triple backticks look like this:
```

Pete.

You’ve fixed the code formatting in one of your posts, but not the other.

You have a similar topic about the same subject, and it’s always best to keep the discussion in one place.
To avoid cluttering-up this extremely useful and informative topic with detailed info about your hardware configuration, I’d suggest you go back to posting in your original topic and provide full info on the hardware that you’re using (including links to the Ethernet board you’re using and details of how this is wired-up to your ESP32), a fully working sketch, details of which version of the ESP32 core you have installed and details of which libraries and library versions you are using.

That way others may be able to replicate your setup and suggest solutions.

Pete.

I’ve posted a solution to the W5500 + ESP32 OTA issue here…

Pete.