BlynkEthernet Manager for STM32 with Built-in LAN8742A Ethernet, LAN8720, W5X00 or ENC28J60 shields

New Releases v1.0.0

  1. Add support to STM32 boards with built-in Ethernet, 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, 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.). To be fixed in future 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 such as :
  1. STM32 boards (with 64+K Flash) running ENC28J60 shields
  2. STM32 boards (with 64+K Flash) running W5x00 shields

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:

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

Enter your credentials (Blynk Server and Port). If you prefer static IP, input it (for example 192.168.2.113 ) in the corresponding field. Otherwise, just leave it blank or nothing .

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:

Sample Code

#if defined(ESP8266) || defined(ESP32)
#error This code is designed to run on Arduino AVR, SAM, SAMD, Teensy 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

Updated: Mar 2nd 2020

BlynkEthernet_STM32_WM for STM32 libraries v1.0.0 just got included into Arduino Library Manager.
Now you can install this library directly from Arduino Library Manager
arduino-library-badge

Updated: Mar 3rd 2020

Releases v1.0.1

New in this version

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

Updated: Mar 6th 2020

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.
1 Like

Updated April 20th 2020

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 EEPROMe.
  3. Permit to input special chars such as % and # into data fields.
  4. MultiBlynk Servers and Tokens with Auto(Re)Connect feature.

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 terminal output:

Start BI_Ethernet_Blynk on STM32F7 board, running Built-in LAN8742A Ethernet
[1] EEPROMsz16384
[3] CCSum=0x0,RCSum=0x0
[5] CrCCsum=0,CrRCsum=0
[7] InitEEPROM,sz=16384,Datasz=380
[10] CrCCSum=3120
[12] MAC: FE-C9-A1-8E-D4-B7
[5629] Dynamic IP OK, connected
[6629] IP:192.168.2.88
[6629] bg:NoDat.Stay
F
Your stored Credentials :
MQTT Server = blank
Port = blank
MQTT UserName = blank
MQTT PWD = blank
Subs Topics = blank
Pubs Topics = blank

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

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.

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

Start BI_Ethernet_Blynk on STM32F7 board, running Built-in LAN8742A Ethernet
[1] EEPROMsz16384
[3] CCSum=0x0,RCSum=0x0
[5] CrCCsum=0,CrRCsum=0
[7] InitEEPROM,sz=16384,Datasz=380
[10] CrCCSum=3120
[12] MAC: FE-C9-A1-8E-D4-B7
[5629] Dynamic IP OK, connected
[6629] IP:192.168.2.88
[6629] bg:NoDat.Stay
Your stored Credentials :
MQTT Server = blank
Port = blank
MQTT UserName = blank
MQTT PWD = blank
Subs Topics = blank
Pubs Topics = blank
FFFFFFFFFF FFFFFFFFFF
Save,CSum=0x2c22
[68929] Hdr=LAN8742A,BName=STM32F767ZIT6-Blynk-WM
[68930] Svr=account.duckdns.org,Tok=tokentoken1a1nKgun10heJSu2G6KQUlJRGIOrVD0QX
[68942] Prt=8080,SIP=192.168.2.88
[68945] CrCCSum=8662
[68947] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Arduino

[68961] BlynkArduinoClient.connect: Connecting to account.duckdns.org:8080
[68982] Ready (ping: 7ms).
[69049] Connected to Blynk Server = account.duckdns.org, Token = token
[69052] r:E&B OK
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB

How to add dynamic parameters from sketch

  • To add custom parameters, just modify from the example below
#define USE_DYNAMIC_PARAMETERS     true

/////////////// Start dynamic Credentials ///////////////

//Defined in <BlynkEthernet_STM32_WM.h>
/**************************************
  #define MAX_ID_LEN                5
  #define MAX_DISPLAY_NAME_LEN      16

  typedef struct
  {
  char id             [MAX_ID_LEN + 1];
  char displayName    [MAX_DISPLAY_NAME_LEN + 1];
  char *pdata;
  uint8_t maxlen;
  } MenuItem;
**************************************/

#if USE_DYNAMIC_PARAMETERS

#define MAX_MQTT_SERVER_LEN      34
char MQTT_Server  [MAX_MQTT_SERVER_LEN + 1]   = "";

#define MAX_MQTT_PORT_LEN        6
char MQTT_Port   [MAX_MQTT_PORT_LEN + 1]  = "";

#define MAX_MQTT_USERNAME_LEN      34
char MQTT_UserName  [MAX_MQTT_USERNAME_LEN + 1]   = "";

#define MAX_MQTT_PW_LEN        34
char MQTT_PW   [MAX_MQTT_PW_LEN + 1]  = "";

#define MAX_MQTT_SUBS_TOPIC_LEN      34
char MQTT_SubsTopic  [MAX_MQTT_SUBS_TOPIC_LEN + 1]   = "";

#define MAX_MQTT_PUB_TOPIC_LEN       34
char MQTT_PubTopic   [MAX_MQTT_PUB_TOPIC_LEN + 1]  = "";

MenuItem myMenuItems [] =
{
  { "mqtt", "MQTT Server",      MQTT_Server,      MAX_MQTT_SERVER_LEN },
  { "mqpt", "Port",             MQTT_Port,        MAX_MQTT_PORT_LEN   },
  { "user", "MQTT UserName",    MQTT_UserName,    MAX_MQTT_USERNAME_LEN },
  { "mqpw", "MQTT PWD",         MQTT_PW,          MAX_MQTT_PW_LEN },
  { "subs", "Subs Topics",      MQTT_SubsTopic,   MAX_MQTT_SUBS_TOPIC_LEN },
  { "pubs", "Pubs Topics",      MQTT_PubTopic,    MAX_MQTT_PUB_TOPIC_LEN },
};

uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem);  //MenuItemSize;

#else

MenuItem myMenuItems [] = {};

uint16_t NUM_MENU_ITEMS = 0;
#endif


/////// // End dynamic Credentials ///////////

  • If you don’t need to add dynamic parameters, use the following in sketch
#define USE_DYNAMIC_PARAMETERS     false
1 Like

Updated April 22nd 2021

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.

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.

Debug Terminal Output

The following is the sample terminal output when running example LAN8720_Ethernet_Blynk on STM32F4 BLACK_F407VE with LAN8720 Ethernet using STM32Ethernet Library.

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