Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: Light Weight Credentials/WiFiManager for Teensy, SAM DUE, SAMD, STM32 & ESP8266 AT

  1. #1
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25

    Light Weight Credentials/WiFiManager for Teensy, SAM DUE, SAMD, STM32 & ESP8266 AT

    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 Teensy, SAM DUE, SAMD, STM32, 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 Teensy 4.0, 3.6, 3.5, 3.2/3.1, 3.0, LC.. Teensy 2.0++ and Teensy 2.0 are not supported yet.

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

    Sample Code
    Code:
    /* Comment this out to disable prints and save space */
    #define ESP_AT_DEBUG_OUTPUT Serial
    
    #define ESP_AT_DEBUG    true
    
    #if ( defined(ESP8266) || defined(ESP32) || defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || !defined(CORE_TEENSY) )
    #error This code is intended to run on Teensy platform! Please check your Tools->Board setting.
    #endif
    
    #ifdef CORE_TEENSY
    
    #if defined(__IMXRT1062__)
    // For Teensy 4.0
    #define EspSerial Serial2   //Serial2, Pin RX2 : 7, TX2 : 8
    #define BOARD_TYPE      "TEENSY 4.0"
    #elif defined(__MK66FX1M0__)
    #define BOARD_TYPE "Teensy 3.6"
    #elif defined(__MK64FX512__)
    #define BOARD_TYPE "Teensy 3.5"
    #elif defined(__MKL26Z64__)
    #define BOARD_TYPE "Teensy LC"
    #elif defined(__MK20DX256__)
    #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete)
    #elif defined(__MK20DX128__)
    #define BOARD_TYPE "Teensy 3.0"
    #elif defined(__AVR_AT90USB1286__)
    #error Teensy 2.0++ not supported yet
    #elif defined(__AVR_ATmega32U4__)
    #error Teensy 2.0 not supported yet
    #else
    // For Other Boards
    #define EspSerial Serial3
    #define BOARD_TYPE      "Unknown Teensy Board"
    #endif
    #endif
    
    #if !defined(EspSerial)
    #define EspSerial Serial1
    #endif
    
    // Start location in EEPROM to store config data. Default 0
    // Config data Size currently is 128 bytes)
    #define EEPROM_START     256
    
    #include <Esp8266_AT_WM_Lite_Teensy.h>
    
    // Your Teensy <-> 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 Teensy_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:
    Start 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:
    Start 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

    Name:  Main.png
Views: 89
Size:  3.9 KB

    2. Input Credentials:

    Name:  Input.png
Views: 85
Size:  4.1 KB

    3. After pressing Save button

    Click image for larger version. 

Name:	Save.png 
Views:	3 
Size:	10.7 KB 
ID:	19338

  2. #2
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25
    Better Config Portal GUI

    The Config Portal screens:

    1.Main Screen

    Click image for larger version. 

Name:	Main.png 
Views:	2 
Size:	6.0 KB 
ID:	19369

    2. Input Credentials:

    Click image for larger version. 

Name:	Input.png 
Views:	2 
Size:	5.3 KB 
ID:	19372

    3. After pressing Save button

    Click image for larger version. 

Name:	Save.png 
Views:	2 
Size:	8.9 KB 
ID:	19373

  3. #3
    Senior Member
    Join Date
    Aug 2017
    Posts
    193
    Quote Originally Posted by khoih-prog View Post
    Better Config Portal GUI

    The Config Portal screens:

    1.Main Screen

    Click image for larger version. 

Name:	Main.png 
Views:	2 
Size:	6.0 KB 
ID:	19369

    2. Input Credentials:

    Click image for larger version. 

Name:	Input.png 
Views:	2 
Size:	5.3 KB 
ID:	19372

    3. After pressing Save button

    Click image for larger version. 

Name:	Save.png 
Views:	2 
Size:	8.9 KB 
ID:	19373
    Got this error when to complile:
    Code:
    In file included from /home/wwatson/Arduino/libraries/ESP_AT_WM_Lite/examples/Teensy40_ESP8266Shield/Teensy40_ESP8266Shield.ino:62:0:
    /home/wwatson/Arduino/libraries/ESP_AT_WM_Lite/src/Esp8266_AT_WM_Lite_Teensy.h:31:34: fatal error: ESP8266_AT_WebServer.h: No such file or directory
    compilation terminated.
    Using library ESP_AT_WM_Lite at version 1.0.0 in folder: /home/wwatson/Arduino/libraries/ESP_AT_WM_Lite 
    Error compiling for board Teensy 4.0.

  4. #4
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25
    Hi,

    Thanks for using the library.

    This library depends on ESP8266_AT_WebServer Library.

    Please install ESP8266_AT_WebServer Library then recompile.

    The issue now is that the library is still new and not included in Arduino IDE Library Manager yet.
    Later, the IDE will normally ask you to include that library thanks to the dependency in libraries.properties

    Code:
    depends=ESP8266_AT_WebServer

  5. #5
    Senior Member
    Join Date
    Aug 2017
    Posts
    193
    Quote Originally Posted by khoih-prog View Post
    Hi,

    Thanks for using the library.

    This library depends on ESP8266_AT_WebServer Library.

    Please install ESP8266_AT_WebServer Library then recompile.

    The issue now is that the library is still new and not included in Arduino IDE Library Manager yet.
    Later, the IDE will normally ask you to include that library thanks to the dependency in libraries.properties

    Code:
    depends=ESP8266_AT_WebServer
    Installed the needed library and got this error when trying to compile:
    Code:
      -> candidates: []
    In file included from /home/wwatson/Arduino/libraries/ESP_AT_WM_Lite/src/Esp8266_AT_WM_Lite_Teensy.h:31:0,
                     from /home/wwatson/Arduino/libraries/ESP_AT_WM_Lite/examples/Teensy40_ESP8266Shield/Teensy40_ESP8266Shield.ino:62:
    /home/wwatson/Arduino/libraries/ESP8266_AT_WebServer/src/ESP8266_AT_WebServer.h:47:29: fatal error: functional-vlpp.h: No such file or directory
    compilation terminated.
    Using library ESP_AT_WM_Lite at version 1.0.0 in folder: /home/wwatson/Arduino/libraries/ESP_AT_WM_Lite 
    Using library ESP8266_AT_WebServer at version 1.0.3 in folder: /home/wwatson/Arduino/libraries/ESP8266_AT_WebServer 
    Error compiling for board Teensy 4.0.
    I think I am missing something

  6. #6
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25
    If you install using Arduino IDE Library Manager, it might have asked you to install the dependency.

    Otherwise, you need to manually install Functional-Vlpp

  7. #7
    Senior Member
    Join Date
    Aug 2017
    Posts
    193
    Quote Originally Posted by khoih-prog View Post
    If you install using Arduino IDE Library Manager, it might have asked you to install the dependency.

    Otherwise, you need to manually install Functional-Vlpp
    Ok now it compiles.

    This is the output:
    Code:
    Start Teensy_ESP8266Shield on TEENSY 4.0
    [ESP_AT] AT_Drv::readUntil, millis = 1300
    [ESP_AT] AT_Drv::readUntil, millis = 3300
    [ESP_AT] AT_Drv::readUntil, millis = 5300
    [ESP_AT] AT_Drv::readUntil, millis = 7300
    [ESP_AT] AT_Drv::readUntil, millis = 9300
    [ESP_AT] Cannot initialize ESP module
    [ESP_AT] AT_Drv::readUntil, millis = 16300
    *AT: WiFi shield not present
    [ESP_AT] AT_Drv::readUntil, millis = 17300
    [ESP_AT] AT_Drv::readUntil, millis = 21300
    [ESP_AT] AT_Drv::readUntil, millis = 22300
    [ESP_AT] AT_Drv::readUntil, millis = 23500
    [ESP_AT] AT_Drv::readUntil, millis = 24500
    [ESP_AT] AT_Drv::readUntil, millis = 25500
    [ESP_AT] AT_Drv::readUntil, millis = 26500
    *AT: CCsum=2282,RCsum=0
    *AT: Init EEPROM sz=1080
    *AT: Open Portal
    [ESP_AT] AT_Drv::readUntil, millis = 27700
    [ESP_AT] AT_Drv::readUntil, millis = 31700
    [ESP_AT] AT_Drv::readUntil, millis = 32700
    [ESP_AT] AT_Drv::readUntil, millis = 33900
    [ESP_AT] AT_Drv::readUntil, millis = 34900
    [ESP_AT] AT_Drv::readUntil, millis = 35900
    [ESP_AT] AT_Drv::readUntil, millis = 36900
    [ESP_AT] AT_Drv::readUntil, millis = 38100
    [ESP_AT] AT_Drv::readUntil, millis = 39100
    [ESP_AT] AT_Drv::readUntil, millis = 40600
    *AT: SSID=ESP_AT_CCE61, PW=MyESP_AT_CCE61
    *AT: IP=192.168.4.1, CH=10
    [ESP_AT] AT_Drv::readUntil, millis = 43100
    I am using a T4 breakout board from:
    https://www.tindie.com/products/cbur...ac_prod_search

    It has an ESP8266 on board with communications on Serial1. It also uses AT commands. Is there a particular ESP8266 program that needs to be loaded into it?

    Thanks

  8. #8
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25
    Currently, for T4, the example uses Serial2 of T4, and speed is 115KBauds

    Code:
    #define EspSerial Serial2   //Serial2, Pin RX2 : 7, TX2 : 8
    ...
    // Your Teensy <-> ESP8266 baud rate:
    #define ESP8266_BAUD 115200
    The connection for using Serial2 is:

    1. Pin RX2 (7 of T4) <=> TX of ESP-01/ESP-12E
    2. Pin TX2 (8 of T4) <=> RX of ESP-01/ESP-12E
    3. 3.3V <=> 3.3V + EN of ESP-01/ESP-12E
    4. GND <=> GND of ESP-01/ESP-12E


    You can change the Serial port in the code depending on how you connect the ESP module to T4. I currently don't have the mentioned T4 breakout board to know how the connection is actually made.

    You also have to load/test the working AT-command firmware to ESP8266 module, if not yet done, then check if the baud rate is 115200. If baud rate is different from 115200, change correspondingly in the code.

    I'm currently using this AT-command firmware version:

    Code:
    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

  9. #9
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25
    Just read the schematic PDF of the board, and ESP is connected to Serial1 (TX1/RX1) of T4.

    Arduino-Teensy4_PLUS_ESP-12E_r1-SCH.pdf

    To test, you can change line 31 of the example code from

    Code:
    #define EspSerial Serial2   //Serial2, Pin RX2 : 7, TX2 : 8
    to

    Code:
    #define EspSerial Serial1   //Serial1, Pin RX1 : 0, TX1 : 1
    Please also check if solder jumpers SJ-2 and SJ-3 are connected.

    The ESP-PGM button is pressed whenever you'd like to upload the AT firmware to ESP module.

  10. #10
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25
    Hope you are doing OK now.
    Just had some mods in the code so that the Config Portal AP SSID is using unique macAddress/ID of Teensy board now, for example ESP_AT_E50AB22C

    Code:
    Start Teensy_ESP8266Shield on TEENSY 4.0
    *AT: CCsum=4286,RCsum=2271
    *AT: Init EEPROM sz=1080
    *AT: Open Portal
    *AT: SSID=ESP_AT_E50AB22C,PW=MyESP_AT_E50AB22C
    *AT: IP=192.168.4.1,CH=10

  11. #11
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    25
    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 Teensy40_ESP8266Shield example shows how it works and should be used as the basis for a sketch that uses this library.
    - The concept of Teensy40_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.

    So, how it works?

    In Configuration Portal Mode, it starts an AP called ESP_AT_XXXXXX. Connect to it using the configurable password you can define in the code. For example, MyESP_AT_XXXXXX (see examples):

    ```cpp
    // SSID and PW for Config Portal
    String ssid = "ESP_AT_" + String(0x1ABCDEF, HEX);
    const char* password = "ESP_AT_PW";
    ```
    After you connected, please, go to http://192.168.4.1 or newly configured AP IP, you'll see this Main page:

    Click image for larger version. 

Name:	Main.png 
Views:	0 
Size:	19.0 KB 
ID:	19441

    Enter your credentials,

    Click image for larger version. 

Name:	Input.png 
Views:	0 
Size:	23.4 KB 
ID:	19442

    then click `Save`.

    Click image for larger version. 

Name:	Save.png 
Views:	0 
Size:	27.3 KB 
ID:	19443

    The WiFi and Custom Credentials will be saved and the board connect to the selected WiFi AP.

    If you're already connected to a listed WiFi AP and don't want to change anything, just select Exit from the Main page to reboot the board and connect to the previously-stored AP. The WiFi Credentials are still intact.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •