Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Can’t load defaults #15

Closed
ghost opened this issue Jun 24, 2020 · 18 comments
Closed

Can’t load defaults #15

ghost opened this issue Jun 24, 2020 · 18 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Jun 24, 2020

Firstly thank you for such an awesome project.

I’m using the template sketch, and I set the load default config flag to true but I can’t seem to get it to work. No matter what I put in for the default data it doesn’t load it into the config portal. I tried eeprom clear hoping that would help and did double reset but also that didn’t work. What am I doing wrong?

@khoih-prog
Copy link
Owner

You need to explain more clearly, with pictures, debug terminal outputs. It's difficult to guess what you're doing and where you're doing not correctly.

@thorathome is the author of the Blynk_WM_Template example. Please help.

@ghost
Copy link
Author

ghost commented Jun 25, 2020

Ok. I didn't ask my question correctly my apologies.

I'm using the Blynk WM Template example script that comes with the library in Arduino IDE. The portion of it that I can't figure out is this:

///////////////////////////////////////////////////////////////////////////////////////////
//// COMPILER SWITCH SELECTION - USE DEFAULT CONFIG PORTAL FIELD DATA OR NOT //////////////
//// SELECT IF YOU WANT CONFIG PORTAL FIELDS INITIALIZED TO SOMETHING OTHER THAN BLANK ////
//// This data only gets loaded on an initial compile and upload and after Config Portal data gets deleted
//// such as by using DRD (Double Reset) or the Blynk command Blynk.clearConfigData()
#define USE_DEFAULT_CONFIG_DATA true
//#define USE_DEFAULT_CONFIG_DATA false

I want to input into the code defaults like the Blynk Server, Blynk Server Port, Board Name, but no matter what I specify in the code like this it doesn't show up on the configuration portal fields. I've tried double reset, blynk.clearconfigdata(), recompiling, clearing eeprom, none of it works:

http://gut.bz/IMG_0275[2145].PNG

  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER SWITCH SELECTIONS - SET UP TO TWO SSIDs & TWO passwords /////////////////////
  //WiFi_Credentials  WiFi_Creds  [NUM_WIFI_CREDENTIALS]
  //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw
  "thisismywifi",  "thisismywifipassword",              // Config Portal WiFi SSID & PWD field values
  "thisismywifi2", "thisismywifipasswordalso",             // Config Portal WiFi SSID1 & PWD1 field values

  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER SWITCH SELECTIONS - SET UP TO TWO BLYNK SERVERS & TWO AUTH CODES ////////////
  // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
  // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token
  "my-blynk-server.com", "token",    // Config Portal Blynk Server & Token field values
  "blynkwm.local", "token",  // Config Portal Blynk Server1 & Token1 field values

  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER SWITCH SELECTIONS - SET DEFAULT PORTS (FOR SSL OR NON-SSL) //////////////////
  //int  blynk_port;
  #if USE_SSL
    9443,                           // Config Portal Port field (default SSL port) value
  #else
    8016,                           // Config Portal Port field (default non-SSL) value
  #endif

@khoih-prog
Copy link
Owner

@kevinleberge

Are you using ESP8266 or ESP32, and EEPROM/SPIFFS or LittleFS?

@ghost
Copy link
Author

ghost commented Jun 25, 2020 via email

@khoih-prog
Copy link
Owner

@kevinleberge

Please try New Blynk_WM v1.0.16 which fixes the USE_DEFAULT_CONFIG_DATA issue and let us know if it's OK.

@khoih-prog khoih-prog added the bug Something isn't working label Jun 26, 2020
@ghost
Copy link
Author

ghost commented Jun 26, 2020

Default settings are loading into the config portal now! Great.

However, it doesn't seem to program settings from portal onto device now. it shows in serial monitor that it's loading default values, not the values submitted on configuration portal.

image

02:20:00.238 -> 
02:20:00.238 -> 
02:20:00.238 -> =======================================
02:20:00.238 -> Blynk_WM_Template
02:20:00.238 -> 
02:20:00.238 -> Setting up WLAN and Blynk WITH WiFiManager
02:20:00.238 -> Starting Blynk.begin (with WM)
02:20:00.238 -> Blynk.setConfigPortal(IOTDevice,configpass)
02:20:00.238 ->   Config Portal will be found at IP: 1.2.3.1
02:20:00.238 -> 
02:20:00.285 -> [632] ======= Start Default Config Data =======  
02:20:00.332 -> [632] Hdr=NonSSL,BrdName=IOTDevice
02:20:00.332 -> [632] SSID=SSID1,PW=password1
02:20:00.332 -> [632] SSID1=SSID2,PW1=password2
02:20:00.332 -> [634] Server=blynk-cloud.com,Token=token1
02:20:00.332 -> [638] Server1=,Token1=
02:20:00.332 -> [640] Port=80
02:20:00.332 -> [641] ======= End Config Data =======
02:20:00.332 -> [645] Hostname=IOTDevice
02:20:00.332 -> [677] SaveCfgFile 
02:20:00.332 -> [677] WCSum=0x1a13
02:20:00.426 -> [772] OK
02:20:00.472 -> [788] SaveBkUpCfgFile 
02:20:00.519 -> [863] OK
02:20:00.566 -> [879] SaveCredFile 
02:20:00.566 -> [879] CW1:pdata=2,len=5
02:20:00.566 -> [880] CW1:pdata=Select a color,len=18
02:20:00.566 -> [880] CW1:pdata=3,len=5
02:20:00.566 -> [880] CW1:pdata=My Beating Heart,len=26
02:20:00.566 -> [881] CW1:pdata=4,len=5
02:20:00.566 -> [883] CW1:pdata=HEX Color Value,len=26
02:20:00.660 -> [966] OK
02:20:00.660 -> [966] CrWCSum=0x108e
02:20:00.660 -> [983] SaveBkUpCredFile 
02:20:00.660 -> [983] CW2:pdata=2,len=5
02:20:00.660 -> [983] CW2:pdata=Select a color,len=18
02:20:00.660 -> [983] CW2:pdata=3,len=5
02:20:00.660 -> [983] CW2:pdata=My Beating Heart,len=26
02:20:00.660 -> [985] CW2:pdata=4,len=5
02:20:00.660 -> [987] CW2:pdata=HEX Color Value,len=26
02:20:00.722 -> [1072] OK
02:20:00.722 -> [1072] ======= Start Loaded Config Data =======
02:20:00.754 -> [1072] Hdr=ESP8266,BrdName=IOTDevice
02:20:00.754 -> [1072] **SSID=SSID1,PW=password1**
02:20:00.754 -> [1073] **SSID1=SSID2,PW1=password2**
02:20:00.754 -> [1076] Server=blynk-cloud.com,Token=**token1**
02:20:00.754 -> [1079] Server1=,Token1=
02:20:00.754 -> [1082] Port=80
02:20:00.754 -> [1083] ======= End Config Data =======
02:20:00.754 -> [1087] bg: noConfigPortal = true
02:20:00.754 -> [1090] Connecting MultiWifi...
02:20:34.189 -> [34502] WiFi not connected
02:20:34.189 -> [34502] bg: Fail2connect WiFi+Blynk
02:20:34.330 -> [34669] 
02:20:34.330 -> stConf:SSID=IOTDevice: Air,PW=configpass
02:20:34.330 -> [34670] IP=1.2.3.1,ch=1
02:20:34.470 -> Blynk NOT CONNECTED 
02:20:34.470 -> 
02:20:34.470 -> 
02:20:34.470 -> Setting up Blynk timers
02:20:34.470 -> ... Blynk timers set up.
02:20:34.470 -> ... heartbeat of Blynk_WM_Template WiFi.status() = 6
02:20:34.470 -> Setup complete 
02:20:34.470 -> 
02:20:35.207 ->  ...

