BLYNK 2.0 OTA with ESP32 and Ethernet module W5500

Hi, i usually build my projects using ESP32 DevKit v1.0 and W5500 ethernet module, not WiFi.

I’d like to know if there’s a roadmap to support Blynk AIR OTA updates through ethernet (cable) not only by WiFi.

Thanks,
Regards
Alex

It is supported as a Business plan feature.

I didn’t think connection method made a difference. I’ve tested Blynk.Air with the LILYGO ESP32 Ethernet board and it worked fine…

Pete.

OK, i have Maker plan (10 devices). In this plan it won’t work ok?

I tried this setup, using the same Blynk library I was already using (BlynkSimpleEthernet.h 1.1.0 and Ethernet.h 2.0.0). When I configure Blynk Air (OTA) and send the firmware file, on the ESP32, it reports the error: httpcode != HTTP_CODE_OK and does not update.

I just tried doing OTA shipments to these Lilygo Ethernet devices from both my Pro and Free Blynk accounts and both worked perfectly. This is a screenshot from my Free account…

I can only assume that your issue is to do with the different hardware and libraries you are using compared to the Lilygo Ethernet devices that I’m using.

Pete.

Some informations about this project:

ESP32 DOIT DEV KIT v1 4MB module
Wiznet W5500 ethernet board connected through SPI interface (SCK GPIO18, MOSI GPIO23, MISO GPIO19, CS GPIO5)
SDCARD module connected to SPI interface (SCK GPIO18, MOSI GPIO23, MISO GPIO19, CS GPIO15)
CANBUS module (GPIO12,13)
RTC DS3231 module (I2C GPIO 21,22)
PZEM004T module (Serial1 hardware GPIO4,2)

All modules and sketch (>3k lines, huge to put here) works perfectly with Blynk 2.0, and with features like sdcard logging and send log to external ftp server every day.

I tried use Arduino OTA library from Juraj Andrassy and works perfectly using this W5500 module but needs to specify IP address of ESP32.

I need an OTA upgrade to use remotely (internet), without specify IP Address of ESP32, especially since my devices are behind routers with NAT and direct external access via public IP is not possible.

Libraries:

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <FS.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
#include <HardwareSerial.h>
#include <EEPROM.h>
#include <ESP32CAN.h>
#include <CAN_config.h>
#include <PZEM004Tv30.h>
#include <NTPClient.h>
#include <BlynkSimpleEthernet.h>
#include <BluetoothSerial.h>
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include <Update.h>   
#include <HTTPClient.h>

In the other topic that you’ve been posting in, I suggested that you come back here and…

You’ve provided some info on your hardware, but I still have no idea which Ethernet board you are actually using.

Also, you should be testing this with a bare minimum sketch, and providing info on exactly which libraries and library versions you are using.
All of this is to allow others to replicate your setup and see if they can get this setup working.

Pete.

Okay, I had a look in my “bits and pieces box” and came across one of these W5500 Ethernet boards

My first attempts at getting this to work with Blynk.Air were unsuccessful, and I realised it was because the ESP32 HTTPClinet library only has support for WiFi connections, and the Ethernet library only had support for LAN8720 and TLK110 chips and not W5500.

A bit of research revealed that the ETH library that ships with the ESP32 core version 3.x has support for the W5500 chip, and I’ve been able to get that working with Blynk.Air.

Here’s how…

  1. Upgrade to the ESP32 Core version 3.x. The only version available at the moment is 3.0.0-aplha3 and to install that you need to change the URL in your IDE preferences file to this:
    https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json
    then install the 3.0.0-aplha3 in board manager.

  2. A couple more connections are needed to het the board working. The connections I used are:

    GPIO5  to  SCS (Chip Select)
    GPIO16 to  INT (Interrupt - might be labelled IRQ)
    GPIO17 to  RST (Reset)
    GPIO18 to  SCLK (SPI Clock)
    GPIO19 to  MISO
    GPIO23 to  MOSI
    GND    to  GND
    3v3    to  3.3v
  1. add your credential to this sketch and upload…
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab

#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_TEMPLATE_NAME "REDACTED"
#define BLYNK_AUTH_TOKEN "REDACTED"

#define BLYNK_FIRMWARE_VERSION        "1.0.1" // For Blynk.Air OTA, Increment with each update

#define BLYNK_PRINT Serial

#include <ETH.h>

// You can use either the SSL or non-SSL library. Stick with SSL unless you have a good reason to change...
//#include <BlynkSimpleEsp32.h>
#include <BlynkSimpleEsp32_SSL.h>

#include <Update.h>   // For Blynk.Air OTA
#include <HTTPClient.h> // For Blynk.Air OTA

// Set this to 1 to enable dual Ethernet support
#define USE_TWO_ETH_PORTS 0

// // Example SPI using ESP-IDF's driver
 #define ETH_PHY_TYPE        ETH_PHY_W5500
 #define ETH_PHY_ADDR         1
 #define ETH_PHY_CS           5
 #define ETH_PHY_IRQ         16 
 #define ETH_PHY_RST         17
 #define ETH_PHY_SPI_HOST    SPI2_HOST
 #define ETH_PHY_SPI_SCK     18
 #define ETH_PHY_SPI_MISO    19
 #define ETH_PHY_SPI_MOSI    23

static bool eth_connected = false;

BlynkTimer timer;

void WiFiEvent(WiFiEvent_t event) // Callback that is triggered when an Ethernet event occurs
{
  switch (event)
  {
  case ARDUINO_EVENT_ETH_START:
      Serial.println("ETH Started");
      // set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
  case ARDUINO_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
  case ARDUINO_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");
      Serial.print(ETH.localIP());
      if (ETH.fullDuplex())
      {
        Serial.print(", FULL_DUPLEX");
      }
      Serial.print(", ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      eth_connected = true;
      break;
  case ARDUINO_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
  case ARDUINO_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
  default:
      break;
  }
}

void setup()
{
  Serial.begin(115200);

  Serial.print("BLYNK_FIRMWARE_VERSION = ");
  Serial.println(BLYNK_FIRMWARE_VERSION);

  WiFi.onEvent(WiFiEvent); // Defines the callback (above) to be called when an Ethernet event occurs

  // Initialise the Ethernet interface...
  pinMode(ETH_PHY_RST, OUTPUT);
  digitalWrite(ETH_PHY_RST, 0);
  delay(200);
  digitalWrite(ETH_PHY_RST, 1);
  delay(200);
  digitalWrite(ETH_PHY_RST, 0);
  delay(200);
  digitalWrite(ETH_PHY_RST, 1);

  // If you want to define a static IP address for your Ethernet device you can do it here using ETH.config()
  // The parameters are: (Device static IP address, Gateway, Subnet mask, DNS server IP)
  // Comment-out the ETH.config command if you want these to be parameters to be assigned by DHCP
  //ETH.config(IPAddress(192, 168, 1, 90), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 1, 1));

  
  ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, ETH_PHY_SPI_HOST, ETH_PHY_SPI_SCK, ETH_PHY_SPI_MISO, ETH_PHY_SPI_MOSI);
  
  delay(5000);
  
  Blynk.config(BLYNK_AUTH_TOKEN);
  Blynk.connect();

  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  if (eth_connected)
  {
      Blynk.run();
  }
  timer.run();
}


void myTimerEvent()
{
  Blynk.virtualWrite(V1, millis() / 1000); // Send uptime in seconds to Blynk datastream V1
}


BLYNK_WRITE(InternalPinOTA) // For Blynk.Air OTA
{
  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();
}


void reboot() // For Blynk.Air OTA
{
  ESP.restart();
  for (;;) {} // Wait here until the restart has begun
}
  1. The sketch writes the current uptime to pin V1, so to utilise this you’ll need to add a V1 datastream preferably of type String, and add a value widget if you want to see this data, but that’s obviously optional.

Blynk.Ait OTA updates now work fine with this setup.

Note that there are some other significant changes in the ESP32 3.x core, including the deprecation of the analogWrite() command, which will break the existing Blynk Edgent examples. More info here…

Pete.

I suspect that another solution may be to use some of the code in this sketch…

where an HTTP GET request is made without the use of an HTTPClient library.

Pete.

1 Like