How to connect to Blynk with Wired Ethernet WT32-ETH01?

Hi,

I’m trying to port a ESP32-S3 code to WT32-ETH01 which is a wired ethernet device.

The problem is that Blynk.begin() seems to support only Wifi

Blynk.begin(auth, ssid, pass);

I wrote a WiFiEvent mapper like found in

It seems to get stock after this printed on the serial console :

[23023] Connecting to "myssid"

It worked once. But then doesn’t work anymore. As if it was only working 1 out of 50 times.

Also once I saw this:

[24877] Connecting to blynk.cloud:443
[31877] Secure connection failed
[31878] Connecting to blynk.cloud:443
[54887] Secure connection failed
[54887] Connecting to blynk.cloud:443

Please help or direct me to the proper documentation.

Thanks!

I don’t understand that statement. Is Blynk.setup() a typo by you?

Pete.

Yes it was a typo. I edited the original question to fix it. Thanks!

Show your full sketch, the default blynk example sketch for Ethernet boards shows that SSID and PW is not required if you include the correct libraries.

/*************************************************************
  This example shows how to use Arduino Ethernet shield (W5100)
  to connect your project to Blynk.

  NOTE: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
        DON'T use them in your sketch directly!

  WARNING: If you have an SD card, you may need to disable it
        by setting pin 4 to HIGH. Read more here:
        https://www.arduino.cc/en/Main/ArduinoEthernetShield

  This is a simple demo of sending and receiving some data.
  Be sure to check out other examples!
 *************************************************************/

/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID           "TMPL2s7k3GZJa"
#define BLYNK_TEMPLATE_NAME         "Quickstart Template"
#define BLYNK_AUTH_TOKEN            "k3ZAnuJkDWs4LX5HSW5ZfebZEpGPvC44"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

#define W5100_CS  10
#define SDCARD_CS 4

BlynkTimer timer;

// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
  // Set incoming value from pin V0 to a variable
  int value = param.asInt();

  // Update state
  Blynk.virtualWrite(V1, value);
}

// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
  // Change Web Link Button message to "Congratulations!"
  Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V3, "onImageUrl",  "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  Blynk.begin(BLYNK_AUTH_TOKEN);
  // You can also specify server:
  //Blynk.begin(BLYNK_AUTH_TOKEN, "blynk.cloud", 80);
  //Blynk.begin(BLYNK_AUTH_TOKEN, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

billd

1 Like

Thanks for the reply ! I will try it out right away.

For reference my buggy code was

#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID "Your Template ID" // replace this with template id
#define BLYNK_DEVICE_NAME "Your Device Name" // replace this with your device name
#define BLYNK_AUTH_TOKEN "---"

#include <ETH.h>

#include <BH1750.h>
#include <BMP085.h>

#include <Blynk.h>
//#include <BlynkSimpleEsp32.h>
//#include <BlynkSimpleEsp32_SSL.h>
//#include <Ethernet2.h>
#include <BlynkSimpleEthernetSSL.h>

#include "Arduino.h"
#include "DHT.h"
#include <Wire.h>

float temperature; // parameters
float humidity;
float pressure;
float mbar;
float uv;
float visible;
float ir;

#define BH1750_DEFAULT_I2CADDR 0x23// because ADD is left floating 
BH1750 myBH1750;

BMP085 myBarometer; // initialise pressure sensor
#define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters

char auth[] = BLYNK_AUTH_TOKEN; // replace this with your auth token
char ssid[] = ""; // replace this with your wifi name (SSID)
char pass[] = ""; // replace this with your wifi password

#define DHTPIN 5 // dht sensor is connected to D5
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE); // initialise dht sensor
BlynkTimer timer;

static bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event)
{
  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;
  }
}

int LED = 2;

void sendSensor() // function to read sensor values and send them to Blynk
{
  digitalWrite(LED, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);
  humidity = dht.readHumidity();
  temperature = dht.readTemperature();
  if (isnan(humidity) || isnan(temperature)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  Serial.println("dht temparature: "+String(temperature,2));

  pressure = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP()); // read pressure value in pascals
  mbar = pressure / 100; // convert millibar to pascals
  /*
  visible = SI1145.ReadVisible(); // visible radiation
  ir = SI1145.ReadIR(); // IR radiation
  uv = SI1145.ReadUV(); // UV index
  */
  /*
  unsigned int amb_als = 0;
  unsigned int amb_ir = 0;
  uv = amb_als = SI1145.getAlsVisData();
  ir = amb_ir = SI1145.getAlsIrData();
  uv = SI1145.getUvIndex();
  Serial.println("sending temp to Blynk uv index: "+String(uv));*/
  
  float lightLevel = myBH1750.readLightLevel();  //start measurment -> wait for result -> read result -> retrun result or 4294967295 if communication error is occurred
  visible = lightLevel;

  Serial.println("sending temp to Blynk temparature: "+String(temperature,2));
  Serial.println("sending temp to Blynk mbar: "+String(mbar,2));
  Serial.println("sending temp to Blynk uv: "+String(uv, 2));
  Serial.println("sending temp to Blynk ir: "+String(ir, 2));
  Serial.println("sending temp to Blynk visible: "+String(visible, 2));
  Blynk.virtualWrite(V0, temperature); // send all the values to their respective virtual pins
  Blynk.virtualWrite(V1, humidity);
  Blynk.virtualWrite(V2, mbar);
  Blynk.virtualWrite(V3, visible);
  Blynk.virtualWrite(V4, ir);
  Blynk.virtualWrite(V5, uv);
  digitalWrite(LED, LOW);   // turn the LED off
}

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

  pinMode(LED, OUTPUT);
  
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
  
  Serial.println("Going to Wire begin");
  Wire.begin(13,14);
  Serial.println("Going to BM init");
  myBarometer.init();
  Serial.println("dht init");
  dht.begin();
  Serial.println("Beginning Si1145!");

  /* BH1750 initialization */
  int retry = 0;
  while (myBH1750.begin() != true && retry < 5)
  {
    Serial.println(F("ROHM BH1750FVI is not present"));    //(F()) saves string to flash & keeps dynamic memory free
    delay(5000);
    retry++;
  }

  delay(1000);
  Blynk.begin(auth, ssid, pass);
  Serial.println("Blynk ready");
  timer.setInterval(15000L, sendSensor); // sendSensor function will run every 1000 milliseconds
}

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

@Bill_Donnelly I tried with the proper header files

#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

However it seems to crash at Blynk.begin(auth);
Here is the serial console output:

Wifi Event
ETH Started
Wifi Event
ETH Connected
Wifi Event
ETH MAC: B0:A7:32:07:0E:07, IPv4: 192.168.50.34, FULL_DUPLEX, 100Mbps
dht init
Going to Blynk begin
[2683] Getting IP...
8��BX݌�t(Uզոlƚ�mթ�

This is my full code

#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME "Weather Station WT32 ESP01"
#define BLYNK_AUTH_TOKEN ""

#include <ETH.h>

#include <BH1750.h>
#include <BMP085.h>

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

#include "Arduino.h"
#include "DHT.h"
#include <Wire.h>

float temperature; // parameters
float humidity;
float pressure;
float mbar;
float uv;
float visible;
float ir;

#define BH1750_DEFAULT_I2CADDR 0x23// because ADD is left floating 
BH1750 myBH1750;

BMP085 myBarometer; // initialise pressure sensor
#define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters

char auth[] = BLYNK_AUTH_TOKEN; // replace this with your auth token
char ssid[] = ""; // replace this with your wifi name (SSID)
char pass[] = ""; // replace this with your wifi password

#define DHTPIN 5 // dht sensor is connected to D5
#define DHTTYPE DHT11     // DHT 11

DHT dht(DHTPIN, DHTTYPE); // initialise dht sensor
BlynkTimer timer;

static bool eth_connected = false; 
void WiFiEvent(WiFiEvent_t event)
{
      Serial.println("Wifi Event");
  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;
  }
}

int LED = 2;

void sendSensor() // function to read sensor values and send them to Blynk
{
  digitalWrite(LED, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);
  humidity = dht.readHumidity();
  temperature = dht.readTemperature();
  if (isnan(humidity) || isnan(temperature)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  Serial.println("dht temparature: "+String(temperature,2));

  pressure = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP()); // read pressure value in pascals
  mbar = pressure / 100; // convert millibar to pascals
  
  float lightLevel = myBH1750.readLightLevel();  //start measurment -> wait for result -> read result -> retrun result or 4294967295 if communication error is occurred
  visible = lightLevel;

  Serial.println("sending temp to Blynk temparature: "+String(temperature,2));
  Serial.println("sending temp to Blynk mbar: "+String(mbar,2));
  Serial.println("sending temp to Blynk uv: "+String(uv, 2));
  Serial.println("sending temp to Blynk ir: "+String(ir, 2));
  Serial.println("sending temp to Blynk visible: "+String(visible, 2));
  Blynk.virtualWrite(V0, temperature); // send all the values to their respective virtual pins
  Blynk.virtualWrite(V1, humidity);
  Blynk.virtualWrite(V2, mbar);
  Blynk.virtualWrite(V3, visible);
  Blynk.virtualWrite(V4, ir);
  Blynk.virtualWrite(V5, uv);
  digitalWrite(LED, LOW);   // turn the LED off
}

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

  pinMode(LED, OUTPUT);
  
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
  
  Serial.println("dht init");
  dht.begin();

  delay(1000);

  Serial.println("Going to Blynk begin");
  Blynk.begin(auth);
  Serial.println("Blynk ready");

  timer.setInterval(15000L, sendSensor); // sendSensor function will run every 1000 milliseconds
}

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

First things I’d do is:

  1. Run a simple, blank sketch to see if it connects with no other code (the example I posted)
  2. Remove the if statement from the loop, this will be running 1000s/second and is not needed. loop should be clean
void loop() {
     Blynk.run();
     timer.run();
}

billd

What makes you think that these are the “proper” header files?

You’ve already linked to a working sketch for the same hardware that you say you are using, which uses the following header files…

#include <ETH.h>
#include <BlynkSimpleEsp32_SSL.h>

I really don’t understand why you aren’t starting-off with a simplified version of @Luke_Clavey’s working sketch for the WT32-ETH01. Something like this…

#define BLYNK_TEMPLATE_ID "*********ID*******"
#define BLYNK_TEMPLATE_NAME "********name*******"
#define BLYNK_AUTH_TOKEN "**********token code******"

#include <ETH.h>
#include <BlynkSimpleEsp32_SSL.h>

 
void WiFiEvent(WiFiEvent_t event)
{
  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);
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
  Blynk.config(BLYNK_AUTH_TOKEN);
  Blynk.connect();
}


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

Pete.

Thanks it worked !

I had missed

  Blynk.config(BLYNK_AUTH_TOKEN);
  Blynk.connect();

and was trying all sort of things (changing headers) to get Blynk.begin(auth, ssid, pass); to work without wifi ssid.

Thanks again for your time.

1 Like

If you now return to Luke’s sketch and copy the lines that have the “for Blynk.Air OTA” comment next to them you’ll be able to do OTA (or more correctly Over Ethernet) updates to your device(s) vroom Blynk.Air

Pete.