@khoih-prog
Copy link
Owner

The USE_DEFAULT_CONFIG_DATA has higher priority than Config Portal and it's designed for developers to test.
You have to turn that feature off in normal operation and Config Portal input data will take over.

//#define USE_DEFAULT_CONFIG_DATA true
#define USE_DEFAULT_CONFIG_DATA false

@thorathome
Copy link
Contributor

Hi @khoih-prog

Thank you for the continued library development. I am building household control and monitoring apps with your library.

I am recompiling the Template sketch with the new library. Same code. (I did add a Blynk.clearConfigData() call to void setup().)
Same Default Config Data.
Having difficulty connecting with SSL

Any quick thoughts as I dig into this?
I do have new routers - Amazon Eero, but all my existing Blynk devices are working fine so far.

Thanks again and in advance.
Thor

THE CODE YOU KNOW

/*  
 * The Arduino/Blynk sketch Blynk_WiFiMgr_ESP32_8266_Template_HexColor.ino is a fully-developed 
 * get-started demo program for the powerful BlynkSimpleEsp... and the newer WiFiManager (WM) libraries. 
 * This demo sketch written by Thor Johnson (https://github.com/thorathome) May 2020 as a template for
 * Blynk Wifi ESP communications. See https://github.com/thorathome/Blynk_Examples
 * 
 * It demonstrates
 * * WiFiManager Config Portal configuration and use
 * * WiFiManager Dynamic (extended) Parameters configuration and use
 * * Use of compiler constants for compile-time selection
 * * Use of Blynk's BLYNK_WRITE_DEFAULT() flexible capability
 * * EEPROM and LittleFS (file system to replace depricated SPIFFS)
 *
 * This sketch lets end-users choose a color using ZeRGBa, colors a blinking (heartbeat) LED, 
 * and shows the HEX code for that color.
 *
 * This sketch requires:
 * * Blynk ZeRGBa configured in MERGE mode with values between 0 and 255
 * * Blynk LED
 * * Blynk Value Display
 * * Blynk master library installed
 * * Blynk_WiFiManager library installed
 * * ESP32 or ESP8266 device
 *
 * As in all Blynk sketches using WiFi, you will need
 * * Your WiFi SSID or SSIDs and passwords (I put mine in my library as a .h file)
 * * Your Blynk authcode or authcodes (I put mine in my library as a .h file)
 * * Your Blynk server URL (Main US Blyk server is blynk-cloud.com.)
 *
 * These values do not need to be coded into the sketch as they may be entered at runtime (once) 
 * into the Config Portal.
 *
 * You also do not have to hardcode the Virtual Pins for the ZeRGBa, LED or Value Display, 
 * can input them at runtime using the Config Portal. 
 * This sketch uses Blynk's BLYNK_WRITE_DEFAULT() capability to deliver this flexibility. 
 * I use this approach to manage a number of similar wireless controls like SONOFFs.
 *
 * The Config Portal will appear as SSID MyConfigPortal, with WiFi password of 12345678 
 * and IP address of 192,168,220,1. 
 * These three values (Config Portal SSID, password, IP address) are hardcoded into the sketch 
 * (but could be made selectable in the Config Portal, itself.)
 *
 * I hope this is as useful to you as it has been to me to understand Blynk, 
 * the BlynkSimpleEsp... and ...WiFiManager libraries, the ESP32 and ESP8266.
 */

#define SERIAL_SPEED 230400
#define SKETCH_NAME "Blynk_WM_Template"

#define BLYNK_PRINT Serial  // Generates Blynk debug prints. Comment out if not needed, saving space
#define BLYNK_WM_DEBUG    0 // Can be 0-3 (3 = detailed)

// These two .h files are in my libraries folder and contain my personal SSID, WiFi passowrd and Blynk authcodes
#include "MY_WIFI_CREDENTIALS.h"   // #defines MY_WIFI_SSID AND MY_WIFI_PASSWORD
#include "MY_BLYNK_CREDENTIALS.h"  // #defines MY_BLYNK_SERVER and MY_xxx_AUTHCODEs
// Each Blynk authcode has a unique name in the MY_BLYNK_CREDENTIALS.h file. 
#define MY_BLYNK_AUTHCODE MY_WM_TEMPLATE_AUTHCODE   // My authcode for development and testing new capabilities


///////////////////////////////////////////////////////////////////////////////////////////
//// COMPILER SWITCH SELECTION - USE WIFI MANAGER OR NOT //////////////////////////////////
#define USE_WM true   // to easily select WiFi Manager or not
//#define USE_WM false   // to easily select WiFi Manager or not
// REMEMBER: not using _WM means we make our own initial WiFi connection


///////////////////////////////////////////////////////////////////////////////////////////
//// COMPILER SWITCH SELECTION - USE SSL OR NOT ///////////////////////////////////////////
#define USE_SSL true // to easily select SSL or not
//#define USE_SSL false // to easily select SSL or not


///////////////////////////////////////////////////////////////////////////////////////////
//// COMPILER VALUE SELECTION - VIRTUAL PINS FOR THE 3 WIDGETS ////////////////////////////
#define CONTROL_DEFAULT_VPIN       "2"  // Can also be changed via Config Portal (USE_DYNAMIC_PARAMETERS)
#define HEARTBEAT_LED_DEFAULT_VPIN "3"  // Can also be changed via Config Portal (USE_DYNAMIC_PARAMETERS)
#define DISPLAY_DEFAULT_VPIN       "4"  // Can also be changed via Config Portal (USE_DYNAMIC_PARAMETERS)
// These can all be reset using Config Portal. I have included them as default values only. */ 


