Blynk Credentials Manager for STM32, AVR, Teensy, etc. boards running ESP8266 AT-command shields

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

Blynk Credentials Manager for STM32, AVR, Teensy, etc. boards running ESP8266 AT-command shields

Post by khoih-prog »

Blynk Credentials Manager for Esp8266AT library

How To Install Using Library Manager

New Version v1.0.3

1. Add support to STM32 (STM32F1, F2, F3, F4, F7, etc) boards

New Version v1.0.2

1. Add support to SAMD (DUE, ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit CIRCUITPLAYGROUND_EXPRESS, etc.) boards

To help you to eliminate hardcoding your Wifi and Blynk credentials for Mega/Teensy boards running ESP8266 AT shields, and updating/reflashing every time when you need to change them. Configuration data are saved in configurable location in EEPROM.

With version v1.0.0 or later, you now can configure:

1. Config Portal Static IP address, Name and Password.
2. Static IP address, Gateway, Subnet Mask and 2 DNS Servers IP addresses.

Sample Code

Code: Select all

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

#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3)  ||defined(STM32F4) || defined(STM32F7) )
  #if defined(ESP8266_AT_USE_STM32)
    #undef ESP8266_AT_USE_STM32
  #endif
  #define ESP8266_AT_USE_STM32      true
#endif

#if ( defined(ESP8266) || defined(ESP32) || defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(CORE_TEENSY) || !(ESP8266_AT_USE_STM32) )
//#error This code is intended to run on STM32 platform! Please check your Tools->Board setting.
#endif

#if ESP8266_AT_USE_STM32
  // For STM32, you have to declare and enable coreresponding Serial Port somewhere else before using it
  #define EspSerial Serial1
 
  #if defined(STM32F0)
    #define BOARD_TYPE  "STM32F0"
    #error Board STM32F0 not supported
  #elif defined(STM32F1)
    #define BOARD_TYPE  "STM32F1"
  #elif defined(STM32F2)
    #define BOARD_TYPE  "STM32F2"
  #elif defined(STM32F3)
    #define BOARD_TYPE  "STM32F3"
  #elif defined(STM32F4)
    #define BOARD_TYPE  "STM32F4"
  #elif defined(STM32F7)
    #define BOARD_TYPE  "STM32F7"  
  #else
    #warning STM32 unknown board selected
    #define BOARD_TYPE  "STM32 Unknown"  
  #endif
#else
// For Mega
#define EspSerial Serial3
#define BOARD_TYPE      "AVR Mega"
#endif

#include <ESP8266_Lib.h>

// Start location in EEPROM to store config data. Default 0
// Config data Size currently is 128 bytes)
#define EEPROM_START     0

#define USE_BLYNK_WM      true
//#define USE_BLYNK_WM      false

#if USE_BLYNK_WM
  #if ESP8266_AT_USE_STM32
    #include <BlynkSimpleShieldEsp8266_STM32_WM.h>
  #else
    #include <BlynkSimpleShieldEsp8266_WM.h>
  #endif
#else
  #include <BlynkSimpleShieldEsp8266_STM32.h>

  #define USE_LOCAL_SERVER      true

  #if USE_LOCAL_SERVER
    char auth[] = "****";
    String BlynkServer = "account.duckdns.org";
    //String BlynkServer = "192.168.2.112";
  #else
    char auth[] = "****";
    String BlynkServer = "blynk-cloud.com";
  #endif

  #define BLYNK_SERVER_HARDWARE_PORT    8080

  // Your WiFi credentials.
  char ssid[] = "****";
  char pass[] = "****";
  
#endif

// Your Teensy <-> ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

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

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

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

#define STATUS_CHECK_INTERVAL     15000L

  // 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))
  {
    // report status to Blynk
    heartBeatPrint();

    checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
  }
}

void setup() 
{
  // Debug console
  Serial.begin(115200);
  delay(1000);
 
  // initialize serial for ESP module
  EspSerial.begin(ESP8266_BAUD);
  Serial.println("\nStart Blynk WiFiManager using ESP8266_AT_Shield on " + String(BOARD_TYPE));

  #if USE_BLYNK_WM
    Serial.println("Start Blynk_WM");
    Blynk.setConfigPortalIP(IPAddress(192, 168, 100, 1));
    //Blynk.setConfigPortal("Teensy4", "MyTeensy4");  
    Blynk.begin(wifi);
  #else
    Serial.println("Start Blynk");
    Blynk.begin(auth, wifi, ssid, pass, BlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
  #endif
}

void loop()
{
  Blynk.run();
  check_status();
}
The following is the sample terminal output when running example Teensy40_ESP8266Shield

1. No Config Data => Config Portal

Code: Select all

Start Blynk WiFiManager using ESP8266_AT_Shield on TEENSY 4.0
Start Blynk_WM
[7866] AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK
[8392] Init new EEPROM, size = 1080
[8393] bg: No configdat. Stay forever in config portal
[12836] startConfig: SSID = Teensy4_CCE61, PW = MyTeensy4_CCE61, IP = 192.168.100.1
2. Config Data Ready => Run

Code: Select all

Start Blynk WiFiManager using ESP8266_AT_Shield on TEENSY 4.0
Start Blynk_WM
[7866] AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK
[8390] Header = SHD_ESP8266, SSID = ****, PW = ****
[8390] Server = ****.duckdns.org, Port = 8080, Token = ****
[8390] Board Name = Teensy4-WM
[8390] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Teensy 4.0

[8390] con2WF: start
[8390] connectToWifi: Try connectWiFi
[8390] Connecting to ****
[14956] AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK
[15493] Get macAddress = 5c:cf:7f:66:05:d2
[22526] IP = 192.168.2.107

[22543] Connected to WiFi
[22543] con2WF: con OK
[22543] IP = 192.168.2.107

[22560] bg: WiFi connected. Try Blynk
[32717] Ready (ping: 18ms).
[32932] bg: WiFi+Blynk connected
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB 
F[634808] run: Blynk lost. Connect Blynk
F[649868] run: Blynk lost. Connect Blynk
F[664928] run: Blynk lost. Connect Blynk
[675040] Ready (ping: 13ms).
[675265] run: Blynk reconnected
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB 

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

We 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. We can download, compile and use to be sure having full control.

Use Local Blynk Server

Blynk Server

Blynk Server Source Code
khoih-prog
Posts: 94
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: Blynk Credentials Manager for STM32, AVR, Teensy, etc. boards running ESP8266 AT-command shields

Post by khoih-prog »

New Releases v1.0.4

1. Add support to SAM DUE
2. Reduce html and code size for faster Config Portal response.
3. Enhance GUI.

How it works

If it cannot connect to the Blynk server in 30 seconds, it will switch to `Configuration Mode`. You will see your built-in LED turned ON. In `Configuration Mode`, it starts a configurable access point, default called Teensy4_XXXXXX`, `SAMD_XXXXXX`, `DUE_XXXXXX`,`Mega_XXXXXX` or `STM32_XXXXXX. Connect to it using password MyTeensy4_XXXXXX`, `MySAMD_XXXXXX`, `MyDUE_XXXXXX`, `MyMega_XXXXXX` or `MySTM32_XXXXXX.

Image

After you connected, please, go to http://192.168.4.1 or the AP IP you specified.

Image

Enter your credentials : WiFi SSID/Password, Blynk Server, Port and Token, Board Name.

Image

Then click `Save`. After you restarted, you will see your built-in LED turned OFF. That means, it connected to your Blynk server successfully.
khoih-prog
Posts: 94
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: Blynk Credentials Manager for STM32, AVR, Teensy, etc. boards running ESP8266 AT-command shields

Post by khoih-prog »

New Releases v1.0.7

1. Add support to all STM32F/L/H/G/WB/MP1 (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.)
2. Add support to Seeeduino SAMD21/SAMD51 boards (SEEED_WIO_TERMINAL, SEEED_FEMTO_M0, SEEED_XIAO_M0, Wio_Lite_MG126, WIO_GPS_BOARD, SEEEDUINO_ZERO, SEEEDUINO_LORAWAN, SEEED_GROVE_UI_WIRELESS, etc.)
3. Sync with latest ESP8266_AT_WebServer Library v1.0.12

New Releases v1.0.6

1. Add support to ESP32-AT
2. Use new ESP_AT_Lib to support ESP8266/ESP32-AT
3. Enhance MultiWiFi connection logic.
4. New logic for USE_DEFAULT_CONFIG_DATA to autoload Config / Dynamic Data in developing stage.

Major Releases v1.0.5

1. Add support to nRF52 (AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc.). Dynamic custom parameters to be saved automatically in LittleFS.
2. Add support to Adafruit SAMD21/SAM51 (Itsy-Bitsy M0/M4, Metro M0/M4, Grand Central M4, Feather M0/M4 Express, etc.). Dynamic custom parameters to be saved automatically in FlashStorage.
3. Add MultiWiFi features for WiFi
4. Add DoubleResetDetector (DRD) feature.
5. Increase WPA2 SSID and PW to 63 chars. Permit special chars such as !,@,#,$,%,^,&,* into data fields.
6. Restructure examples separate Credentials / Defines / Dynamic Params / Code.
7. Drop support to Teensy boards.


The following is the sample terminal output when running example STM32_ESP8266Shield  using STM32 Nucleo-144 NUCLEO_F767ZI with ESP8266-AT shield.

Code: Select all

Start STM32_ESP8266Shield on NUCLEO_F767ZI
Start Blynk_ESP8266AT_WM
[6566] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK

EEPROM size = 16384, start = 0
Flag read = 0xffffffff
No doubleResetDetected
SetFlag write = 0xd0d01234
[11998] ======= Start Default Config Data =======
[12000] Hdr=STM32_ESP_AT,SSID=HueNet1,PW=password
[12004] SSID1=HueNet,PW1=password
[12007] Svr=account.duckdns.org,Prt=8080,Tok=new_token
[12014] BName=STM32_ESP_AT
[12017] i=0,id=mqtt,data=default-mqtt-server
[12021] i=1,id=mqpt,data=1883
[12023] SaveEEPROM,Sz=16384,DataSz=0,WCSum=0x2360
[12028] ======= Start Loaded Config Data =======
[12032] Hdr=SHD_ESP8266,SSID=HueNet1,PW=password
[12037] SSID1=HueNet,PW1=password
[12040] Svr=account.duckdns.org,Prt=8080,Tok=new_token
[12047] BName=STM32_ESP_AT
[12049] i=0,id=mqtt,data=default-mqtt-server
[12053] i=1,id=mqpt,data=1883
[12056] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on STM32 NUCLEO_F767ZI

[12069] ConMultiWifi
[12071] con2WF:SSID=HueNet1,PW=password
[12075] Remaining retry_time=3
[12078] Con2:HueNet1
[18645] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[19189] Mac=68:c6:3a:a4:6a:97
[24253] IP=192.168.2.85


[24270] WOK
[24270] WOK, lastConnectedIndex=0
[24270] con2WF:OK
[24272] IP=192.168.2.85


[24290] b:WOK.TryB
[34457] Ready (ping: 12ms).
[34633] b:WBOK
Stop doubleResetDetecting
ClearFlag write = 0xd0d04321
B
Your stored Credentials :
MQTT Server = default-mqtt-server
Port = 1883
BBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB
Post Reply

Return to “Libraries & Hardware”