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

Working libraries, libraries being ported and related hardware
Post Reply
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

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

Post by khoih-prog »

https://github.com/khoih-prog/BlynkEthernet_STM32_WM

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 :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- All STM32 Boards with Built-in Ethernet, See How To Use Built-in Ethernet

2. STM32 boards (with 64+K Flash) running ENC28J60 shields
3. STM32 boards (with 64+K Flash) running W5x00 shields

Sample Code

Code: Select all

#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.

Code: Select all

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.

Image
Last edited by khoih-prog on Thu Apr 22, 2021 5:34 am, edited 2 times in total.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by stevestrong »

No laptop required, but a blynk server. Does the server run on the STM board?
User avatar
Juraj
Posts: 47
Joined: Fri Jan 03, 2020 7:47 pm
Answers: 1
Location: Slovakia
Contact:

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by Juraj »

stevestrong wrote: Mon Mar 02, 2020 9:21 am No laptop required, but a blynk server. Does the server run on the STM board?
Blynk server is in cloud. Who knows on what does it run there
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by khoih-prog »

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
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by stevestrong »

What speaks against using direct connection between app and client?
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by khoih-prog »

To make the devices become IoT, so that you can control, check them from anywhere in the world.
You sure can write an APP to control one of your devices directly, but it's not that easy for everybody to write an APP to control multiple devices from the Internet, without a server sitting in the middle.
It's also not worth our time just to write an APP ourselves instead of standing on other people's shoulders?

Certainly, the decision is all personal.
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by khoih-prog »

New in Version v1.0.2

1. Fix crashing bug when using dynamic EthernetServer
2. Enhance examples, fix indentation, update README.md
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by khoih-prog »

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:

Image

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

Image

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.

Image

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:

Image
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: BlynkEthernet Manager for STM32 running Built-In Ethernet or W5x00/ENC28J60 shields

Post by khoih-prog »

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.
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

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

Post by khoih-prog »

Tested OK with new STM32 core v2.0.0

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

Code: Select all

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
Post Reply

Return to “Libraries & Hardware”