#if USE_WM
  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER SWITCH SELECTION - USE DEFAULT CONFIG PORTAL FIELD DATA OR NOT //////////////
  //// SELECT IF YOU WANT CONFIG PORTAL FIELDS INITIALIZED TO SOMETHING OTHER THAN BLANK ////
  //// This data only gets loaded on an initial compile and upload and after Config Portal data gets deleted
  //// such as by using DRD (Double Reset) or the Blynk command Blynk.clearConfigData()
  #define USE_DEFAULT_CONFIG_DATA true
  //#define USE_DEFAULT_CONFIG_DATA false

  // When developing and debugging the WM Config Portal, I use this to FORCE the Config Portal to appear
  //  and to appear with the DEFAULT_CONFIG_DATA.  
  // Once my code does what I want, I generally set CLEAR_CONFIG_DATA to false
  // This lets the Config Portal behave normally
  //#define CLEAR_CONFIG_DATA true  // DEBUGGING TOOL!  This deletes the device's existing Config Portal data in setup() 
                                  //    will force Config Portal up with DEFAULT_CONFIG_DATA [see code in void setup()]
  #define CLEAR_CONFIG_DATA false // USE THIS FOR NORMAL OPERATION - use existing Config Portal Data as normal (provides continuity)
                                



  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER SWITCH SELECTION - USE DYNAMIC (CUSTOM) CONFIG PORTAL FIELDS OR NOT /////////
  #define USE_DYNAMIC_PARAMETERS true
  //#define USE_DYNAMIC_PARAMETERS false

  
  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER SWITCH SELECTION - USE LITTLEFS (ESP8266 ONLY), SPIFFS OR EEPROM /////////////////////////////////////
  //// only relevant if using WiFiManager _WM
  
  #ifdef ESP8266
    // #define USE_SPIFFS and USE_LITTLEFS   false        => using EEPROM for configuration data in WiFiManager
    // #define USE_LITTLEFS    true                       => using LITTLEFS for configuration data in WiFiManager
    // #define USE_LITTLEFS    false and USE_SPIFFS true  => using SPIFFS for configuration data in WiFiManager
    // Be sure to define USE_LITTLEFS and USE_SPIFFS before #include <BlynkSimpleEsp8266_WM.h>
    // From ESP8266 core 2.7.1, SPIFFS will be deprecated and to be replaced by LittleFS
    // Select USE_LITTLEFS (higher priority) or USE_SPIFFS
  
    #define USE_LITTLEFS                true
    //#define USE_LITTLEFS                false

    #define USE_SPIFFS false  // Choosing EEPROM over LittleFS / SPIFFS here
    //#define USE_SPIFFS true   
    
    #if USE_LITTLEFS
      //LittleFS has higher priority
      #ifdef USE_SPIFFS
        #undef USE_SPIFFS
      #endif
      #define USE_SPIFFS                  false
      #warning Use LittleFS for ESP8266
    #elif USE_SPIFFS
      //#define USE_SPIFFS false  // ESP8266, Choosing EEPROM over LittleFS / SPIFFS here
      #define USE_SPIFFS true
      #warning Using SPIFFS for ESP8266
    #else
      #warning Using EEPROM for ESP8266
    #endif  
  #else
    //#define USE_SPIFFS false  // ESP32, Choosing EEPROM over LittleFS / SPIFFS here
    #define USE_SPIFFS true
    #if USE_SPIFFS
      #warning Using SPIFFS for ESP32
    #else
      #warning Using EEPROM for ESP32
    #endif
  #endif

  #if USE_LITTLEFS
    #define CurrentFileFS     "LittleFS"
  #elif USE_SPIFFS
    #define CurrentFileFS     "SPIFFS"
  #endif  

  // COMPILE-TIME LOGIC: NON-VOLATILE MEMORY SELECTION (WiFiManager only) 
  // NOT NECESSARY TO MODIFY
  #if !( USE_LITTLEFS || USE_SPIFFS)
    // EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes)
    #define EEPROM_SIZE    (2 * 1024)
    // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE
    #define EEPROM_START   512
  #endif


  // NOT NECESSARY TO MODIFY - MUST BE INCLUDED
  // Force some params in Blynk, only valid for library version 1.0.1 and later
  // (from the Github doc)
  #define TIMEOUT_RECONNECT_WIFI                    10000L
  #define RESET_IF_CONFIG_TIMEOUT                   true
  #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET    3  // Library default is 10 (times 2) - DEBUG SET AT 2

  // NOT NECESSARY TO MODIFY
  // COMPILE-TIME LOGIC: AUTOMATIC LIBRARY SELECTION 
  #if USE_SSL
    #if ESP8266
      #include <BlynkSimpleEsp8266_SSL_WM.h>
    #endif
    #if ESP32
      #include <BlynkSimpleEsp32_SSL_WM.h> 
    #endif
  #else // no SSL
    #if ESP8266
      #include <BlynkSimpleEsp8266_WM.h>
    #endif
    #if ESP32
      #include <BlynkSimpleEsp32_WM.h>
    #endif
  #endif

// NOT NECESSARY TO MODIFY
#else // not using WiFiManager
  #if USE_SSL
    #if ESP8266
      #include <BlynkSimpleEsp8266_SSL.h>
    #endif
    #if ESP32
      #include <BlynkSimpleEsp32_SSL.h>
    #endif
  #else // no SSL
    #if ESP8266
      #include <BlynkSimpleEsp8266.h>
    #endif
    #if ESP32
      #include <BlynkSimpleEsp32.h>
    #endif
  #endif
#endif


