- Important Notes for Portenta_H7
- Why do we need this Ethernet_Manager_Portenta_H7 library
- Changelog
- Prerequisites
- Installation
- Packages' Patches
- Libraries' Patches
- How to use default Credentials and have them pre-loaded onto Config Portal
- How to use
- Important Notes for using Dynamic Parameters' ids
- Examples
- So, how it works?
- Example Ethernet_Portenta_H7
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
The LittleFS of the new Portenta_H7 board currently tested OK with only maximum 8 files. The files, from 9 and up, somehow strangely can't be written and / or read. This is possibly a bug in the ArduinoCore-mbed mbed_portenta core
. The same behaviour is observed from core v2.0.0 up to v3.4.1.
If LittleFS size is reduced to 1024KB, test is OK with only maximum 4 files.
Beware and keep checking for updates.
Why do we need this Ethernet_Manager_Portenta_H7 library
-
This is the new library, adding to the current WiFiManager sets of libraries. It's designed to help you eliminate
hardcoding
your Credentials in Portenta_H7 boards using Ethernet from Portenta Vision shields. It's currently not supporting SSL. Will support soon. -
You can update Credentials any time you need to change via Configure Portal. Data are saved in configurable locations in Portenta_H7 LittleFS.
-
DoubleDetectDetector feature to force Config Portal when double reset is detected within predetermined time, default 10s.
-
Configurable Config Portal Title to be either BoardName or default undistinguishable names.
-
Examples are redesigned to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device
The Portenta_H7 boards, are currently supported using ArduinoCore-mbed mbed_portenta core
.
New recent features:
- DoubleDetectDetector feature to force Config Portal when double reset is detected within predetermined time, default 10s.
- Configurable Config Portal Title to be either BoardName or default undistinguishable names.
- Examples are redesigned to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device
This Ethernet_Manager_Portenta_H7 library currently supports these following boards:
- Portenta_H7 boards, using
ArduinoCore-mbed mbed_portenta core
- Portenta_H7 using Ethernet from Portenta Vision shields
Arduino IDE 1.8.19+
for Arduino.ArduinoCore-mbed mbed_portenta core 3.4.1+
for Arduino Portenta_H7 boards, such as Portenta_H7 Rev2 ABX00042, etc..Functional-Vlpp library v1.0.2+
to use server's lambda function. To install. checkEthernetWebServer library v2.3.0+
. To install. checkDoubleResetDetector_Generic v1.8.1+
. To install, checkLittleFS_Portenta_H7 v1.2.0+
. To install, check
The suggested way to install is to:
The best way is to use Arduino Library Manager
. Search for Ethernet_Manager_Portenta_H7
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate to Ethernet_Manager_Portenta_H7 page.
- Download the latest release
Ethernet_Manager_Portenta_H7-main.zip
. - Extract the zip file to
Ethernet_Manager_Portenta_H7-main
directory - Copy the whole
Ethernet_Manager_Portenta_H7-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install Ethernet_Manager_Portenta_H7 library by using Library Manager. Search for Ethernet_Manager_Portenta_H7 in Platform.io Author's Libraries
- Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File
To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.), you have to copy the file portenta_post_install.sh into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh).
Then run the following command using sudo
$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1
$ chmod 755 portenta_post_install.sh
$ sudo ./portenta_post_install.sh
This will create the file /etc/udev/rules.d/49-portenta_h7.rules
as follows:
# Portenta H7 bootloader mode UDEV rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"
Supposing the ArduinoCore-mbed core version is 3.4.1. Now only one file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh
Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/mbed_portenta/x.yy.zz/portenta_post_install.sh
To fix Adafruit_MQTT_Library library
, just copy the following file into the Adafruit_MQTT_Library library
installed directory to overwrite the old files:
See this example and modify as necessary
- To load Default Credentials
bool LOAD_DEFAULT_CONFIG_DATA = true;
- To use system default to load "blank" when there is no valid Credentials
bool LOAD_DEFAULT_CONFIG_DATA = false;
- Example of Default Credentials
/// Start Default Config Data //////////////////
/*
typedef struct Configuration
{
char header [16];
char static_IP [16];
char board_name [24];
int checkSum;
} Ethernet_Configuration;
*/
#define TO_LOAD_DEFAULT_CONFIG_DATA true
#if TO_LOAD_DEFAULT_CONFIG_DATA
bool LOAD_DEFAULT_CONFIG_DATA = false;
Ethernet_Configuration defaultConfig =
{
//char header[16], dummy, not used
#if USE_SSL
"Eth_SSL",
#else
"Eth_NonSSL",
#endif
// char static_IP [16];
//"192.168.2.230",
// Use dynamic DHCP IP
"",
//char board_name [24];
"Air-Control",
// terminate the list
//int checkSum, dummy, not used
0
/////////// End Default Config Data /////////////
};
#else
bool LOAD_DEFAULT_CONFIG_DATA = false;
Ethernet_Configuration defaultConfig;
#endif // TO_LOAD_DEFAULT_CONFIG_DATA
/////////// End Default Config Data /////////////
- Include in your sketch
// Must be before #include <Ethernet_Manager_Portenta_H7.h>
#include <Ethernet_Manager_Portenta_H7.h>
Ethernet_Manager ethernet_manager;
- To add custom parameters, just add
#ifndef dynamicParams_h
#define dynamicParams_h
#include "defines.h"
// USE_DYNAMIC_PARAMETERS defined in defines.h
/////////////// Start dynamic Credentials ///////////////
/**************************************
#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] = "default-mqtt-server";
#define MAX_MQTT_PORT_LEN 6
char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883";
#define MAX_MQTT_USERNAME_LEN 34
char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username";
#define MAX_MQTT_PW_LEN 34
char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password";
#define MAX_MQTT_SUBS_TOPIC_LEN 34
char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic";
#define MAX_MQTT_PUB_TOPIC_LEN 34
char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic";
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 ///////////
#endif //dynamicParams_h
- If you don't need to add dynamic parameters, use the following in sketch
#define USE_DYNAMIC_PARAMETERS false
- When you want to open a config portal, just add
ethernet_manager.begin();
const char NewCustomsStyle[] /*PROGMEM*/ = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}\
button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>";
...
ethernet_manager.setCustomsStyle(NewCustomsStyle);
ethernet_manager.setCustomsHeadElement("<style>html{filter: invert(10%);}</style>");
ethernet_manager.setCORSHeader("Your Access-Control-Allow-Origin");
While in AP mode, connect to it using its SSID
(ESP_XXXXXX) / Password
("MyESP_XXXXXX"), then open a browser to the Portal AP IP, default 192.168.4.1
, configure wifi then click Save. The Credentials / WiFi connection information will be saved in non-volatile memory. It will then autoconnect.
Once Credentials / WiFi network information is saved in the host non-volatile memory, it will try to autoconnect to WiFi every time it is started, without requiring any function calls in the sketch.
- These ids (such as "mqtt" in example) must be unique.
Please be noted that the following reserved names are already used in library:
"ip" for Static IP Address
"nm" for Board Name
If no valid config data are stored in LittleFS, it will switch to Configuration Mode
. Connect to access point at the IP address displayed on Terminal or Router's DHCP server :
After you connected to, for example, 192.168.2.132
, the Browser will display the following picture:
Enter your credentials (Blynk Servers/Tokens and Port). If you prefer static IP, input it (for example 192.168.2.222
) 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 picture:
This ethernet_manager.run()
is not a blocking call, so you can use it for critical functions requiring in loop().
In operation, if Ethernet or connection is lost, ethernet_manager.run()
will try reconnecting automatically. Therefore, ethernet_manager.run()
must be called in the loop()
function.
void loop()
{
ethernet_manager.run();
...
}
Example Ethernet_Portenta_H7
1. File Ethernet_Portenta_H7.ino
2. File defines.h
Ethernet_Manager_Portenta_H7/examples/Ethernet_Portenta_H7/defines.h
Lines 12 to 102 in 37c94fe
3. File Credentials.h
4. File dynamicParams.h
This is the terminal output of PORTENTA_H7_M7 with Ethernet from Portenta Vision shield, running Ethernet_Portenta_H7 example.
Start Ethernet_Portenta_H7 on PORTENTA_H7_M7
Ethernet Shield type : Ethernet using Portenta_Ethernet Library
EthernetManager_Portenta_H7 v1.6.1
DoubleResetDetector_Generic v1.7.3
Flash Size: (KB) = 2048.00
FlashIAP Start Address: = 0x8080000
LittleFS size (KB) = 1536.00
LittleFS Mount OK
LittleFS Flag read = 0xd0d01234
Flag read = 0xd0d01234
doubleResetDetected
Saving to DRD file : 0xd0d04321
Saving DRD file OK
LittleFS Flag read = 0xd0d04321
ClearFlag write = 0xd0d04321
[ETM] =====================
[ETM] DRD. Run ConfigPortal
[ETM] =====================
[ETM] Start connectEthernet using DHCP
[ETM] MAC:FE-9F-FE-D9-D4-BA
[ETM] IP: 192.168.2.132
[ETM] bg: isForcedConfigPortal = false
[ETM] bg:Stay forever in CP: DRD/MRD
[ETM] clearForcedCP
[ETM] SaveCPFile
[ETM] OK
[ETM] CfgIP= 192.168.2.132
Connected! IP address: 192.168.2.132
Your stored Credentials :
MQTT Server = default-mqtt-server
Port = 1883
MQTT UserName = default-mqtt-username
MQTT PWD = default-mqtt-password
Subs Topics = default-mqtt-SubTopic
Pubs Topics = default-mqtt-PubTopic
HHHHHHHHHHETM]
h:Updating LittleFS: /littlefs/config.etm
[ETM] WCSum=0x c1f
[ETM] CrWCSum=0x 219f
[ETM] h:Rst
Start Ethernet_Portenta_H7 on PORTENTA_H7_M7
Ethernet Shield type : Ethernet using Portenta_Ethernet Library
EthernetManager_Portenta_H7 v1.6.1
DoubleResetDetector_Generic v1.7.3
Flash Size: (KB) = 2048.00
FlashIAP Start Address: = 0x8080000
LittleFS size (KB) = 1536.00
LittleFS Mount OK
LittleFS Flag read = 0xd0d04321
Flag read = 0xd0d04321
No doubleResetDetected
Saving DOUBLERESETDETECTOR_FLAG to DRD file : 0xd0d01234
Saving DRD file OK
SetFlag write = 0xd0d01234
[ETM] CCSum=0x c1f ,RCSum=0x c1f
[ETM] CrCCsum=0x 219f ,CrRCsum=0x 219f
[ETM] CrCCsum=0x 219f ,CrRCsum=0x 219f
[ETM] Valid Stored Dynamic Data
[ETM] ======= Start Stored Config Data =======
[ETM] Header= PORTENTA-H7-ETH , BoardName= Portenta_H7_ETH
[ETM] StaticIP= 192.168.2.222
[ETM] Start connectEthernet using Static IP = 192.168.2.222
[ETM] MAC:FE-9D-FD-DA-DC-83
[ETM] IP: 192.168.2.222
[ETM] begin:Ethernet Connected.
Connected! IP address: 192.168.2.222
Stop doubleResetDetecting
Saving to DRD file : 0xd0d04321
Saving DRD file OK
LittleFS Flag read = 0xd0d04321
ClearFlag write = 0xd0d04321
H
Your stored Credentials :
MQTT Server = new-mqtt-server
Port = 1883
MQTT UserName = new-mqtt-username
MQTT PWD = new-mqtt-password
Subs Topics = new-mqtt-SubTopic
Pubs Topics = new-mqtt-PubTopic
This is the terminal output of PORTENTA_H7_M7 with Ethernet from Portenta Vision shield, running MQTT_Ethernet_Portenta_H7 example.
Start MQTT_Ethernet_Portenta_H7 on PORTENTA_H7_M7
Ethernet Shield type : Ethernet using Portenta_Ethernet Library
EthernetManager_Portenta_H7 v1.6.1
DoubleResetDetector_Generic v1.7.3
Flash Size: (KB) = 2048.00
FlashIAP Start Address: = 0x8080000
LittleFS size (KB) = 1536.00
LittleFS Mount OK
LittleFS Flag read = 0xd0d01234
Flag read = 0xd0d01234
doubleResetDetected
Saving to DRD file : 0xd0d04321
Saving DRD file OK
LittleFS Flag read = 0xd0d04321
ClearFlag write = 0xd0d04321
[ETM] =====================
[ETM] DRD. Run ConfigPortal
[ETM] =====================
[ETM] CCSum=0x 8e7 ,RCSum=0x 8e7
[ETM] CrCCsum=0x 19fa ,CrRCsum=0x 19fa
[ETM] CrCCsum=0x 19fa ,CrRCsum=0x 19fa
[ETM] Valid Stored Dynamic Data
[ETM] ======= Start Stored Config Data =======
[ETM] Header= PORTENTA-H7-ETH , BoardName= Portenta-MQTT
[ETM] StaticIP=
[ETM] Start connectEthernet using DHCP
[ETM] MAC:FE-98-FB-D7-D5-BA
[ETM] IP: 192.168.2.132
[ETM] bg: isForcedConfigPortal = false
[ETM] bg:Stay forever in CP: DRD/MRD
[ETM] clearForcedCP
[ETM] SaveCPFile
[ETM] OK
[ETM] CfgIP= 192.168.2.132
Connected! IP address: 192.168.2.132
H
Your stored Credentials :
AIO_SERVER = io.adafruit.com
AIO_SERVERPORT = 1883
AIO_USERNAME = private
AIO_KEY = private
AIO_PUB_TOPIC = /feeds/Temperature
AIO_SUB_TOPIC = /feeds/LED_Control
HHHHHHHHH HHHHHHHHHH HH
Start MQTT_Ethernet_Portenta_H7 on PORTENTA_H7_M7
Ethernet Shield type : Ethernet using Portenta_Ethernet Library
EthernetManager_Portenta_H7 v1.6.1
DoubleResetDetector_Generic v1.7.3
Flash Size: (KB) = 2048.00
FlashIAP Start Address: = 0x8080000
LittleFS size (KB) = 1536.00
[ETM] CCSum=0x adb ,RCSum=0x adb
[ETM] CrCCsum=0x 2236 ,CrRCsum=0x 2236
[ETM] CrCCsum=0x 2236 ,CrRCsum=0x 2236
[ETM] Valid Stored Dynamic Data
[ETM] ======= Start Stored Config Data =======
[ETM] Header= PORTENTA-H7-ETH , BoardName= PORTENTA-H7-ETH
[ETM] StaticIP= 192.168.2.222
[ETM] Start connectEthernet using Static IP = 192.168.2.222
[ETM] MAC:FE-9E-FF-D6-DA-BA
[ETM] IP: 192.168.2.222
[ETM] begin:Ethernet Connected.
Connected! IP address: 192.168.2.222
H
Your stored Credentials :
AIO_SERVER = io.adafruit.com
AIO_SERVERPORT = 1883
AIO_USERNAME = user_name
AIO_KEY = aio_key
AIO_PUB_TOPIC = /feeds/Temperature
AIO_SUB_TOPIC = /feeds/LED_Control
Creating new Ethernet client object OK
Creating new MQTT object OK
AIO_SERVER = io.adafruit.com, AIO_SERVERPORT = 1883
AIO_USERNAME = user_name, AIO_KEY = aio_key
Creating new MQTT_Pub_Topic, Temperature = user_name/feeds/Temperature
Creating new Temperature object OK
Temperature MQTT_Pub_Topic = user_name/feeds/Temperature
Creating new AIO_SUB_TOPIC, LED_Control = user_name/feeds/LED_Control
Creating new LED_Control object OK
LED_Control AIO_SUB_TOPIC = user_name/feeds/LED_Control
THTHTHT
Debug is enabled by default on Serial.
You can also change the debugging level from 0 to 4
/* Comment this out to disable prints and save space */
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 0
#define _Ethernet_Manager_Portenta_H7_LOGLEVEL_ 2
If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.
Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.
Submit issues to: Ethernet_Manager_Portenta_H7 issues
- Same features for other boards with new Ethernet shields.
- Add SSL/TLS feature.
- Bug Searching and Killing
- Support more non-compatible Ethernet Libraries such as Ethernet_Shield_W5200, EtherCard, EtherSia.
- Add support to Portenta_H7 using Ethernet from Portenta Vision shields
- More flexible to configure reconnection timeout.
- For fresh config data, don't need to wait for connecting timeout before entering config portal.
- If the config data not entered completely (Credentials, etc.), entering config portal
- Add configurable Config Portal IP
- Change Synch XMLHttpRequest to Async
- Add configurable Static IP, GW, Subnet Mask and 2 DNS Servers' IP Addresses.
- Add checksums
- Add auto(re)connect
- Easy-to-use Dynamic Parameters without the necessity to write complicated ArduinoJSon functions
- Default Credentials and dynamic parameters
- DoubleDetectDetector to force Config Portal when double reset is detected within predetermined time, default 10s.
- Configurable Config Portal Title
- Re-structure all examples to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dyamic Params quickly for each device.
- Add Table of Contents and Version String
- Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header
- Add functions to control Config Portal from software or Virtual Switches.
- Add
LibraryPatches
for Adafruit_MQTT_Library to fix compiler error for Portenta_H7, RP2040-based and many other boards.
Please help contribute to this project and add your name here.
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed under MIT
Copyright (c) 2021- Khoi Hoang