BlynkEthernet Manager for STM32 running Built-In Ethernet or LAN8720,W5x00/ENC28J60

How To Install Using Library Manager

New Releases v1.0.1

  1. Fix hanging bug in STM32 boards with built-in Ethernet LAN8742A.

New Releases v1.0.0

  1. Add support to STM32 boards with built-in Ethernet LAN8742A, ENC28J60 or W5x00 Ethernet shields
  • This is the new library, adding to the current Blynk_WiFiManager. It’s designed to help you eliminate hardcoding your Blynk credentials in STM32 boards using with Ethernet (Built-in LAN8742A, W5100, W5200, W5500, ENC28J60, etc). It’s currently not supporting SSL and can not saved config dada to non-volatile memory (EEPROM, battery-saved SRAM, SPIFFS, etc.). Will fix in next releases.
  • You can update Blynk Credentials any time you need to change via Configure Portal. Data to be saved in configurable locations in EEPROM.

This library currently supports

  1. STM32 boards with built-in Ethernet LAN8742A such as :
  1. STM32 boards (with 64+K Flash) running ENC28J60 shields
  2. STM32 boards (with 64+K Flash) running W5x00 shields

Sample Code

#if defined(ESP8266) || defined(ESP32)
#error This code is designed to run on STM32 platform, not ESP8266 nor ESP32! Please check your Tools->Board setting.
#endif

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

#if defined(ARDUINO_ARCH_STM32F1)
  #define DEVICE_NAME  "STM32F1"
  #define BLYNK_NO_YIELD
#elif defined(ARDUINO_ARCH_STM32F3)
  #define DEVICE_NAME  "STM32F3"
  #define BLYNK_NO_YIELD
#elif defined(ARDUINO_ARCH_STM32F4)
  #define DEVICE_NAME  "STM32F4"
  #define BLYNK_NO_YIELD
#elif defined(ARDUINO_ARCH_STM32F7)
  #define DEVICE_NAME  "STM32F7"  
  #define BLYNK_NO_YIELD
#else
  #define DEVICE_NAME  "STM32 Unknown"  
  #define BLYNK_NO_YIELD
#endif
        

#define USE_BUILTIN_ETHERNET    false
//  If don't use USE_BUILTIN_ETHERNET, and USE_UIP_ETHERNET => use W5x00 with Ethernet library
#define USE_UIP_ETHERNET        false 

#if (USE_BUILTIN_ETHERNET)
  #define ETHERNET_NAME     "Built-in STM32 Ethernet"
#elif (USE_UIP_ETHERNET)
  #define ETHERNET_NAME     "ENC28J60 Ethernet Shield"
#else
  #define ETHERNET_NAME     "W5x00 Ethernet Shield"
#endif

// Start location in EEPROM to store config data. Default 0.
// Config data Size currently is 128 bytes w/o chksum, 132 with chksum)
#define EEPROM_START     0

#define USE_SSL     false

#define USE_CHECKSUM      true

#if USE_SSL
  // Need ArduinoECCX08 and ArduinoBearSSL libraries
  // Currently, error not enough memory for many STM32 boards. Don't use
  #error SSL not support
#else
  #if USE_BUILTIN_ETHERNET
    #include <BlynkSTM32BIEthernet_WM.h>
  #elif USE_UIP_ETHERNET
    #include <BlynkSTM32UIPEthernet_WM.h>
  #else
    #include <BlynkSTM32Ethernet_WM.h>
  #endif 
#endif

#define USE_BLYNK_WM      true

#if !USE_BLYNK_WM
  #define USE_LOCAL_SERVER      true

  #if USE_LOCAL_SERVER
    char auth[] = "******";
    char server[] = "account.duckdns.org";
    //char server[] = "192.168.2.112";
  #else
    char auth[] = "******";
    char server[] = "blynk-cloud.com";
  #endif
  
  #define BLYNK_HARDWARE_PORT       8080
#endif

#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
  #define W5100_CS  10
  #define SDCARD_CS 4
#endif

void setup()
{
  // Debug console
  Serial.begin(115200);
  Serial.println("\nStart W5100_Blynk on STM32 running " + String(ETHERNET_NAME) + " " + String(DEVICE_NAME));

#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
#endif

#if USE_BLYNK_WM
  Blynk.begin();
#else
  #if USE_LOCAL_SERVER
    Blynk.begin(auth, server, BLYNK_HARDWARE_PORT);
  #else
    Blynk.begin(auth);
    // You can also specify server:
    //Blynk.begin(auth, server, BLYNK_HARDWARE_PORT);
  #endif
#endif

  if (Blynk.connected())
  {
    #if USE_BLYNK_WM
    Serial.print(F("Conn2Blynk: server = "));
    Serial.print(Blynk.getServerName());
    Serial.print(F(", port = "));
    Serial.println(Blynk.getHWPort());
    Serial.print(F("Token = "));
    Serial.println(Blynk.getToken());  
    #endif
    Serial.print(F("IP = "));
    Serial.println(Ethernet.localIP());
  }
}

void heartBeatPrint(void)
{
  static int num = 1;

  if (Blynk.connected())
    Serial.print(F("B"));
  else
    Serial.print(F("F"));
  
  if (num == 80) 
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0) 
  {
    Serial.print(F(" "));
  }
} 

void check_status()
{
  static unsigned long checkstatus_timeout = 0;

#define STATUS_CHECK_INTERVAL     60000L

  // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
  if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
  {
    heartBeatPrint();
    checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
  }
}