#if USE_WM
  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER VALUE SELECTION - CONFIG PORTAL'S OWN SSID AND password /////////////////////
  //// Config Portal turns on when WiFiManager cannot connect to WiFi or Blynk
  //// only relevant if using WiFiManager _WM
  #define CONFIG_PORTAL_SSID "Config_WiFiManager_Template"   // SSID for device-generated WiFi beacon
  #define CONFIG_PORTAL_PASSWORD "12345678"     // password for device-generated WiFi beacon - 8+ characters
  #define CONFIG_PORTAL_IPADDRESS 192,168,220,1 // IP address of Config Portal once connected to WiFi beacon
  #define DEVICE_HOST_NAME "WiFiManager_Template"  // DHCP Host name for device


  #if USE_DEFAULT_CONFIG_DATA // Set default values for "standard" fields presented in Config Portal
    bool LOAD_DEFAULT_CONFIG_DATA = true;  //do not modify - used by library
    
    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER SWITCH SELECTIONS - SET DEFAULT VALUES PRESENTED IN CONFIG PORTAL ///////////////
    //// Data structure AND default values for "standard" fields presented in Config Portal
    Blynk_WM_Configuration defaultConfig =
    {
      // NOT NECESSARY TO MODIFY
      //char header[16], dummy, not used
      #if USE_SSL  
        "SSL",
      #else
        "NonSSL",
      #endif

      ///////////////////////////////////////////////////////////////////////////////////////////
      //// COMPILER SWITCH SELECTIONS - SET UP TO TWO SSIDs & TWO passwords /////////////////////
      //WiFi_Credentials  WiFi_Creds  [NUM_WIFI_CREDENTIALS]
      //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw
      MY_WIFI_SSID,  MY_WIFI_PASSWORD,  // Config Portal WiFi SSID & PWD field values
      "SSID1", "password1",             // Config Portal WiFi SSID1 & PWD1 field values
    
      ///////////////////////////////////////////////////////////////////////////////////////////
      //// COMPILER SWITCH SELECTIONS - SET UP TO TWO BLYNK SERVERS & TWO AUTH CODES ////////////
      // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
      // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token
      "account.bogus.org", "token1",    // Config Portal Blynk Server & Token field values
      MY_BLYNK_SERVER, MY_BLYNK_AUTHCODE, //Config Portal Blynk Server1 & Token1 field values
      
      ///////////////////////////////////////////////////////////////////////////////////////////
      //// COMPILER SWITCH SELECTIONS - SET DEFAULT PORTS (FOR SSL OR NON-SSL) //////////////////
      //int  blynk_port;
      #if USE_SSL
        9443,                           // Config Portal Port field (default SSL port) value
      #else
        8080,                           // Config Portal Port field (default non-SSL) value
      #endif
    
      ///////////////////////////////////////////////////////////////////////////////////////////
      //// COMPILER SWITCH SELECTIONS - SET DEFAULT BOARD NAME //////////////////////////////////
      //char board_name     [24];
      "WiFiManager",                    // Config Portal Board Name field value
    
      // terminate the list
      //int  checkSum, dummy, not used
      0
      /////////// End Default Config Data /////////////
    };
   
  #else // not using USE_DEFAULT_CONFIG_DATA 
    // Set up the "standard" Config Portal fields
    bool LOAD_DEFAULT_CONFIG_DATA = false;
    
    // AUTOMATICALLY GENERATE THE "STANDARD"CONFIG PORTAL DATA STRUCTURE
    // NOT NECESSARY TO MODIFY
    Blynk_WM_Configuration defaultConfig;  // loads t4he default confir portal data type with blacnk defaults  
  #endif

  
  #if USE_DYNAMIC_PARAMETERS
    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET UP DYNAMIC PARAMETER DATA TYPES & INITIAL VALUES //////
    //Defined in <BlynkSimpleEsp8266_WM.h> and <BlynkSimpleEsp8266_SSL_WM.h>   
    /**************************************
    #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;
    ************************************* */    
    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET UP FIELD LENGTHS AND DEFAULT VALUES FOR EACH DYNAMIC PARAMETER
    #define CONTROL_VPIN_LENGTH 5 // First DYNAMIC_PARAMETER (ZeRGBa Virtual Pin)
    char controlVpinC [ CONTROL_VPIN_LENGTH + 1 ] = CONTROL_DEFAULT_VPIN;

    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET UP FIELD LENGTHS AND DEFAULT VALUES FOR EACH DYNAMIC PARAMETER
    #define CONTROL_LABEL_LENGTH 18 // Second DYNAMIC_PARAMETER (Widget Label for ZeRGBa) 
    char controlLabel [ CONTROL_LABEL_LENGTH + 1 ] = "Select a color";

    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET UP FIELD LENGTHS AND DEFAULT VALUES FOR EACH DYNAMIC PARAMETER
    #define HEARTBEAT_LED_VPIN_LENGTH 5 // Third DYNAMIC_PARAMETER (Heartbeat LED Virtual Pin)
    char heartbeatVpinC [ HEARTBEAT_LED_VPIN_LENGTH + 1 ] = HEARTBEAT_LED_DEFAULT_VPIN;  

    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET UP FIELD LENGTHS AND DEFAULT VALUES FOR EACH DYNAMIC PARAMETER
    #define HEARTBEAT_LED_LABEL_LENGTH 26 // Fourth DYNAMIC_PARAMETER (Widget Label for Heartbeat LED)
    char heartbeatLabel [ HEARTBEAT_LED_LABEL_LENGTH + 1 ] = "My Beating Heartx";  

    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET UP FIELD LENGTHS AND DEFAULT VALUES FOR EACH DYNAMIC PARAMETER
    #define DISPLAY_VPIN_LENGTH 5 // Fifth DYNAMIC_PARAMETER (Hex Color Value Display Virtual Pin)
    char displayVpinC [ DISPLAY_VPIN_LENGTH + 1 ] = DISPLAY_DEFAULT_VPIN;  

    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET UP FIELD LENGTHS AND DEFAULT VALUES FOR EACH DYNAMIC PARAMETER
    #define DISPLAY_LABEL_LENGTH 26 // Sixth DYNAMIC_PARAMETER (Widget Label for Hex color display)
    char displayLabel [ DISPLAY_LABEL_LENGTH + 1 ] = "HEX Color Value";  


    ///////////////////////////////////////////////////////////////////////////////////////////
    //// COMPILER VALUE SELECTION - SET THE LABELS SHOWN IN CONFIG PORTAL FOR EACH DYNAMIC VARIABLE
    //// MAKE SURE YOUR DYNAMIC_PARAMETERS MATCH THIS STRUCTURE ////    
    MenuItem myMenuItems [] =
    { // 1234    123456789012345
      { "cvpn", "ZeRGBa VPin (#)", controlVpinC,    CONTROL_VPIN_LENGTH },
      { "clab", "ZeRGBa Label",    controlLabel,    CONTROL_LABEL_LENGTH },
      { "hvpn", "Hbeat VPin (#)",  heartbeatVpinC,  HEARTBEAT_LED_VPIN_LENGTH },
      { "hlab", "Hbeat Label",     heartbeatLabel,  HEARTBEAT_LED_LABEL_LENGTH },
      { "dvpn", "Hex VPin (#)",    displayVpinC,    DISPLAY_VPIN_LENGTH },
      { "dlab", "Hex Label",       displayLabel,    DISPLAY_LABEL_LENGTH },
    };

    // Automatically calculate the # of DYNAMIC PARAMETERS menu items - DO NOT TOUCH
    uint16_t NUM_MENU_ITEMS = sizeof ( myMenuItems ) / sizeof ( MenuItem );  //MenuItemSize;

  #else // not using USE_DYNAMIC_PARAMETERS - SET UP NULL (DYNAMIC) MENU
    // NOT NECESSARY TO MODIFY
    MenuItem myMenuItems [] = {};
    uint16_t NUM_MENU_ITEMS = 0;
  #endif // end USE_DYNAMIC_PARAMETERS    

#else // NOT USING WIFI MANAGER - SET STANDARD WIFI & BLYNK CREDENTIALS, VIRTUAL PIN CHAR VARIABLES
  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER VALUE SELECTION - STANDARD WIFI CREDENTIALS /////////////////////////////////
  //// Will be used in standard WiFi/begin() and Blynk.config() commands below //////////////
  char WiFiSSID[] = MY_WIFI_SSID;  // network SSID (name)
  char WiFiPass[] = MY_WIFI_PASSWORD;  // network password

  ///////////////////////////////////////////////////////////////////////////////////////////
  //// COMPILER VALUE SELECTION - BLYNK AUTH /////////////////////////////////
  //// Will be used in standard WiFi/begin() and Blynk.config() commands below //////////////
  char blynkAuth[] = "<my_auth>"; // BLYNK Auth 

  // Will be converted to int values in Setup
  char controlVpinC[] =   CONTROL_DEFAULT_VPIN;
  char heartbeatVpinC[] = HEARTBEAT_LED_DEFAULT_VPIN;
  char displayVpinC[] =   DISPLAY_DEFAULT_VPIN;
#endif


// Integer versions of our three Virtual Pins - values loaded in Setup
int controlVpin;   // = CONTROL_DEFAULT_VPIN or set in Config Portam (WM)
int heartbeatVpin; // = HEARTBEAT_LED_DEFAULT_VPIN or set in Config Portam (WM)
int displayVpin;   // = DISPLAY_DEFAULT_VPIN or set in Config Portam (WM)



// THIS SKETCH SETS UP A HEARTBEAT LED ON A TIMER TO SHOW SYSTEM IS ALIVE AND WELL
BlynkTimer myTimer;
// Blynk timers to blink a heartbeat LED on and off
int heartbeatLEDinterval = 3000; // interval between heartbeats for onboard and Blynk Virtual LED in millisec 
int heartbeatLEDtimerID; 

int heartbeatLEDduration = 750; // duraction of each blink in millisec (set as an interval timer)
int heartbeatLEDdurationTimerID;
bool heartbeatLEDon = false; // this lets me use the same routine for the turn-on timer and the turn-off interval


#include "ESP_LED_BUILTINS.h"  // Corrects for Arduino ESP8266 quirk inverting LED_BUILTIN - (#included code below)
/* Here's the code in ESP_LED_BUILTINS
#ifdef ESP32
  #define LED_BUILTIN 13  // NOT DEFINED IN ESP32 BOARD FILES - HMMM.  
#endif

#ifdef ESP8266  // There's a quirk in ESP8266 Arduino that has the LED_BUILTIN inverted. This corrects for it.
  #define LED_BUILTIN_HIGH LOW
  #define LED_BUILTIN_LOW HIGH
#else
  #define LED_BUILTIN_HIGH HIGH
  #define LED_BUILTIN_LOW LOW
#endif
*/





// SETUP WIFI, BLYNK, HEARTBEAT
 void setup() 
{
  // HELP DEBUG THIS SKETCH WITH GOOD PRINTOUTS
  Serial.begin ( SERIAL_SPEED );
  delay ( 500 );  
  Serial.println ( "\n\n=======================================" );
  Serial.print ( SKETCH_NAME ); 
  #if USE_SSL
    Serial.print ( " ** Using SSL **" );  
  #endif
  Serial.println();

  #if CLEAR_CONFIG_DATA // Use this during development when you want to FORCE the Config Portal to appear
    Blynk.clearConfigData();  // and to appear with teh DEFAULT_CONFIG_DATA
  #endif
  
  connectToWLANandBlynk();  // Connect to WiFi, then to Blynk server

  setupBlynkTimers();  // Establish Blynk timers after Blynk is connected

  // Initialize Onboard LED 
  pinMode ( LED_BUILTIN, OUTPUT );  
  digitalWrite ( LED_BUILTIN, LED_BUILTIN_LOW ); 
    
  // Set Blynk Virtual Heartbeat LED OFF
  Blynk.virtualWrite ( heartbeatVpin, 000 );  
  heartbeatLEDblink(); // start first heartbeat 
  
  Serial.println ( "\nSetup complete \n" );    
  
} //end setup





// KEEPING IT SIMPLE
void loop()
{
  Blynk.run();
  myTimer.run();  
  
} // end loop





// CONNECT TO WLAN WITH OR WITHOUT WM
// Connect to Blynk once WiFi connection establishked
// Uses compiler switches for WiFiManager, SSL, other choices
void connectToWLANandBlynk()
{
  // Setup WLAN and Blynk
  Serial.print ( "\nSetting up WLAN and Blynk " );  
  #if USE_WM
    Serial.println ( "WITH WiFiManager" ); 
  #else
    Serial.println ( "WITHOUT WiFiManager" );  
  #endif
  
  #if USE_WM
    Serial.println ( "Starting Blynk.begin (with WM)" );  

    // SET UP THE CONFIG PORTAL CREDENTIALS AND CONNECTION INFO
    Blynk.setConfigPortalChannel ( 0 );  // 0 -> Use a random WiFi 2.4GHz channel for the Config Portal
    Blynk.setConfigPortal ( CONFIG_PORTAL_SSID, CONFIG_PORTAL_PASSWORD ); // Set up Config Portal SSID & Password
    Blynk.setConfigPortalIP ( IPAddress ( CONFIG_PORTAL_IPADDRESS ) ); // Set up IP address for COnfig Portal once connected to WiFi

    Serial.print ( "Blynk.setConfigPortal(" ); 
    Serial.print ( CONFIG_PORTAL_SSID ); Serial.print ( "," );  
    Serial.print ( CONFIG_PORTAL_PASSWORD ); Serial.println ( ")" );   
    Serial.print ( "  Config Portal will be found at IP: " ); Serial.print ( IPAddress ( CONFIG_PORTAL_IPADDRESS ) );  
    Serial.println ( "\n" );  
    
    //Blynk.config ( blynkAuth );  // not needed with WM 
    Blynk.begin ( DEVICE_HOST_NAME ); // DHCP (router) device name
  
  #else//NOT using WM
    Serial.println ( "Starting WiFi.begin (no WM)" );  
    WiFi.begin ( WiFiSSID, WiFiPass );
    Serial.println ( "... waiting a few seconds for WiFi ..." );    
    #if ESP8266
      delay ( 7500 );  // For esp8266, it needs a delay to realize it has connected
    #endif
      
    // REBOOT if we do not have a good WiFi connection
    if ( WiFi.status() != WL_CONNECTED )
    {
      Serial.println ( "Resetting in a few seconds...\n\n\n\n\n" );
      delay ( 3000 );  
      ESP.restart();
    } 
    
    // Configure and launch Blynk
    Blynk.config ( blynkAuth );
    Blynk.connect ( 2500 ); // Don't get stuck hanging for more than 2500 millis.
  #endif // using WM
  
  if ( Blynk.connected() ) 
  {
    #if ( USE_LITTLEFS || USE_SPIFFS)
      Serial.println("\nBlynk using " + String(CurrentFileFS) + " connected. Board Name : " + Blynk.getBoardName());
    #else
      Serial.println("\nBlynk using EEPROM connected. Board Name : " + Blynk.getBoardName());
      Serial.printf("EEPROM size = %d bytes, EEPROM start address = %d / 0x%X\n", EEPROM_SIZE, EEPROM_START, EEPROM_START);
    #endif  
        
    Serial.println ( "Blynk connected just fine" ); 
    Serial.print   ( "  IP address  " ); Serial.println ( WiFi.localIP() ) ;
    Serial.print   ( "  MAC address " ); Serial.println ( WiFi.macAddress() );  
    Serial.println();  
  }
  else Serial.println ( "Blynk NOT CONNECTED \n\n" );  
} // end connectToWLANandBlynk





// SET UP BLYNK TIMER FOR HEARTBEAT (and anything eles you may want later)
void setupBlynkTimers()
{
  Serial.println ( "Setting up Blynk timers" );  
  // Interval timer for heartbeatLED (Blynk LED and onboard LED
  heartbeatLEDtimerID = myTimer.setInterval ( heartbeatLEDinterval, heartbeatLEDblink );  

  Serial.println ( "... Blynk timers set up." );  
  
} //end setupBlynkTimers





// LED HEARTBEAT
void heartbeatLEDblink()
/* Blink the on-board LED AND the Virtual Blynk LED
 * If LED is off, it turne the LEDs on, then sets a timer to turn LED off
 * When the timer triggers, same routine turns the LEDs off
 */
{
  if ( heartbeatLEDon ) // if LED is on, turn it off and vice cersa
  {
    //heartbeatLED.off(); // Blynk Virtual LED
    
    digitalWrite ( LED_BUILTIN, LED_BUILTIN_LOW ); // On-board LED
    Blynk.virtualWrite ( heartbeatVpin, 000 );  
    Serial.println ( " ..." );
  } else
  {
    //heartbeatLED.on();      // Blynk Virtual LED
    
    digitalWrite ( LED_BUILTIN, LED_BUILTIN_HIGH );  // On-board LED
    Blynk.virtualWrite ( heartbeatVpin, 255 );  
    // Set the timer to turn off the LEDs in a bit  
    heartbeatLEDdurationTimerID = myTimer.setTimeout ( heartbeatLEDduration, heartbeatLEDblink ); 
    
    Serial.print ( "... heartbeat of " ); Serial.print ( SKETCH_NAME ); 
    Serial.print ( " WiFi.status() = " ); Serial.print ( WiFi.status() );  
  }
  
  heartbeatLEDon = ! heartbeatLEDon; // flip status
} //end heartbeatLEDblink





// BLYNK_WRITE_DEFAULT GETS CALLED WHEN THERE IS NO SPECIFIC BLYNK_WRITE FOR THAT VIRTUAL PIN
// This makes it a flexible - and programmable - receiver
// The Config Portal can provide FLEXIBLE Virtual Pin to power this
BLYNK_WRITE_DEFAULT() 
{
  // THE VIRTUAL PIN THAT SENT THE MESSAGE TO BLYNK
  int writeVpin = request.pin; 
  
  Serial.print ( "\nRECEIVED BLYNK SIGNAL FROM V");
  Serial.print ( writeVpin );
  Serial.println ( ": " );
  
  // Print all parameter values
  for ( auto i = param.begin(); i < param.end(); ++i ) 
  {
    Serial.print ( "* param = " ); 
    Serial.println ( i.asString() );  
  }
  Serial.println ( "*****\n" );  

  if ( writeVpin == controlVpin ) // We have color input from ZeRGBa
  {
    // Get the colorfrom ZeRGBa, updatethe Heartbeat LED color and display
    int r = param[0].asInt();
    int g = param[1].asInt();
    int b = param[2].asInt();

    Serial.print ( "\n\nHORSE sent r, g, b (HEX) = " );
    Serial.print ( r, HEX ); Serial.print ( ", " );  
    Serial.print ( g, HEX ); Serial.print ( ", " );  
    Serial.print ( b, HEX ); Serial.println(); 

    String rS = String ( r, HEX ); if ( rS.length() < 2 ) rS = "0" + rS;  
    String gS = String ( g, HEX ); if ( gS.length() < 2 ) gS = "0" + gS;   
    String bS = String ( b, HEX ); if ( bS.length() < 2 ) bS = "0" + bS;  
    Serial.print ( "HEX = " );
    Serial.print ( rS ); Serial.print ( ", " );  
    Serial.print ( gS ); Serial.print ( ", " );  
    Serial.print ( bS ); Serial.println();  

    String rgbHEX = "#" + rS + gS + bS;
    Serial.print ( "Color = " ); Serial.println ( rgbHEX ); Serial.println();  

    // UPDATE THE HEARTBEAT LED COCLOR AND HEX DISPLAY
    Blynk.setProperty ( heartbeatVpin, "color", rgbHEX );  
    
    Blynk.setProperty ( displayVpin, "color", "#FFFFFF" );  
    Blynk.virtualWrite ( displayVpin, rgbHEX );  
  }
} //end BLYNK_WRITE_DEFAULT





#if USE_WM
// UPDATE DYNAMIC PARAMETERS 
//  1 - CONVERTS THE char INFO FROM THE CONFIG PORTAL OR COMPILER CONSTANTS TO THE int VALUES THEY NEED TO BE FOR USE IN A SKETCH
//  2 -   UPDATES BLYNK WITH OTHER DYNAMIC PARAMETERS (WIDGET LABELS) 
void updateDynamicParameters()
{

  Serial.print ( "\nupdateDynamicParameters has: \n   controlVpinC/label = """ ); Serial.print ( controlVpinC ); Serial.print ( """/" ); Serial.print ( controlLabel ); 
  Serial.print ( "\n   heartbeatVpinC/label = """ ); Serial.print ( heartbeatVpinC ); Serial.print ( """/" ); Serial.print ( heartbeatLabel ); 
  Serial.print ( "\n   displayVpinC/label = """ ); Serial.print ( displayVpinC ); Serial.print ( """/" ); Serial.print ( displayLabel ); 
  Serial.println ( "\n" );  
    
  // Convert char Virtual Pin numbers to int in preperation for Blynk connect
  controlVpin = atoi ( controlVpinC );
  if ( controlVpin < 0 || controlVpin > 255 )
  {
    controlVpin = atoi ( CONTROL_DEFAULT_VPIN );
    Serial.print ( "**** Bad controlVpin input value of " );
    Serial.println ( controlVpinC );
  };
  Serial.print ( "   Set controlVpin/controlLabel to " ) ; Serial.print ( controlVpin );
  Serial.print ( "/" ); Serial.println ( controlLabel );   
  Blynk.setProperty ( controlVpin, "label", controlLabel ); 

  heartbeatVpin = atoi ( heartbeatVpinC );
  if ( heartbeatVpin < 0 || heartbeatVpin > 255 )
  {
    heartbeatVpin = atoi ( HEARTBEAT_LED_DEFAULT_VPIN );
    Serial.print ( "**** Bad heartbeatVpin input value of " );
    Serial.println ( heartbeatVpinC );
  }
  Serial.print ( "   Set heartbeatVpin/heartbeatLabel to " ) ; Serial.print ( heartbeatVpin );
  Serial.print ( "/" ); Serial.println ( heartbeatLabel );   
  Blynk.setProperty ( heartbeatVpin, "label", heartbeatLabel );  
    
  displayVpin = atoi ( displayVpinC );
  if ( displayVpin < 0 || displayVpin > 255 )
  {
    displayVpin = atoi ( DISPLAY_DEFAULT_VPIN );
    Serial.print ( "**** Bad displayVpin input value of " );
    Serial.println ( displayVpinC );
  }
  Serial.print ( "   Set displayVpin/displayLabel to " ) ; Serial.print ( displayVpin );
  Serial.print ( "/" ); Serial.println ( displayLabel );   
  Blynk.setProperty ( displayVpin, "label", displayLabel );  
  Serial.println();  
  
} // end updateDynamicParameters
#endif // (updateDynamicParameters not needed if NOT USE_WM)




// BLYNK_CONNECTED GETS CALLED WHEN CONNECTING TO BLYNK SERVERS
// GETS CALLED IMMEDIATELY ON FIRST CONNECT TO BLYNK SERVER, TOO
BLYNK_CONNECTED()
{
  Serial.println ( "\nBLYNK_CONNECTED..." );  

  #if USE_WM
    // Convert the Config Portal (or compiler constant) Virtual Pin char values to Blynk-usable ints
    updateDynamicParameters();  
  #endif

} // end BLYNK_CONNECTED





// BLYNK_APP_CONNECTED GETS CALLED WHEN APP CONNECTS TO BLYNK SERVERS
// IT IS NOT SUPER RELIABLE !  
BLYNK_APP_CONNECTED()
{
  Serial.println ( "\nBLYNK_APP_CONNECTED..." );  

} // end BLYNK_APP_CONNECTED

DEBUG TRACE

=======================================
Blynk_WM_Template ** Using SSL **

Setting up WLAN and Blynk WITH WiFiManager
Starting Blynk.begin (with WM)
Blynk.setConfigPortal(Config_WiFiManager_Template,12345678)
  Config Portal will be found at IP: 192.168.220.1

[586] Hostname=WiFiManagerTemplate
[593] SaveCfgFile 
[593] WCSum=0x339a
[696] OK
[700] SaveBkUpCfgFile 
[798] OK
[802] SaveCredFile 
[897] OK
[897] CrWCSum=0x1106
[902] SaveBkUpCredFile 
[998] OK
[998] bg: Stay forever in config portal.DRD detected
[1313] 
stConf:SSID=Config_WiFiManager_Template,PW=12345678
[1314] IP=192.168.220.1,ch=2
Blynk NOT CONNECTED 


Setting up Blynk timers
... Blynk timers set up.
... heartbeat of Blynk_WM_Template WiFi.status() = 6
Setup complete 

 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...
... heartbeat of Blynk_WM_Template WiFi.status() = 6 ...

**< Here, I saved the Config Portal >**

[121398] h:UpdLittleFS:/wmssl_conf.dat
[121403] SaveCfgFile 
[121403] WCSum=0x339a
[121508] OK
[121516] SaveBkUpCfgFile 
[121613] OK
[121619] SaveCredFile 
[121713] OK
[121713] CrWCSum=0x1106
[121719] SaveBkUpCredFile 
[121816] OK
[121816] h:Rst

**< device rebooted >**

=======================================
Blynk_WM_Template ** Using SSL **

Setting up WLAN and Blynk WITH WiFiManager
Starting Blynk.begin (with WM)
Blynk.setConfigPortal(Config_WiFiManager_Template,12345678)
  Config Portal will be found at IP: 192.168.220.1

[699] Hostname=WiFiManagerTemplate
[711] SaveCfgFile 
[711] WCSum=0x339a
[819] OK
[825] SaveBkUpCfgFile 
[918] OK
[925] SaveCredFile 
[1021] OK
[1021] CrWCSum=0x1106
[1028] SaveBkUpCredFile 
[1120] OK
[1120] Connecting MultiWifi...
[8399] WiFi connected after time: 1
[8399] SSID: Serengeti, RSSI = -51
[8399] Channel: 1, IP address: 192.168.4.102
[8399] bg: WiFi OK. Try Blynk
[8400] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[9421] NTP time: Fri Jun 26 17:03:09 2020
[9421] Connecting to account.bogus.org:9443
[25053] NTP time: Fri Jun 26 17:03:25 2020
[25053] Connecting to account.bogus.org:9443
[40570] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[40585] NTP time: Fri Jun 26 17:03:41 2020
[40585] Connecting to blynk-cloud.com:9443
[45587] NTP time: Fri Jun 26 17:03:46 2020
[45587] Connecting to blynk-cloud.com:9443
[50587] NTP time: Fri Jun 26 17:03:51 2020
[50588] Connecting to blynk-cloud.com:9443
[55589] NTP time: Fri Jun 26 17:03:56 2020
[55589] Connecting to blynk-cloud.com:9443
[60583] Blynk not connected
[60583] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[60600] NTP time: Fri Jun 26 17:04:01 2020
[60600] Connecting to account.bogus.org:9443
[76531] NTP time: Fri Jun 26 17:04:17 2020
[76531] Connecting to account.bogus.org:9443
[92170] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[92188] NTP time: Fri Jun 26 17:04:32 2020
[92188] Connecting to blynk-cloud.com:9443
[97189] NTP time: Fri Jun 26 17:04:37 2020
[97190] Connecting to blynk-cloud.com:9443
[102191] NTP time: Fri Jun 26 17:04:42 2020
[102191] Connecting to blynk-cloud.com:9443
[107192] NTP time: Fri Jun 26 17:04:47 2020
[107192] Connecting to blynk-cloud.com:9443
[112184] Blynk not connected
[112184] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[112201] NTP time: Fri Jun 26 17:04:52 2020
[112201] Connecting to account.bogus.org:9443
[127847] NTP time: Fri Jun 26 17:05:08 2020
[127847] Connecting to account.bogus.org:9443
[143511] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

[143529] NTP time: Fri Jun 26 17:05:24 2020
[143529] Connecting to blynk-cloud.com:9443
[148530] NTP time: Fri Jun 26 17:05:29 2020
[148531] Connecting to blynk-cloud.com:9443
[153531] NTP time: Fri Jun 26 17:05:34 2020
[153532] Connecting to blynk-cloud.com:9443
[158532] NTP time: Fri Jun 26 17:05:39 2020
[158533] Connecting to blynk-cloud.com:9443
[163525] Blynk not connected

@khoih-prog
Copy link
Owner

@thorathome

Having difficulty connecting with SSL
Any quick thoughts as I dig into this?

I have no problem at all connecting SSL (to my local Blynk Server) using ESP8266/ESP32.

But check that we have modified the USE_DEFAULT_CONFIG_DATA feature

The USE_DEFAULT_CONFIG_DATA has higher priority than Config Portal and it's designed for developers to test.
You have to turn that feature off in normal operation and Config Portal input data will take over.

//#define USE_DEFAULT_CONFIG_DATA true
#define USE_DEFAULT_CONFIG_DATA false

It seems that you might have either wrong tokens (taken from Default Config in sketch).

If you turn on USE_DEFAULT_CONFIG_DATA, you have to use the correct SSID/PW and BlynkServer/Token in your sketch as the board will use them.

After the first boot with USE_DEFAULT_CONFIG_DATA is ON, default Config Data will be saved in LittleFS / SPIFFS / EEPROM. You can then turn OFF USE_DEFAULT_CONFIG_DATA and let the board using the Credentials from LittleFS / SPIFFS / EEPROM as well as whenever you update from Config Portal.

It's a little bit confusing now, but I think this what you're expecting. Hopefully you will rewrite the README to explain more clearly to users.

@khoih-prog
Copy link
Owner

@thorathome

 // This lets the Config Portal behave normally
  //#define CLEAR_CONFIG_DATA true  // DEBUGGING TOOL!  This deletes the device's existing Config Portal data in setup() 
                                    //    will force Config Portal up with DEFAULT_CONFIG_DATA [see code in void setup()]
  #define CLEAR_CONFIG_DATA false   // USE THIS FOR NORMAL OPERATION - use existing Config Portal Data as normal (provides continuity)

You don't need this feature now with new v1.0.16, necessary only if you're using v1.0.15
But good to have this option instead of using DRD.

@thorathome
Copy link
Contributor

Hi @khoih-prog

Thanks again for your time and patience. I made a #TrueNoobError with the new WM library loading. Forgot the certs file. Also had two copies of your library loaded up under Arduino IDE. My double bad. Fixed now for ESP8266&32.

All is Right With the World on a Friday.

I like your approach to LOAD_CONFIG_DATA, thanks. Easier to explain = primarily for development and debugging.

I've been saving up a few questions about using the WM Library

  • What is BOARD_NAME used for? It does not appear to be anywhere in the Config Portal data structure. Do we care? (I like DEVICE_HOST_NAME – shows up in the Config Portal and my router directory.)

  • How can I adjust the Config Portal to show only 1 SSID/Passwd or 1 Blynk server/authcode
    (Where do I set [NUM_BLYNK_CREDENTIALS]?)

  • I understand the utility of
    #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 3 // Library default is 10 (times 2) –
    However, I am still unclear on what these two other #defines do and where should they be in my code?
    #define TIMEOUT_RECONNECT_WIFI 10000L
    #define RESET_IF_CONFIG_TIMEOUT true

  • I hate to ask, but do I need RTCwidget if I have SSL and am getting the time anyway?

I did find some bugs in the non-WM parts of my Blynk_WM_Template and will load the updated code.
Init, I removed the clearConfigData() code as it's no longer needed, also updated comments regarding USE_CONFIG_DATA.

Again, nice work. Thanks. I'm using WM.

@khoih-prog
Copy link
Owner

khoih-prog commented Jun 26, 2020

@thorathome

Forgot the certs file.

That's why your README instructions is so important for everybody, even for the PRO like you.

  • What is BOARD_NAME used for? It does not appear to be anywhere in the Config Portal data structure. Do we care? (I like DEVICE_HOST_NAME – shows up in the Config Portal and my router directory.)

This is helpful for certain people in certain use case.

For example, you need 1 sketch for all boards, but thanks to personalized BOARD_NAME, you can differentiate the boards in running by personalizing a different BOARD_NAME for each board using Config Portal in runtime, then you can use BOARD_NAME for HOSTNAME so that on your Router, you can know which device is which. It's not nice that every board has the same name such as ESP8266_WM, ESP_XXXXXX, etc

  • How can I adjust the Config Portal to show only 1 SSID/Passwd or 1 Blynk server/authcode
    (Where do I set [NUM_BLYNK_CREDENTIALS]?)

Not configurable now. You have to modify the library code, but not as simple as just modifying NUM_BLYNK_CREDENTIALS or NUM_WIFI_CREDENTIALS. If not use, you can specify duplicated or dummy data.

Will think about a simple way to do that, or just use 2 different source files for single set of Credentials.

Now making it simpler is not easy ;-(

  • I understand the utility of
    #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 3 // Library default is 10 (times 2) –
    However, I am still unclear on what these two other #defines do and where should they be in my code?
    #define TIMEOUT_RECONNECT_WIFI 10000L

This is deprecated and is not used now after I used MultiWiFi features (from v1.07 or v1.0.11??), but forgot to delete. Need to clean house from time to time. No incentive and no memory at all until someone reminds !!! ;=}

#define RESET_IF_CONFIG_TIMEOUT true

If we're here but still in configuration_mode, permit running CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET times before reset hardware to permit user another chance to enter Config Portal.

  • I hate to ask, but do I need RTCwidget if I have SSL and am getting the time anyway?

It's up to you. If you can manage time yourself using NTP in SSL, it's good. But not for everybody, especially in many cases, users don't use SSL. IMHO, using RTCWidget is preferable as it's much easier and simpler.

@ghost
Copy link
Author

ghost commented Jun 27, 2020

The USE_DEFAULT_CONFIG_DATA has higher priority than Config Portal and it's designed for developers to test.
You have to turn that feature off in normal operation and Config Portal input data will take over.

//#define USE_DEFAULT_CONFIG_DATA true
#define USE_DEFAULT_CONFIG_DATA false

Totally worked, thank you so much

@khoih-prog
Copy link
Owner

To @thorathome and @kevinleberge

Your contributions are noted in Contributions and Thanks

  1. Thanks to thorathome and kevinleberge to help locate the bugs, discuss the USE_DEFAULT_CONFIG_DATA solution leading to release v1.0.16. See Can’t load defaults and Setting "#define USE_DYNAMIC_PARAMETERS false" on Blynk_WM_Template.ino results in compile error

@ghost
Copy link
Author

ghost commented Jun 27, 2020

One last on this one. Either I'm not understanding it correctly, The Blynk VM Template description is wrong or it's not working as intended.

Currently it says:

///////////////////////////////////////////////////////////////////////////////////////////
//// COMPILER SWITCH SELECTION - USE DEFAULT CONFIG PORTAL FIELD DATA OR NOT //////////////
//// SELECT IF YOU WANT CONFIG PORTAL FIELDS INITIALIZED TO SOMETHING OTHER THAN BLANK ////
//// This data only gets loaded on an initial compile and upload and after Config Portal data gets deleted
//// such as by using DRD (Double Reset) or the Blynk command Blynk.clearConfigData()
#define USE_DEFAULT_CONFIG_DATA true
//#define USE_DEFAULT_CONFIG_DATA false

Maybe it should say
///////////////////////////////////////////////////////////////////////////////////////////
//// FOR DEBUG USE. IF YOU WANT TO FORCE CONFIG PORTAL FIELDS FOR TESTING ////
//// When this switch is on settings entered into sketch will be used regardless of what is entered into config portal ////
//// Set to false if you want to use config portal ////
#define USE_DEFAULT_CONFIG_DATA true
//#define USE_DEFAULT_CONFIG_DATA false

@thorathome
Copy link
Contributor

Hi @kevinleberge

Thanks for the help keeping this example up to date. Yes, you found a bug in the code. It is part of an even LARGER bug that I have now corrected and have posted on my own Github repository. I have also updated comments in the sketch, especially regarding USE_CONFIG_DATA, which has evolved considerably these past weeks.
All comments welcomed.

I've also submitted the same code to our benefactor @khoih-prog to post on his official Blynk_WM repository.

This is very helpful and much appreciated. Now that I have this code publicly available, I realize that I need to maintain it as the WM library evolves.

@khoih-prog
Copy link
Owner

Hi @kevinleberge

Just update Blynk_WM_Template to the latest version from @thorathome GitHub Repo.

Please have a look and test to see if there is anything not working as expected.

@ghost
Copy link
Author

ghost commented Jun 27, 2020

Glad to help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants