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

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

BlynkEthernet Manager for STM32 running Built-In Ethernet or 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 Tue Mar 03, 2020 6:33 am, edited 1 time in total.

stevestrong
Posts: 354
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 7
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: 28
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: 54
Joined: Thu Feb 27, 2020 7:54 am

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: 354
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 7
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: 54
Joined: Thu Feb 27, 2020 7:54 am

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: 54
Joined: Thu Feb 27, 2020 7:54 am

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: 54
Joined: Thu Feb 27, 2020 7:54 am

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

Post Reply

Return to “Libraries & Hardware”