void loop()
{
  Blynk.run();
  check_status();
}

The following is the sample terminal output when running example BI_Ethernet_Blynk on Nucleo-144 F767ZI with built-in Ethernet PHY.

Start BI_Ethernet_Blynk on STM32 running Built-in STM32 Ethernet STM32 Unknown
[1] EEPROM, sz:16384
[3] CCksum=0x0,RCksum=0x0
[6] InitEEPROM
[6621] GetIP:
[6621] IP:192.168.2.94
[6621] bg: No cfgdat. Stay
[6621] CfgIP=192.168.2.94
F[10938] SaveEEPROM,sz=16384,chkSum=0x19b4
[10938] Hdr=W5100,Auth=****
[10941] Svr=account.duckdns.org,Port=8080
[10945] SIP=nothing,BName=STM32-F767ZI-WM
[10949] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Arduino

[10962] BlynkArduinoClient.connect: Connecting to account.duckdns.org:8080
[10984] Ready (ping: 6ms).
[11051] run: got E&B
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB
BBBBBBBBBB BBBBBBBBBB BBBB

This is the link to Blynk

Blynk IoT Platform

Blynk was designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, visualize it and do many other cool things.

You can install and use Local Blynk Server (RPi Zero W, 3B+, 4, Laptop, PC, etc) to have full control.
The Server source code is in Public Domain and written in Java. You can download, compile and use to be sure having full control.

Use Local Blynk Server

Blynk Server

Blynk Server Source Code

New in Version v1.0.2

  1. Fix crashing bug when using dynamic EthernetServer
  2. Enhance examples, fix indentation, update README.md

New in Version v1.0.3

  1. Reduce html and code size for faster Config Portal response. Enhance GUI.
  2. Change default macAddress for boards to avoid macAddress conflict while simultaneously testing multiple boards.

So, how it works? If no valid config data are stored in EEPROM, it will switch to Configuration Mode. Connect to access point at the IP address displayed on Terminal or Router's DHCP server as in the following picture:

|500x203

After you connected to, for example, 192.168.2.86, the Browser will display the following picture:

|357x500

Enter your credentials (Blynk Server and Port). If you prefer static IP, input it (for example 192.168.2.79) in the corresponding field. Otherwise, just leave it blank or nothing to use auto IP assigned by DHCP server.

|350x500

Then click Save. After the board auto-restarted, you will see if it's connected to your Blynk server successfully as in the following picture:

|500x242

Major Releases v1.1.0

  1. Fix Config Portal Bug.
  2. Add functions to control Config Portal from software or Virtual Switches. Check How to trigger a Config Portal from code #25
  3. Use more efficient FlashStorage_STM32 Library to save data to emulaled-EEPROM.
  4. Add support to new EthernetENC library for ENC28J60.

Releases v1.0.4

  1. New powerful-yet-simple-to-use feature to enable adding dynamic custom parameters from sketch and input using the same Config Portal. Config Portal will be auto-adjusted to match the number of dynamic parameters.
  2. Dynamic custom parameters to be saved automatically in EEPROM
  3. Permit to input special chars such as % and # into data fields.
  4. MultiBlynk Servers and Tokens with Auto(Re)Connect feature.

Releases v1.2.0

  1. Add support to LAN8720 Ethernet for many STM32F4 (F407xx, NUCLEO_F429ZI) and STM32F7 (DISCO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG) boards.
  2. Add LAN8720 examples
  3. Add Packages’ Patches for STM32 to use LAN8720 with STM32Ethernet and LwIP libraries

Releases v1.1.1

  1. To permit autoreset after configurable timeout if DRD/MRD or non-persistent forced-CP.

Sample Debug Terminal Output

Start LAN8720_Ethernet_Blynk on BLACK_F407VE using LAN8720 Ethernet & STM32Ethernet Library
BlynkEthernet_STM32_WM v1.2.0

EEPROM size = 16384, start = 0
Flag read = 0xd0d04321
No doubleResetDetected
SetFlag write = 0xd0d01234
[3054] CCSum=0x2a72,RCSum=0x2a72
[3054] ChkCrR:CrCCsum=0x15d7,CrRCsum=0x15d7
[3058] CrCCsum=0x15d7,CrRCsum=0x15d7
[3061] ======= Start Stored Config Data =======
[3066] Hdr=LAN8742A,BName=BLACK_F407VE
[3070] Svr=account.duckdns.org,Tok=token1
[3076] Svr1=account.ddns.net,Tok1=token2
[3082] Prt=8080,SIP=192.168.2.167
[3086] connectEthernet: Use static_IP=192.168.2.167
[3091] MAC: FE-C6-B0-96-A9-DF
[5715] IP:192.168.2.167
[5715] bg:ECon.TryB
[5715] Try connecting to BlynkServer=account.duckdns.org,Token=token1
[5722] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on STM32 BLACK_F407VE

[5813] Ready (ping: 7ms).
[5880] Connected to BlynkServer=account.duckdns.org,Token=token1
[5882] bg:EBCon
Conn2Blynk: server = account.duckdns.org, port = 8080
Token = token1
IP = 192.168.2.167
B
Your stored Credentials :
MQTT Server = mqtt_server
Port = 1883
MQTT UserName = mqtt-User
MQTT PWD = mqtt_pass
Subs Topics = Subs_Topics
Pubs Topics = Pubs_Topics
Stop doubleResetDetecting
ClearFlag write = 0xd0d04321
BBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB