The use of the ESP8266 in the world of IoT

User avatar
By khoih-prog
#86017 https://github.com/khoih-prog/ESP_AT_WM_Lite

How To Install Using Arduino Library Manager

This library is a Light Weight Credentials / WiFi Manager for ESP8266 AT shields, specially designed to support AVR Mega, STM32, Teensy, SAM DUE, SAMD, etc. boards running ESP8266 AT-command shields, with smaller memory (64+K bytes)

You can also specify static AP and STA IP. Use much less memory compared to full-fledge WiFiManager. Credentials are saved in EEPROM, FlashStorage or DueFlashStorage.

You can use this library when your boards have more than 32K bytes of memory, for example Mega 1280/2560, SAM DUE, BluePill/BlackPill F103C8 (64+K Bytes).

The web configuration portal, served from the ESP8266 AT-command shields is operating as an access point (AP) with configurable static IP address or use default IP Address of 192.168.4.1

Sample Code
Code: Select all/* Comment this out to disable prints and save space */
#define ESP_AT_DEBUG_OUTPUT Serial

#define ESP_AT_DEBUG    true

#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

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

#include <Esp8266_AT_WM_Lite_STM32.h>

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

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

  if (WiFi.status() == WL_CONNECTED)
    Serial.print("H");        // H means connected to WiFi
  else
    Serial.print("F");        // F means not connected to WiFi
 
  if (num == 80)
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0)
  {
    Serial.print(" ");
  }
}

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

  //KH
  #define HEARTBEAT_INTERVAL    10000L
  // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds.
  if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
  {
    heartBeatPrint();
    checkstatus_timeout = millis() + HEARTBEAT_INTERVAL;
  }
}

ESP_AT_WiFiManager_Lite* ESP_AT_WiFiManager;    //(&EspSerial, ESP8266_BAUD);

void setup()
{
  // Debug console
  Serial.begin(115200);
  delay(1000);

  Serial.println("\nStart STM32_ESP8266Shield on " + String(BOARD_TYPE));

  // initialize serial for ESP module
  EspSerial.begin(115200);
 
  ESP_AT_WiFiManager = new ESP_AT_WiFiManager_Lite(&EspSerial, ESP8266_BAUD);

  // Optional to change default AP IP(192.168.4.1) and channel(10)
  //ESP_AT_WiFiManager->setConfigPortalIP(IPAddress(192, 168, 120, 1));
  //ESP_AT_WiFiManager->setConfigPortalChannel(1);

  ESP_AT_WiFiManager->begin();
}

void loop()
{
  ESP_AT_WiFiManager->run();
  check_status();
}


This is the terminal output when running Teensy_ESP8266Shield example on Teensy 4.0

1. Open Config Portal

Code: Select allStart Teensy_ESP8266Shield on TEENSY 4.0
*AT: CCsum=5543,RCsum=1127042391
*AT: Init EEPROM sz=1080
*AT: Open Portal
*AT: SSID=ESP_AT_CCE61, PW=MyESP_AT_CCE61
*AT: IP=192.168.4.1, CH=10
FFF


2. Got valid Credential from Config Portal, then connected to WiFi

Code: Select allStart Teensy_ESP8266Shield on TEENSY 4.0
*AT: CCsum=2271,RCsum=2271
*AT: Hdr=SHD_ESP8266, SSID=HueNet1, PW=****
*AT: con2WF:start
*AT: con2WF:spent millis=0
*AT: Con2 HueNet1
*AT: IP=192.168.2.82
*AT: WiFi OK
*AT: con2WF:OK
*AT: IP=192.168.2.82
*AT: WiFi OK
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH

And the Config Portal screens:

1.Main Screen
Image

2. Input Credentials:
Image

3. After pressing Save button
Image
User avatar
By khoih-prog
#86143 Updated: Mar 22nd 2020

New in v1.0.1

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, SAMD EEPROM-emulated FlashStorage or SAM DUE DueFlashStorage.

If you have used the full-fledge WiFiManager such as :
1. Tzapu WiFiManager
2. Ken Taylor WiFiManager
3. ESP_WiFiManager

and have to write complicated callback functions to save custom parameters in SPIFFS, you'd appreciate the simplicity of this Light-Weight Credentials / WiFiManager

How It Works

- The STM32_ESP8266Shield example shows how it works and should be used as the basis for a sketch that uses this library.
- The concept of  STM32_ESP8266Shield example is that a new ESP8266 AT shield will start a WiFi configuration portal when powered up, but has no valid stored Credentials.
- There are 6 more custom parameters added in the sketch which you can use in your program later. In the example, they are: 2 sets of Blynk Servers and Tokens, Blynk Port and MQTT Server.
- Using any WiFi enabled device with a browser (computer, phone, tablet) connect to the newly created AP and type in the configurable AP IP address (default 192.168.4.1). The Config Portal AP channel (default 10) is also configurable to avoid conflict with other APs.
- The Config Portal is auto-adjusted to fix the 2 static parameters (WiFi SSID/PWD) as well as 6 more dynamic custom parameters.
- After the custom data entered, and Save button pressed, the configuration data will be saved in host's non-volatile memory, then the board reboots.
- If there is valid stored Credentials, it'll go directly to connect to WiFi without starting / using the Config Portal.
- ESP8266 AT shield will try to connect. If successful, the dynamic DHCP or configured static IP address will be displayed in the configuration portal.
- The ESP8266 AT shield WiFi Config Portal network and Web Server will shutdown to return control to the sketch code.

This is the terminal output when running STM32_ESP8266Shield example on STM32:

1. Open Config Portal

Code: Select allStart STM32_ESP8266Shield on STM32F4
*AT: CrCCsum=6217,CrRCsum=825255525
*AT: CCSum=1983,RCSum=1752461166
*AT: InitEEPROM,sz=1080,Datasz=264
*AT: pdata=blank,len=34
*AT: pdata=blank,len=34
*AT: pdata=blank,len=34
*AT: pdata=blank,len=34
*AT: pdata=blank,len=6
*AT: pdata=blank,len=34
*AT: CrCCSum=3120
*AT: b:OpenPortal
*AT: SSID=ESP_AT_E50AB22C,PW=MyESP_AT_E50AB22C
*AT: IP=192.168.4.1,CH=1
Your stored Credentials :
Blynk Server1 = blank
Token1 = blank
Blynk Server2 = blank
Token2 = blank
Port = blank
MQTT Server = blank
FFF



2. Got valid Credential from Config Portal, then connected to WiFi

Code: Select allStart STM32_ESP8266Shield on STM32F4
*AT: CrCCsum=10595,CrRCsum=10595
*AT: CCSum=2271,RCSum=2271
*AT: Hdr=SHD_ESP8266,SSID=HueNet1,PW=****
*AT: i=0,id=sv1,data=blynk1.duckdns.org
*AT: i=1,id=tk1,data=****
*AT: i=2,id=sv2,data=blynk2.duckdns.org
*AT: i=3,id=tk2,data=****
*AT: i=4,id=pt,data=8080
*AT: i=5,id=mq,data=mqtt.duckdns.org
*AT: con2WF:start
*AT: con2WF:spentMsec=0
*AT: Con2:HueNet1
*AT: IP=192.168.2.135
*AT: WOK
*AT: con2WF:OK
*AT: IP=192.168.2.135
*AT: b:WOK
Your stored Credentials :
Blynk Server1 = blynk1.duckdns.org
Token1 = ****
Blynk Server2 = blynk2.duckdns.org
Token2 = ****
Port = 8080
MQTT Server = mqtt.duckdns.org

HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH