diff --git a/README.md b/README.md index 1dfa87b..28966ec 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/BlynkGSM_Manager.svg)](http://github.com/khoih-prog/BlynkGSM_Manager/issues) -By design, Blynk user can run ESP32/ESP8266 boards with either WiFi or GSM/GPRS by using different sketches, and have to upload / update firmware to change. This library enables user to include both Blynk GSM/GPRS and WiFi libraries in one sketch, run ***both WiFi and GSM/GPRS simultaneously***, or select one to use at runtime after reboot. +--- + +By design, Blynk user can run ESP32/ESP8266 boards with **either WiFi or GSM/GPRS** by using different sketches, and have to upload / update firmware to change. This library enables user to include both Blynk GSM/GPRS and WiFi libraries in one sketch, run ***both WiFi and GSM/GPRS simultaneously***, or select one to use at runtime after reboot. This is also a Blynk and WiFiManager Library for configuring/auto(re)connecting ESP8266/ESP32 modules to the available MultiWiFi APs and MultiBlynk servers at runtime. Connection is with or without SSL. Configuration data to be saved in either LittleFS / SPIFFS or EEPROM. Default Credentials as well as Dynamic custom parameters can be added and modified easily without coding knowledge. DoubleResetDetector is used to force Config Portal opening even if the Credentials are still valid. @@ -20,9 +22,18 @@ 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 HostName, 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. +- `Multiple WiFi Credentials (SSID, Password) and system will autoconnect to the best and available WiFi SSID.` +- `Multiple Blynk Credentials (Server, Token) and system will autoconnect to the available Blynk Servers.` + +--- + +### Releases v1.0.10 +1. Use ESP8266/ESP32 MultiWiFi feature to autoconnect to the best and available WiFi SSID. +2. Auto format SPIFFS/LittleFS for first time usage. +3. Fix bug and logic of USE_DEFAULT_CONFIG_DATA. -### Major Releases v1.0.9 +#### Major Releases v1.0.9 1. Add MultiWiFi/Blynk features for WiFi 2. Add MultiBlynk feature for GPRS/GSM @@ -31,28 +42,8 @@ New recent features: 5. Add Configurable Config Portal Title 6. Add Default Config Data. -### Releases v1.0.8 - -1. Fix potential dangerous bug in code and examples of v1.0.7. - -### Releases v1.0.7 - -#### Potential dangerous bug, Don't use this version - -1. WiFi Password max length is 63, according to WPA2 standard. -2. Permit to input special chars such as ***%*** and ***#*** into data fields. - -### Releases v1.0.6 - -#### Potential dangerous bug, Don't use this version - -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, or SPIFFS***. -3. See issue [Add dynamic parameters](https://github.com/khoih-prog/BlynkGSM_Manager/issues/5) - -### Releases v1.0.5 - -1. Add more modem supports. Thanks to new [TinyGSM library v0.10.5+](https://github.com/vshymanskyy/TinyGSM). +--- +--- ## Supported modems @@ -89,32 +80,37 @@ More modems may be supported later: - [ ] ZTE MG2639 - [ ] Hi-Link HLK-RM04 -### Releases v1.0.4 - -1. Enhance Config Portal GUI. -2. Reduce code size. - --- ## Prerequisite -1. [`Arduino IDE 1.8.12 or later` for Arduino](https://www.arduino.cc/en/Main/Software) -2. [`ESP32 core 1.0.4 or later`](https://github.com/espressif/arduino-esp32/releases) for ESP32 (Use Arduino Board Manager) -3. [`ESP8266 core 2.6.3 or later`](https://github.com/esp8266/Arduino/releases) for ES82662 (Use Arduino Board Manager) -3. [`Blynk library 0.6.1 or later`](https://github.com/blynkkk/blynk-library/releases) -4. [`TinyGSM library 0.10.5 or later`](https://github.com/vshymanskyy/TinyGSM) +1. [`Arduino IDE 1.8.12+` for Arduino](https://www.arduino.cc/en/Main/Software) +2. [`ESP32 core 1.0.4+`](https://github.com/espressif/arduino-esp32/releases) for ESP32 (Use Arduino Board Manager) +3. [`ESP8266 core 2.7.3+`](https://github.com/esp8266/Arduino/releases) for ES82662 (Use Arduino Board Manager) +4. [`Blynk library 0.6.1+`](https://github.com/blynkkk/blynk-library/releases) +5. [`TinyGSM library 0.10.8+`](https://github.com/vshymanskyy/TinyGSM) +6. [`ESP_DoubleResetDetector library 1.0.3+`](https://github.com/khoih-prog/ESP_DoubleResetDetector) to use DRD feature. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com + +--- -#### Use Arduino Library Manager +## Installation -1. The easiest way is to use `Arduino Library Manager`. Search for `BlynkGSM_Manager`, then select / install the latest version. -2. More detailed instructions at [![arduino-library-badge](https://www.ardu-badge.com/badge/BlynkGSM_Manager.svg?)](https://www.ardu-badge.com/BlynkGSM_Manager) +### Use Arduino Library Manager +The best and easiest way is to use `Arduino Library Manager`. Search for `BlynkGSM_Manager`, then select / install the latest version. You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/badge/BlynkGSM_Manager.svg?)](https://www.ardu-badge.com/BlynkGSM_Manager) for more detailed instructions. -#### Manual Install +### Manual Install 1. Navigate to [BlynkGSM_Manager](https://github.com/khoih-prog/BlynkGSM_Manager) page. 2. Download the latest release `BlynkGSM_Manager-master.zip`. 3. Extract the zip file to `BlynkGSM_Manager-master` directory -4. Copy whole - - `BlynkGSM_Manager-master` folder to Arduino libraries directory such as `~/Arduino/libraries`. +4. Copy the whole `BlynkGSM_Manager-master` folder to Arduino libraries' directory such as `~/Arduino/libraries/`. + +### VS Code & PlatformIO: +1. Install [VS Code](https://code.visualstudio.com/) +2. Install [PlatformIO](https://platformio.org/platformio-ide) +3. Install **BlynkGSM_Manager** library by using [Library Manager](https://docs.platformio.org/en/latest/librarymanager/). Search for **BlynkGSM_Manager** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22) +4. Use included [platformio.ini](examples/platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically + +--- ### Important information @@ -124,17 +120,20 @@ Please read more information in [TinyGSM Library](https://github.com/vshymanskyy ### How to use -For ESP32 and ESP8266, in your code : +For ESP32 and ESP8266, in your code : + 1. Replace - - `BlynkSimpleTinyGSM.h` with - - `BlynkSimpleTinyGSM_M.h` -2. Then replace + - `BlynkSimpleTinyGSM.h` with `BlynkSimpleTinyGSM_M.h` + +2. Then replace + - `Blynk.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT)` with `Blynk_WF.begin("TTGO-TCALL-GSM")` for WiFi - `Blynk.xxx()` with `Blynk_WF.xxx()` for WiFi - `Blynk.xxx()` with `Blynk_GSM.xxx()` for GSM/GPRS 3. Add + ```cpp #if USE_BLYNK_WM #include @@ -145,20 +144,20 @@ For ESP32 and ESP8266, in your code : 4. then add -``` +```cpp // Only for ESP8266 #define USE_LITTLEFS true #define USE_SPIFFS false ``` to use LittleFS (for ESP8266), or -``` +```cpp #define USE_LITTLEFS false #define USE_SPIFFS true ``` to use SPIFFS or -``` +```cpp #define USE_LITTLEFS false #define USE_SPIFFS false ``` @@ -167,7 +166,7 @@ to use EEPROM. Currently, data size in v1.0.9, with DRD and not including dynami 5. -``` +```cpp // Force some params in Blynk, only valid for library version 1.0.1 and later #define TIMEOUT_RECONNECT_WIFI 10000L #define RESET_IF_CONFIG_TIMEOUT true @@ -176,22 +175,25 @@ to use EEPROM. Currently, data size in v1.0.9, with DRD and not including dynami ``` 6. To use personalized Config Portal AP SSID and Password, as well as IP Address, channel e.g. call : -``` - // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict - Blynk_WF.setConfigPortalChannel(0); +```cpp +// Set config portal SSID and Password +Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); + +// Use configurable AP IP, instead of default IP 192.168.4.1 +Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1)); +// Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict +Blynk_WF.setConfigPortalChannel(0); ``` 7. You can specify STA-mode Static IP address, Gateway, Subnet Mask, as well as DNS server 1 and 2: -``` -// From v1.0.5, select either one of these to set static IP - Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 220), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); - //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 220), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), - // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); - //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 220), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), - // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); +```cpp +// Select either one of these to set static IP + DNS +Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); +//Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), +// IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); +//Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), +// IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); ``` 8. Change `Blynk.run()` for WiFi to `Blynk_WF.run()`. @@ -200,78 +202,248 @@ to use EEPROM. Currently, data size in v1.0.9, with DRD and not including dynami That's it. -### How to add dynamic parameters from sketch +--- +--- + +### HOWTO Use default Credentials and have them pre-loaded onto Config Portal + +See this example and modify as necessary -- To add custom parameters, just modify from the example below +#### 1. To load [Default Credentials](examples/TTGO_TCALL_GSM/Credentials.h) +```cpp +bool LOAD_DEFAULT_CONFIG_DATA = true; ``` -#define USE_DYNAMIC_PARAMETERS true -/////////////// Start dynamic Credentials /////////////// +#### 2. To use system default to load "blank" when there is no valid Credentials + +```cpp +bool LOAD_DEFAULT_CONFIG_DATA = false; +``` + +#### 3. Example of [Default Credentials](examples/TTGO_TCALL_GSM/Credentials.h) -//Defined in -/************************************** - #define MAX_ID_LEN 5 - #define MAX_DISPLAY_NAME_LEN 16 +```cpp +#if USE_BLYNK_WM - typedef struct + /// Start Default Config Data ////////////////// + + /* + // Defined in + + #define SSID_MAX_LEN 32 + //From v1.0.10, WPA2 passwords can be up to 63 characters long. + #define PASS_MAX_LEN 64 + + typedef struct + { + char wifi_ssid[SSID_MAX_LEN]; + char wifi_pw [PASS_MAX_LEN]; + } WiFi_Credentials; + + #define BLYNK_SERVER_MAX_LEN 32 + #define BLYNK_TOKEN_MAX_LEN 36 + + typedef struct + { + char blynk_server [BLYNK_SERVER_MAX_LEN]; + char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; + char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; + } Blynk_Credentials; + + #define NUM_WIFI_CREDENTIALS 2 + #define NUM_BLYNK_CREDENTIALS 2 + + // Configurable items besides fixed Header + #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) + #define DEFAULT_GPRS_PIN "1234" + + typedef struct Configuration + { + char header [16]; + WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; + Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + int blynk_port; + // YOUR GSM / GPRS RELATED + char apn [32]; + char gprsUser [32]; + char gprsPass [32]; + char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + // END OF YOUR GSM / GPRS RELATED + char board_name [24]; + int checkSum; + } Blynk_WF_Configuration; + + */ + + //bool LOAD_DEFAULT_CONFIG_DATA = true; + bool LOAD_DEFAULT_CONFIG_DATA = false; + + Blynk_WF_Configuration defaultConfig = { - char id [MAX_ID_LEN + 1]; - char displayName [MAX_DISPLAY_NAME_LEN + 1]; - char *pdata; - uint8_t maxlen; - } MenuItem; -**************************************/ + //char header[16], dummy, not used + "GSM", + //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] + //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw + "SSID1", "password1", + "SSID2", "password2", + // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token + "account.ddns.net", "wifi_token", "gsm_token", + "account.duckdns.org", "wifi_token1", "gsm_token1", + //int blynk_port; + 8080, + // YOUR GSM / GPRS RELATED + //char apn [32]; + "rogers-core-appl1.apn", + //char gprsUser [32]; + "wapuser1", + //char gprsPass [32]; + "wap", + //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + "1245678", + // END OF YOUR GSM / GPRS RELATED + //char board_name [24]; + "ESP32-GSM-WiFi", + //int checkSum, dummy, not used + 0 + }; + + /////////// End Default Config Data ///////////// -#if USE_DYNAMIC_PARAMETERS +#endif // #if USE_BLYNK_WM +``` -#define MAX_MQTT_SERVER_LEN 34 -char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = ""; +#### 4. How to add dynamic parameters from sketch -#define MAX_MQTT_PORT_LEN 6 -char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = ""; +- To add custom parameters, just modify the example below -#define MAX_MQTT_USERNAME_LEN 34 -char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = ""; +```cpp +#if USE_BLYNK_WM -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = ""; + #define USE_DYNAMIC_PARAMETERS true + + /////////////// Start dynamic Credentials /////////////// + + //Defined in + /************************************** + #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] = "mqtt.ddns.net"; + + #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] = "mqtt-user"; + + #define MAX_MQTT_PW_LEN 34 + char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; + + #define MAX_MQTT_SUBS_TOPIC_LEN 34 + char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; + + #define MAX_MQTT_PUB_TOPIC_LEN 34 + char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; + + 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 /////////// -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = ""; +#endif // #if USE_BLYNK_WM -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = ""; +``` +#### 5. If you don't need to add dynamic parameters -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 }, -}; +Use the following code snippet in sketch -uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; +```cpp +#define USE_DYNAMIC_PARAMETERS false +``` -#else +or + +```cpp +/////////////// Start dynamic Credentials /////////////// MenuItem myMenuItems [] = {}; uint16_t NUM_MENU_ITEMS = 0; -#endif - /////// // End dynamic Credentials /////////// + ``` +--- + Also see examples: 1. [TTGO_TCALL_GSM](examples/TTGO_TCALL_GSM) 2. [ESP32_GSM](examples/ESP32_GSM) 3. [ESP8266_GSM](examples/ESP8266_GSM) +4. [TTGO_TCALL_SHT3x](examples/TTGO_TCALL_SHT3x) +5. [ESP32_GSM_SHT3x](examples/ESP32_GSM_SHT3x) +6. [ESP8266_GSM_SHT3x](examples/ESP8266_GSM_SHT3x) --- +### Important Notes for using Dynamic Parameters' ids + +1. These ids (such as "mqtt" in example) must be ***unique***. + +Please be noted that the following ***reserved names are already used in library***: + +``` +"id" for WiFi SSID +"pw" for WiFi PW +"id1" for WiFi1 SSID +"pw1" for WiFi1 PW +"apn" for GPRS/GSM apn +"usr" for GPRS/GSM user +"pwd" for GPRS/GSM password +"pin" for GPRS/GSM pin +"sv" for Blynk Server +"wtk" for Blynk WiFi Token +"gtk" for Blynk GPRS/GSM Token +"sv1" for Blynk Server1 +"wtk1" for Blynk WiFi Token1 +"gtk1" for Blynk GPRS/GSM Token1 +"pt" for Blynk Port +"nm" for Board Name +``` + +--- +--- + ## So, how it works? If it detects no valid stored Credentials or 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 WiFi access point called ***ESP_xxxxxx***. Connect to it using password ***MyESP_xxxxxx***. @@ -281,6 +453,7 @@ You can set: 1. static Config Portal IP address by using `Blynk_WF.setConfigPortalIP(IPAddress(xxx, xxx, xxx, xxx))` 2. random Config Portal WiFi channel by using `Blynk_WF.setConfigPortalChannel(0)` 3. selected Config Portal WiFi channel by using `Blynk_WF.setConfigPortalChannel(channel)` +4. selected Config Portal SSID and Password by using `Blynk_WF.setConfigPortal("PortalSSID", "PortalPass")`

@@ -338,226 +511,13 @@ void loop() ``` --- - -### How to use default Credentials and have them pre-loaded onto Config Portal - -See this example and modify as necessary - -1. To load [Default Credentials](examples/TTGO_TCALL_GSM/Credentials.h) -``` -bool LOAD_DEFAULT_CONFIG_DATA = true; -``` - -2. To use system default to load "blank" when there is no valid Credentials -``` -bool LOAD_DEFAULT_CONFIG_DATA = false; -``` - -3. Example of [Default Credentials](examples/TTGO_TCALL_GSM/Credentials.h) - -```cpp -/// Start Default Config Data ////////////////// - -/* - // Defined in - - #define SSID_MAX_LEN 32 - //From v1.0.10, WPA2 passwords can be up to 63 characters long. - #define PASS_MAX_LEN 64 - - typedef struct - { - char wifi_ssid[SSID_MAX_LEN]; - char wifi_pw [PASS_MAX_LEN]; - } WiFi_Credentials; - - #define BLYNK_SERVER_MAX_LEN 32 - #define BLYNK_TOKEN_MAX_LEN 36 - - typedef struct - { - char blynk_server [BLYNK_SERVER_MAX_LEN]; - char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; - char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; - } Blynk_Credentials; - - #define NUM_WIFI_CREDENTIALS 2 - #define NUM_BLYNK_CREDENTIALS 2 - - // Configurable items besides fixed Header - #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) - #define DEFAULT_GPRS_PIN "1234" - - typedef struct Configuration - { - char header [16]; - WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; - Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - int blynk_port; - // YOUR GSM / GPRS RELATED - char apn [32]; - char gprsUser [32]; - char gprsPass [32]; - char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - // END OF YOUR GSM / GPRS RELATED - char board_name [24]; - int checkSum; - } Blynk_WF_Configuration; - -*/ - -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; - -Blynk_WF_Configuration defaultConfig = -{ - //char header[16], dummy, not used - "GSM", - //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] - //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw - "SSID1", "password1", - "SSID2", "password2", - // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token - "account.ddns.net", "wifi_token", "gsm_token", - "account.duckdns.org", "wifi_token1", "gsm_token1", - //int blynk_port; - 8080, - // YOUR GSM / GPRS RELATED - //char apn [32]; - "rogers-core-appl1.apn", - //char gprsUser [32]; - "wapuser1", - //char gprsPass [32]; - "wap", - //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - "1245678", - // END OF YOUR GSM / GPRS RELATED - //char board_name [24]; - "ESP32-GSM-WiFi", - //int checkSum, dummy, not used - 0 -}; - -/////////// End Default Config Data ///////////// -``` - -### How to add dynamic parameters from sketch - -- To add custom parameters, just modify the example below - -``` -#define USE_DYNAMIC_PARAMETERS true - -/////////////// Start dynamic Credentials /////////////// - -//Defined in -/************************************** - #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] = "mqtt.ddns.net"; - -#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] = "mqtt-user"; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; - -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 /////////// - -``` -- If you don't need to add dynamic parameters, use the following in sketch - -``` -#define USE_DYNAMIC_PARAMETERS false -``` - -or - -``` -/////////////// Start dynamic Credentials /////////////// - -MenuItem myMenuItems [] = {}; - -uint16_t NUM_MENU_ITEMS = 0; -/////// // End dynamic Credentials /////////// - -``` - -### Important Notes for using Dynamic Parameters' ids - -1. These ids (such as "mqtt" in example) must be ***unique***. - -Please be noted that the following ***reserved names are already used in library***: - -``` -"id" for WiFi SSID -"pw" for WiFi PW -"id1" for WiFi1 SSID -"pw1" for WiFi1 PW -"apn" for GPRS/GSM apn -"usr" for GPRS/GSM user -"pwd" for GPRS/GSM password -"pin" for GPRS/GSM pin -"sv" for Blynk Server -"wtk" for Blynk WiFi Token -"gtk" for Blynk GPRS/GSM Token -"sv1" for Blynk Server1 -"wtk1" for Blynk WiFi Token1 -"gtk1" for Blynk GPRS/GSM Token1 -"pt" for Blynk Port -"nm" for Board Name -``` - --- ## Example [TTGO_TCALL_GSM](examples/TTGO_TCALL_GSM) Please take a look at other examples, as well. -1. File [ESP32WM_Config.ino](examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino) +1. File [TTGO_TCALL_GSM.ino](examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino) ``` #include "defines.h" @@ -623,7 +583,8 @@ void setup() while (!SerialMon); SerialMon.print(F("\nStart TTGO-TCALL-GSM using ")); - SerialMon.println(CurrentFileFS); + SerialMon.print(CurrentFileFS); + SerialMon.println(" on " + String(ARDUINO_BOARD)); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); @@ -643,11 +604,26 @@ void setup() Serial.println(F("Use WiFi to connect Blynk")); #if USE_BLYNK_WM + + // Set config portal SSID and Password + Blynk_WF.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); + // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 232, 1)); + // Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict Blynk_WF.setConfigPortalChannel(0); - // Set personalized Hostname + + // Select either one of these to set static IP + DNS + Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); + + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //Blynk_WF.begin(); + // Use this to personalize DHCP hostname (RFC952 conformed) + // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char Blynk_WF.begin("TTGO-TCALL-GSM"); #else Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT); @@ -768,7 +744,7 @@ void loop() // 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 0 + #define EEPROM_START 0 #endif // Force some params in Blynk, only valid for library version 1.0.1 and later @@ -889,91 +865,94 @@ void loop() #ifndef Credentials_h #define Credentials_h -/// Start Default Config Data ////////////////// - -/* - // Defined in +#if USE_BLYNK_WM - #define SSID_MAX_LEN 32 - //From v1.0.10, WPA2 passwords can be up to 63 characters long. - #define PASS_MAX_LEN 64 - - typedef struct - { - char wifi_ssid[SSID_MAX_LEN]; - char wifi_pw [PASS_MAX_LEN]; - } WiFi_Credentials; + /// Start Default Config Data ////////////////// - #define BLYNK_SERVER_MAX_LEN 32 - #define BLYNK_TOKEN_MAX_LEN 36 + /* + // Defined in - typedef struct - { - char blynk_server [BLYNK_SERVER_MAX_LEN]; - char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; - char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; - } Blynk_Credentials; + #define SSID_MAX_LEN 32 + //From v1.0.10, WPA2 passwords can be up to 63 characters long. + #define PASS_MAX_LEN 64 + + typedef struct + { + char wifi_ssid[SSID_MAX_LEN]; + char wifi_pw [PASS_MAX_LEN]; + } WiFi_Credentials; + + #define BLYNK_SERVER_MAX_LEN 32 + #define BLYNK_TOKEN_MAX_LEN 36 + + typedef struct + { + char blynk_server [BLYNK_SERVER_MAX_LEN]; + char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; + char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; + } Blynk_Credentials; + + #define NUM_WIFI_CREDENTIALS 2 + #define NUM_BLYNK_CREDENTIALS 2 + + // Configurable items besides fixed Header + #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) + #define DEFAULT_GPRS_PIN "1234" + + typedef struct Configuration + { + char header [16]; + WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; + Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + int blynk_port; + // YOUR GSM / GPRS RELATED + char apn [32]; + char gprsUser [32]; + char gprsPass [32]; + char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + // END OF YOUR GSM / GPRS RELATED + char board_name [24]; + int checkSum; + } Blynk_WF_Configuration; - #define NUM_WIFI_CREDENTIALS 2 - #define NUM_BLYNK_CREDENTIALS 2 + */ - // Configurable items besides fixed Header - #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) - #define DEFAULT_GPRS_PIN "1234" + //bool LOAD_DEFAULT_CONFIG_DATA = true; + bool LOAD_DEFAULT_CONFIG_DATA = false; - typedef struct Configuration + Blynk_WF_Configuration defaultConfig = { - char header [16]; - WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; - Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - int blynk_port; + //char header[16], dummy, not used + "GSM", + //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] + //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw + "SSID1", "password1", + "SSID2", "password2", + // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token + "account.ddns.net", "wifi_token", "gsm_token", + "account.duckdns.org", "wifi_token1", "gsm_token1", + //int blynk_port; + 8080, // YOUR GSM / GPRS RELATED - char apn [32]; - char gprsUser [32]; - char gprsPass [32]; - char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - // END OF YOUR GSM / GPRS RELATED - char board_name [24]; - int checkSum; - } Blynk_WF_Configuration; - -*/ - -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; - -Blynk_WF_Configuration defaultConfig = -{ - //char header[16], dummy, not used - "GSM", - //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] - //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw - "SSID1", "password1", - "SSID2", "password2", - // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token - "account.ddns.net", "wifi_token", "gsm_token", - "account.duckdns.org", "wifi_token1", "gsm_token1", - //int blynk_port; - 8080, - // YOUR GSM / GPRS RELATED - //char apn [32]; - "rogers-core-appl1.apn", - //char gprsUser [32]; - "wapuser1", - //char gprsPass [32]; - "wap", - //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - "1245678", - // END OF YOUR GSM / GPRS RELATED - //char board_name [24]; - "ESP32-GSM-WiFi", - //int checkSum, dummy, not used - 0 -}; - -/////////// End Default Config Data ///////////// + //char apn [32]; + "rogers-core-appl1.apn", + //char gprsUser [32]; + "wapuser1", + //char gprsPass [32]; + "wap", + //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + "1245678", + // END OF YOUR GSM / GPRS RELATED + //char board_name [24]; + "ESP32-GSM-WiFi", + //int checkSum, dummy, not used + 0 + }; + + /////////// End Default Config Data ///////////// +#endif // #if USE_BLYNK_WM #endif //Credentials_h ``` @@ -984,76 +963,89 @@ Blynk_WF_Configuration defaultConfig = #ifndef dynamicParams_h #define dynamicParams_h -#define USE_DYNAMIC_PARAMETERS true - -/////////////// Start dynamic Credentials /////////////// - -//Defined in -/************************************** - #define MAX_ID_LEN 5 - #define MAX_DISPLAY_NAME_LEN 16 +#if USE_BLYNK_WM - typedef struct + #define USE_DYNAMIC_PARAMETERS true + + /////////////// Start dynamic Credentials /////////////// + + //Defined in + /************************************** + #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] = "mqtt.ddns.net"; + + #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] = "mqtt-user"; + + #define MAX_MQTT_PW_LEN 34 + char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; + + #define MAX_MQTT_SUBS_TOPIC_LEN 34 + char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; + + #define MAX_MQTT_PUB_TOPIC_LEN 34 + char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; + + MenuItem myMenuItems [] = { - 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] = "mqtt.ddns.net"; - -#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] = "mqtt-user"; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; - -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 + { "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 /////////// - -/////// // End dynamic Credentials /////////// +#endif // #if USE_BLYNK_WM #endif //dynamicParams_h ``` --- +--- + +### Debug Termimal Output Samples #### This is the terminal debug output when running both WiFi and GSM/GPRS at the same time using example [TTGO_TCALL_GSM](examples/TTGO_TCALL_GSM) ``` -Start TTGO-TCALL-GSM + +Start TTGO-TCALL-GSM_SHT3x using SPIFFS on ESP32_DEV Set GSM module baud rate Use WiFi to connect Blynk + +SPIFFS Flag read = 0xd0d04321 +No doubleResetDetected +Saving config file... +Saving config file OK [3108] Hostname=TTGO-TCALL-GSM [3169] LoadCfgFile [3169] OK @@ -1116,8 +1108,15 @@ BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGB ``` --- +--- + +### Releases v1.0.10 + +1. Use ESP8266/ESP32 MultiWiFi feature to autoconnect to the best and available WiFi SSID. +2. Auto format SPIFFS/LittleFS for first time usage. +3. Fix bug and logic of USE_DEFAULT_CONFIG_DATA. -### Major Releases v1.0.9 +#### Major Releases v1.0.9 1. Add MultiWiFi/Blynk features for WiFi 2. Add MultiBlynk feature for GPRS/GSM @@ -1126,18 +1125,18 @@ BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGB 5. Add Configurable Config Portal Title 6. Add Default Config Data. -### Releases v1.0.8 +#### Releases v1.0.8 1. Fix potential dangerous bug in code and examples of v1.0.7. -### Releases v1.0.7 +#### Releases v1.0.7 #### Potential dangerous bug, Don't use this version 1. WiFi Password max length is 63, according to WPA2 standard. 2. Permit to input special chars such as ***%*** and ***#*** into data fields. -### Releases v1.0.6 +#### Releases v1.0.6 #### Potential dangerous bug, Don't use this version @@ -1145,25 +1144,25 @@ BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGB 2. Dynamic custom parameters to be saved ***automatically in EEPROM, or SPIFFS***. 3. See issue [Add dynamic parameters](https://github.com/khoih-prog/BlynkGSM_Manager/issues/5) -### Releases v1.0.5 +#### Releases v1.0.5 1. Add more modem supports. Thanks to new [TinyGSM library v0.10.1+](https://github.com/vshymanskyy/TinyGSM). -### Releases v1.0.4 +#### Releases v1.0.4 ***Why this version*** 1. Enhance Config Portal GUI. 2. Reduce code size. -### Releases v1.0.3 +#### Releases v1.0.3 ***New in this version*** 1. Add checksum for more reliable data 2. Add clearConfigData() to enable forcing into ConfigPortal Mode when necessary -### Releases v1.0.2 +#### Releases v1.0.2 ***New in this version*** @@ -1171,13 +1170,14 @@ BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGB 2. Add many more useful functions such as `setConfigPortalChannel()`, `getFullConfigData()`, etc. 3. Completely ***restructure*** the library. -### Releases v1.0.1 +#### Releases v1.0.1 ***New in this version*** 1. Change Synch XMLHttpRequest to Async to avoid ["InvalidAccessError" DOMException](https://xhr.spec.whatwg.org/) 2. Reduce memory usage. +--- --- ## TO DO @@ -1186,14 +1186,21 @@ BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGB ## DONE -1. Permit EEPROM size and location configurable to avoid conflict with others. -2. More flexible to configure reconnection timeout. -3. For fresh config data, don't need to wait for connecting timeout before entering config portal. -4. If the config data not entered completely (APN, GPRS User, GPRS Pass, Server, HardwarePort and Blynk token), entering config portal -5. Better Cofig Portal GUI -6. WiFi Password max length is 63, according to WPA2 standard. -7. Permit to input special chars such as ***%*** and ***#*** into data fields. -8. Dynamic custom parameters + 1. Permit EEPROM size and location configurable to avoid conflict with others. + 2. More flexible to configure reconnection timeout. + 3. For fresh config data, don't need to wait for connecting timeout before entering config portal. + 4. If the config data not entered completely (APN, GPRS User, GPRS Pass, Server, HardwarePort and Blynk token), entering config portal + 5. Better Cofig Portal GUI + 6. WiFi Password max length is 63, according to WPA2 standard. + 7. Permit to input special chars such as ***%*** and ***#*** into data fields. + 8. Add Dynamic Custom Parameters with checksum + 9. Add function to configure AP Channel (fixed or random) to avoid channel conflict. +10. Default Credentials and dynamic parameters +11. **DoubleDetectDetector** to force Config Portal when double reset is detected within predetermined time, default 10s. +12. Configurable Config Portal Title +13. Re-structure all examples to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device. + +--- ### Contributions and thanks @@ -1202,6 +1209,17 @@ BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGB 3. Thanks to [FRANAIRBUS](https://github.com/FRANAIRBUS) to open the request to [Add dynamic parameters](https://github.com/khoih-prog/BlynkGSM_Manager/issues/5) 4. Thanks to [brondolin](https://github.com/brondolin) to provide the amazing fix. See [Issue 3](https://github.com/khoih-prog/Blynk_WM/issues/3). + + + + + + + +
vshymanskyy
⭐️ vshymanskyy

mikekgr
mikekgr

FRANAIRBUS
FRANAIRBUS

brondolin
brondolin

+ +--- + ## Contributing If you want to contribute to this project: @@ -1210,6 +1228,14 @@ If you want to contribute to this project: - Create issues and pull requests - Tell other people about this library +--- + +### License + +- The library is licensed under [MIT](https://github.com/khoih-prog/WebSockets2_Generic/blob/master/LICENSE) + +--- + ## Copyright Copyright 2020- Khoi Hoang diff --git a/examples/ESP32_GSM/Credentials.h b/examples/ESP32_GSM/Credentials.h index 3156e68..0d45a06 100644 --- a/examples/ESP32_GSM/Credentials.h +++ b/examples/ESP32_GSM/Credentials.h @@ -1,115 +1,121 @@ /**************************************************************************************************************************** - Credentials.h for ESP32_GSM.ino - For ESP32 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 + Credentials.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef Credentials_h #define Credentials_h -/// Start Default Config Data ////////////////// - -/* - // Defined in +#if USE_BLYNK_WM - #define SSID_MAX_LEN 32 - //From v1.0.10, WPA2 passwords can be up to 63 characters long. - #define PASS_MAX_LEN 64 + /// Start Default Config Data ////////////////// - typedef struct - { - char wifi_ssid[SSID_MAX_LEN]; - char wifi_pw [PASS_MAX_LEN]; - } WiFi_Credentials; - - #define BLYNK_SERVER_MAX_LEN 32 - #define BLYNK_TOKEN_MAX_LEN 36 + /* + // Defined in - typedef struct - { - char blynk_server [BLYNK_SERVER_MAX_LEN]; - char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; - char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; - } Blynk_Credentials; + #define SSID_MAX_LEN 32 + //From v1.0.10, WPA2 passwords can be up to 63 characters long. + #define PASS_MAX_LEN 64 + + typedef struct + { + char wifi_ssid[SSID_MAX_LEN]; + char wifi_pw [PASS_MAX_LEN]; + } WiFi_Credentials; + + #define BLYNK_SERVER_MAX_LEN 32 + #define BLYNK_TOKEN_MAX_LEN 36 + + typedef struct + { + char blynk_server [BLYNK_SERVER_MAX_LEN]; + char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; + char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; + } Blynk_Credentials; + + #define NUM_WIFI_CREDENTIALS 2 + #define NUM_BLYNK_CREDENTIALS 2 + + // Configurable items besides fixed Header + #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) + #define DEFAULT_GPRS_PIN "1234" + + typedef struct Configuration + { + char header [16]; + WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; + Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + int blynk_port; + // YOUR GSM / GPRS RELATED + char apn [32]; + char gprsUser [32]; + char gprsPass [32]; + char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + // END OF YOUR GSM / GPRS RELATED + char board_name [24]; + int checkSum; + } Blynk_WF_Configuration; - #define NUM_WIFI_CREDENTIALS 2 - #define NUM_BLYNK_CREDENTIALS 2 + */ - // Configurable items besides fixed Header - #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) - #define DEFAULT_GPRS_PIN "1234" + //bool LOAD_DEFAULT_CONFIG_DATA = true; + bool LOAD_DEFAULT_CONFIG_DATA = false; - typedef struct Configuration + Blynk_WF_Configuration defaultConfig = { - char header [16]; - WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; - Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - int blynk_port; + //char header[16], dummy, not used + "GSM", + //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] + //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw + "SSID1", "password1", + "SSID2", "password2", + // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token + "account.ddns.net", "wifi_token", "gsm_token", + "account.duckdns.org", "wifi_token1", "gsm_token1", + //int blynk_port; + 8080, // YOUR GSM / GPRS RELATED - char apn [32]; - char gprsUser [32]; - char gprsPass [32]; - char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - // END OF YOUR GSM / GPRS RELATED - char board_name [24]; - int checkSum; - } Blynk_WF_Configuration; - -*/ - -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; - -Blynk_WF_Configuration defaultConfig = -{ - //char header[16], dummy, not used - "GSM", - //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] - //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw - "SSID1", "password1", - "SSID2", "password2", - // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token - "account.ddns.net", "wifi_token", "gsm_token", - "account.duckdns.org", "wifi_token1", "gsm_token1", - //int blynk_port; - 8080, - // YOUR GSM / GPRS RELATED - //char apn [32]; - "rogers-core-appl1.apn", - //char gprsUser [32]; - "wapuser1", - //char gprsPass [32]; - "wap", - //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - "1245678", - // END OF YOUR GSM / GPRS RELATED - //char board_name [24]; - "ESP32-GSM-WiFi", - //int checkSum, dummy, not used - 0 -}; - -/////////// End Default Config Data ///////////// + //char apn [32]; + "rogers-core-appl1.apn", + //char gprsUser [32]; + "wapuser1", + //char gprsPass [32]; + "wap", + //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + "1245678", + // END OF YOUR GSM / GPRS RELATED + //char board_name [24]; + "ESP32-GSM-WiFi", + //int checkSum, dummy, not used + 0 + }; + + /////////// End Default Config Data ///////////// +#endif // #if USE_BLYNK_WM #endif //Credentials_h diff --git a/examples/ESP32_GSM/ESP32_GSM.ino b/examples/ESP32_GSM/ESP32_GSM.ino index 5a8e9f2..18dfdba 100644 --- a/examples/ESP32_GSM/ESP32_GSM.ino +++ b/examples/ESP32_GSM/ESP32_GSM.ino @@ -3,10 +3,10 @@ For ESP32 to run GSM/GPRS and WiFi simultaneously, using config portal feature Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #include "defines.h" @@ -86,7 +88,8 @@ void setup() while (!SerialMon); SerialMon.print(F("\nStart ESP32-WIFI-GSM using ")); - SerialMon.println(CurrentFileFS); + SerialMon.print(CurrentFileFS); + SerialMon.println(" on " + String(ARDUINO_BOARD)); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); @@ -107,12 +110,28 @@ void setup() Serial.println(F("Use WiFi to connect Blynk")); #if USE_BLYNK_WM + + // Set config portal SSID and Password + Blynk_WF.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); + // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 240, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 232, 1)); + // Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict Blynk_WF.setConfigPortalChannel(0); - // Set personalized Hostname + + // Select either one of these to set static IP + DNS + Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); + + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //Blynk_WF.begin(); + // Use this to personalize DHCP hostname (RFC952 conformed) + // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char Blynk_WF.begin("ESP32-WiFi-GSM"); + #else Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT); diff --git a/examples/ESP32_GSM/defines.h b/examples/ESP32_GSM/defines.h index 5d8f806..35c05ce 100644 --- a/examples/ESP32_GSM/defines.h +++ b/examples/ESP32_GSM/defines.h @@ -1,12 +1,12 @@ /**************************************************************************************************************************** - defines.h for ESP32_GSM.ino + defines.h For ESP32 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef defines_h diff --git a/examples/ESP32_GSM/dynamicParams.h b/examples/ESP32_GSM/dynamicParams.h index 8f528c7..6f30ee7 100644 --- a/examples/ESP32_GSM/dynamicParams.h +++ b/examples/ESP32_GSM/dynamicParams.h @@ -1,89 +1,96 @@ /**************************************************************************************************************************** - dynamicParams.h for ESP32_GSM.ino - For ESP32 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + dynamicParams.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef dynamicParams_h #define dynamicParams_h -#define USE_DYNAMIC_PARAMETERS true - -/////////////// Start dynamic Credentials /////////////// - -//Defined in -/************************************** - #define MAX_ID_LEN 5 - #define MAX_DISPLAY_NAME_LEN 16 - - typedef struct +#if USE_BLYNK_WM + + #define USE_DYNAMIC_PARAMETERS true + + /////////////// Start dynamic Credentials /////////////// + + //Defined in + /************************************** + #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] = "mqtt.ddns.net"; + + #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] = "mqtt-user"; + + #define MAX_MQTT_PW_LEN 34 + char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; + + #define MAX_MQTT_SUBS_TOPIC_LEN 34 + char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; + + #define MAX_MQTT_PUB_TOPIC_LEN 34 + char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; + + MenuItem myMenuItems [] = { - 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] = "mqtt.ddns.net"; - -#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] = "mqtt-user"; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; - -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 /////////// + { "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 // #if USE_BLYNK_WM #endif //dynamicParams_h diff --git a/examples/ESP32_GSM_SHT3x/Credentials.h b/examples/ESP32_GSM_SHT3x/Credentials.h index d9fa1ce..0d45a06 100644 --- a/examples/ESP32_GSM_SHT3x/Credentials.h +++ b/examples/ESP32_GSM_SHT3x/Credentials.h @@ -1,116 +1,121 @@ /**************************************************************************************************************************** - Credentials.h for ESP32_GSM_SHT3x.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 + Credentials.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef Credentials_h #define Credentials_h -/// Start Default Config Data ////////////////// - -/* - // Defined in +#if USE_BLYNK_WM - #define SSID_MAX_LEN 32 - //From v1.0.10, WPA2 passwords can be up to 63 characters long. - #define PASS_MAX_LEN 64 + /// Start Default Config Data ////////////////// - typedef struct - { - char wifi_ssid[SSID_MAX_LEN]; - char wifi_pw [PASS_MAX_LEN]; - } WiFi_Credentials; - - #define BLYNK_SERVER_MAX_LEN 32 - #define BLYNK_TOKEN_MAX_LEN 36 + /* + // Defined in - typedef struct - { - char blynk_server [BLYNK_SERVER_MAX_LEN]; - char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; - char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; - } Blynk_Credentials; + #define SSID_MAX_LEN 32 + //From v1.0.10, WPA2 passwords can be up to 63 characters long. + #define PASS_MAX_LEN 64 + + typedef struct + { + char wifi_ssid[SSID_MAX_LEN]; + char wifi_pw [PASS_MAX_LEN]; + } WiFi_Credentials; + + #define BLYNK_SERVER_MAX_LEN 32 + #define BLYNK_TOKEN_MAX_LEN 36 + + typedef struct + { + char blynk_server [BLYNK_SERVER_MAX_LEN]; + char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; + char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; + } Blynk_Credentials; + + #define NUM_WIFI_CREDENTIALS 2 + #define NUM_BLYNK_CREDENTIALS 2 + + // Configurable items besides fixed Header + #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) + #define DEFAULT_GPRS_PIN "1234" + + typedef struct Configuration + { + char header [16]; + WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; + Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + int blynk_port; + // YOUR GSM / GPRS RELATED + char apn [32]; + char gprsUser [32]; + char gprsPass [32]; + char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + // END OF YOUR GSM / GPRS RELATED + char board_name [24]; + int checkSum; + } Blynk_WF_Configuration; - #define NUM_WIFI_CREDENTIALS 2 - #define NUM_BLYNK_CREDENTIALS 2 + */ - // Configurable items besides fixed Header - #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) - #define DEFAULT_GPRS_PIN "1234" + //bool LOAD_DEFAULT_CONFIG_DATA = true; + bool LOAD_DEFAULT_CONFIG_DATA = false; - typedef struct Configuration + Blynk_WF_Configuration defaultConfig = { - char header [16]; - WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; - Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - int blynk_port; + //char header[16], dummy, not used + "GSM", + //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] + //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw + "SSID1", "password1", + "SSID2", "password2", + // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token + "account.ddns.net", "wifi_token", "gsm_token", + "account.duckdns.org", "wifi_token1", "gsm_token1", + //int blynk_port; + 8080, // YOUR GSM / GPRS RELATED - char apn [32]; - char gprsUser [32]; - char gprsPass [32]; - char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - // END OF YOUR GSM / GPRS RELATED - char board_name [24]; - int checkSum; - } Blynk_WF_Configuration; - -*/ - -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; - -Blynk_WF_Configuration defaultConfig = -{ - //char header[16], dummy, not used - "GSM", - //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] - //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw - "SSID1", "password1", - "SSID2", "password2", - // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token - "account.ddns.net", "wifi_token", "gsm_token", - "account.duckdns.org", "wifi_token1", "gsm_token1", - //int blynk_port; - 8080, - // YOUR GSM / GPRS RELATED - //char apn [32]; - "rogers-core-appl1.apn", - //char gprsUser [32]; - "wapuser1", - //char gprsPass [32]; - "wap", - //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - "1245678", - // END OF YOUR GSM / GPRS RELATED - //char board_name [24]; - "ESP32-GSM-WiFi", - //int checkSum, dummy, not used - 0 -}; - -/////////// End Default Config Data ///////////// + //char apn [32]; + "rogers-core-appl1.apn", + //char gprsUser [32]; + "wapuser1", + //char gprsPass [32]; + "wap", + //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + "1245678", + // END OF YOUR GSM / GPRS RELATED + //char board_name [24]; + "ESP32-GSM-WiFi", + //int checkSum, dummy, not used + 0 + }; + + /////////// End Default Config Data ///////////// +#endif // #if USE_BLYNK_WM #endif //Credentials_h diff --git a/examples/ESP32_GSM_SHT3x/ESP32_GSM_SHT3x.ino b/examples/ESP32_GSM_SHT3x/ESP32_GSM_SHT3x.ino index 4f75430..3cd3c96 100644 --- a/examples/ESP32_GSM_SHT3x/ESP32_GSM_SHT3x.ino +++ b/examples/ESP32_GSM_SHT3x/ESP32_GSM_SHT3x.ino @@ -4,10 +4,10 @@ Uploading SHT3x temperature and humidity data to Blynk Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -22,6 +22,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #include "defines.h" @@ -143,7 +145,8 @@ void setup() while (!SerialMon); SerialMon.print(F("\nStart ESP32-WIFI-GSM_SHT3x using ")); - SerialMon.println(CurrentFileFS); + SerialMon.print(CurrentFileFS); + SerialMon.println(" on " + String(ARDUINO_BOARD)); Sensor.Begin(); @@ -166,12 +169,28 @@ void setup() Serial.println(F("Use WiFi to connect Blynk")); #if USE_BLYNK_WM + + // Set config portal SSID and Password + Blynk_WF.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); + // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 240, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 232, 1)); + // Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict Blynk_WF.setConfigPortalChannel(0); - // Set personalized Hostname + + // Select either one of these to set static IP + DNS + Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); + + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //Blynk_WF.begin(); + // Use this to personalize DHCP hostname (RFC952 conformed) + // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char Blynk_WF.begin("ESP32-WiFi-GSM"); + #else Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT); diff --git a/examples/ESP32_GSM_SHT3x/defines.h b/examples/ESP32_GSM_SHT3x/defines.h index 5abafef..24ba366 100644 --- a/examples/ESP32_GSM_SHT3x/defines.h +++ b/examples/ESP32_GSM_SHT3x/defines.h @@ -1,13 +1,13 @@ /**************************************************************************************************************************** - defines.h for ESP32_GSM_SHT3x.ino + defines.h For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature Uploading SHT3x temperature and humidity data to Blynk Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -22,6 +22,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef defines_h diff --git a/examples/ESP32_GSM_SHT3x/dynamicParams.h b/examples/ESP32_GSM_SHT3x/dynamicParams.h index 5801e86..6f30ee7 100644 --- a/examples/ESP32_GSM_SHT3x/dynamicParams.h +++ b/examples/ESP32_GSM_SHT3x/dynamicParams.h @@ -1,90 +1,96 @@ /**************************************************************************************************************************** - dynamicParams.h for ESP32_GSM_SHT3x.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + dynamicParams.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef dynamicParams_h #define dynamicParams_h -#define USE_DYNAMIC_PARAMETERS true - -/////////////// Start dynamic Credentials /////////////// - -//Defined in -/************************************** - #define MAX_ID_LEN 5 - #define MAX_DISPLAY_NAME_LEN 16 - - typedef struct +#if USE_BLYNK_WM + + #define USE_DYNAMIC_PARAMETERS true + + /////////////// Start dynamic Credentials /////////////// + + //Defined in + /************************************** + #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] = "mqtt.ddns.net"; + + #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] = "mqtt-user"; + + #define MAX_MQTT_PW_LEN 34 + char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; + + #define MAX_MQTT_SUBS_TOPIC_LEN 34 + char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; + + #define MAX_MQTT_PUB_TOPIC_LEN 34 + char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; + + MenuItem myMenuItems [] = { - 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] = "mqtt.ddns.net"; - -#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] = "mqtt-user"; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; - -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 /////////// + { "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 // #if USE_BLYNK_WM #endif //dynamicParams_h diff --git a/examples/ESP8266_GSM/Credentials.h b/examples/ESP8266_GSM/Credentials.h index 39f6885..f398b87 100644 --- a/examples/ESP8266_GSM/Credentials.h +++ b/examples/ESP8266_GSM/Credentials.h @@ -1,26 +1,28 @@ /**************************************************************************************************************************** - Credentials.h for ESP8266_GSM.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 + Credentials.h + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef Credentials_h @@ -76,8 +78,8 @@ */ -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; +//bool LOAD_DEFAULT_CONFIG_DATA = true; +bool LOAD_DEFAULT_CONFIG_DATA = false; Blynk_WF_Configuration defaultConfig = { diff --git a/examples/ESP8266_GSM/ESP8266_GSM.ino b/examples/ESP8266_GSM/ESP8266_GSM.ino index b85d669..02f1c18 100644 --- a/examples/ESP8266_GSM/ESP8266_GSM.ino +++ b/examples/ESP8266_GSM/ESP8266_GSM.ino @@ -1,26 +1,28 @@ /**************************************************************************************************************************** - ESP8266_GSM.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + ESP8266_GSM.ino + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #include "defines.h" @@ -87,7 +89,8 @@ void setup() while (!SerialMon); SerialMon.print(F("\nStart ESP8266-WIFI-GSM using ")); - SerialMon.println(CurrentFileFS); + SerialMon.print(CurrentFileFS); + SerialMon.println(" on " + String(ARDUINO_BOARD)); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); @@ -108,12 +111,28 @@ void setup() Serial.println(F("Use WiFi to connect Blynk")); #if USE_BLYNK_WM + + // Set config portal SSID and Password + Blynk_WF.setConfigPortal("TestPortal-ESP8266", "TestPortalPass"); + // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 232, 1)); + // Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict Blynk_WF.setConfigPortalChannel(0); - // Set personalized Hostname + + // Select either one of these to set static IP + DNS + Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); + + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //Blynk_WF.begin(); + // Use this to personalize DHCP hostname (RFC952 conformed) + // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char Blynk_WF.begin("ESP8266-WiFi-GSM"); + #else Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT); diff --git a/examples/ESP8266_GSM/defines.h b/examples/ESP8266_GSM/defines.h index fa9fb1d..a03a635 100644 --- a/examples/ESP8266_GSM/defines.h +++ b/examples/ESP8266_GSM/defines.h @@ -1,26 +1,28 @@ /**************************************************************************************************************************** - defines.h for ESP8266_GSM.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + defines.h + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef defines_h diff --git a/examples/ESP8266_GSM/dynamicParams.h b/examples/ESP8266_GSM/dynamicParams.h index e5adc9c..f00421b 100644 --- a/examples/ESP8266_GSM/dynamicParams.h +++ b/examples/ESP8266_GSM/dynamicParams.h @@ -1,26 +1,28 @@ /**************************************************************************************************************************** - dynamicParams.h for ESP8266_GSM.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + dynamicParams.h for ESP8266_GSM.ino + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef dynamicParams_h diff --git a/examples/ESP8266_GSM_SHT3x/Credentials.h b/examples/ESP8266_GSM_SHT3x/Credentials.h index b184112..2bc6c1b 100644 --- a/examples/ESP8266_GSM_SHT3x/Credentials.h +++ b/examples/ESP8266_GSM_SHT3x/Credentials.h @@ -1,27 +1,29 @@ /**************************************************************************************************************************** - Credentials.h for ESP8266_GSM_SHT3x.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 + Credentials.h + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef Credentials_h @@ -77,8 +79,8 @@ */ -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; +//bool LOAD_DEFAULT_CONFIG_DATA = true; +bool LOAD_DEFAULT_CONFIG_DATA = false; Blynk_WF_Configuration defaultConfig = { diff --git a/examples/ESP8266_GSM_SHT3x/ESP8266_GSM_SHT3x.ino b/examples/ESP8266_GSM_SHT3x/ESP8266_GSM_SHT3x.ino index 7f2340f..5f6ba98 100644 --- a/examples/ESP8266_GSM_SHT3x/ESP8266_GSM_SHT3x.ino +++ b/examples/ESP8266_GSM_SHT3x/ESP8266_GSM_SHT3x.ino @@ -1,27 +1,29 @@ /**************************************************************************************************************************** - ESP8266_GSM_SHT3x.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + ESP8266_GSM_SHT3x.ino + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #include "defines.h" @@ -143,7 +145,8 @@ void setup() while (!SerialMon); SerialMon.print(F("\nStart ESP8266-WIFI-GSM_SHT3x using ")); - SerialMon.println(CurrentFileFS); + SerialMon.print(CurrentFileFS); + SerialMon.println(" on " + String(ARDUINO_BOARD)); Sensor.Begin(); @@ -166,12 +169,28 @@ void setup() Serial.println(F("Use WiFi to connect Blynk")); #if USE_BLYNK_WM + + // Set config portal SSID and Password + Blynk_WF.setConfigPortal("TestPortal-ESP8266", "TestPortalPass"); + // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 232, 1)); + // Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict Blynk_WF.setConfigPortalChannel(0); - // Set personalized Hostname + + // Select either one of these to set static IP + DNS + Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); + + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //Blynk_WF.begin(); + // Use this to personalize DHCP hostname (RFC952 conformed) + // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char Blynk_WF.begin("ESP8266-WiFi-GSM"); + #else Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT); diff --git a/examples/ESP8266_GSM_SHT3x/defines.h b/examples/ESP8266_GSM_SHT3x/defines.h index 0abc4dc..b028643 100644 --- a/examples/ESP8266_GSM_SHT3x/defines.h +++ b/examples/ESP8266_GSM_SHT3x/defines.h @@ -1,27 +1,29 @@ /**************************************************************************************************************************** - defines.h for ESP8266_GSM_SHT3x.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + defines.h + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef defines_h diff --git a/examples/ESP8266_GSM_SHT3x/dynamicParams.h b/examples/ESP8266_GSM_SHT3x/dynamicParams.h index bb2efe0..d36eaed 100644 --- a/examples/ESP8266_GSM_SHT3x/dynamicParams.h +++ b/examples/ESP8266_GSM_SHT3x/dynamicParams.h @@ -1,27 +1,29 @@ /**************************************************************************************************************************** - dynamicParams.h for ESP8266_GSM_SHT3x.ino - For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + dynamicParams.h for ESP8266_GSM_SHT3x.ino + For ESP8266 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef dynamicParams_h diff --git a/examples/TTGO_TCALL_GSM/Credentials.h b/examples/TTGO_TCALL_GSM/Credentials.h index 4ecf34e..0d45a06 100644 --- a/examples/TTGO_TCALL_GSM/Credentials.h +++ b/examples/TTGO_TCALL_GSM/Credentials.h @@ -1,116 +1,121 @@ /**************************************************************************************************************************** - Credentials.h for TTGO-TCALL.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 + Credentials.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef Credentials_h #define Credentials_h -/// Start Default Config Data ////////////////// +#if USE_BLYNK_WM -/* - // Defined in - - #define SSID_MAX_LEN 32 - //From v1.0.10, WPA2 passwords can be up to 63 characters long. - #define PASS_MAX_LEN 64 - - typedef struct - { - char wifi_ssid[SSID_MAX_LEN]; - char wifi_pw [PASS_MAX_LEN]; - } WiFi_Credentials; + /// Start Default Config Data ////////////////// - #define BLYNK_SERVER_MAX_LEN 32 - #define BLYNK_TOKEN_MAX_LEN 36 + /* + // Defined in - typedef struct - { - char blynk_server [BLYNK_SERVER_MAX_LEN]; - char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; - char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; - } Blynk_Credentials; + #define SSID_MAX_LEN 32 + //From v1.0.10, WPA2 passwords can be up to 63 characters long. + #define PASS_MAX_LEN 64 + + typedef struct + { + char wifi_ssid[SSID_MAX_LEN]; + char wifi_pw [PASS_MAX_LEN]; + } WiFi_Credentials; + + #define BLYNK_SERVER_MAX_LEN 32 + #define BLYNK_TOKEN_MAX_LEN 36 + + typedef struct + { + char blynk_server [BLYNK_SERVER_MAX_LEN]; + char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; + char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; + } Blynk_Credentials; + + #define NUM_WIFI_CREDENTIALS 2 + #define NUM_BLYNK_CREDENTIALS 2 + + // Configurable items besides fixed Header + #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) + #define DEFAULT_GPRS_PIN "1234" + + typedef struct Configuration + { + char header [16]; + WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; + Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + int blynk_port; + // YOUR GSM / GPRS RELATED + char apn [32]; + char gprsUser [32]; + char gprsPass [32]; + char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + // END OF YOUR GSM / GPRS RELATED + char board_name [24]; + int checkSum; + } Blynk_WF_Configuration; - #define NUM_WIFI_CREDENTIALS 2 - #define NUM_BLYNK_CREDENTIALS 2 + */ - // Configurable items besides fixed Header - #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) - #define DEFAULT_GPRS_PIN "1234" + //bool LOAD_DEFAULT_CONFIG_DATA = true; + bool LOAD_DEFAULT_CONFIG_DATA = false; - typedef struct Configuration + Blynk_WF_Configuration defaultConfig = { - char header [16]; - WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; - Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - int blynk_port; + //char header[16], dummy, not used + "GSM", + //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] + //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw + "SSID1", "password1", + "SSID2", "password2", + // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token + "account.ddns.net", "wifi_token", "gsm_token", + "account.duckdns.org", "wifi_token1", "gsm_token1", + //int blynk_port; + 8080, // YOUR GSM / GPRS RELATED - char apn [32]; - char gprsUser [32]; - char gprsPass [32]; - char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - // END OF YOUR GSM / GPRS RELATED - char board_name [24]; - int checkSum; - } Blynk_WF_Configuration; - -*/ - -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; - -Blynk_WF_Configuration defaultConfig = -{ - //char header[16], dummy, not used - "GSM", - //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] - //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw - "SSID1", "password1", - "SSID2", "password2", - // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token - "account.ddns.net", "wifi_token", "gsm_token", - "account.duckdns.org", "wifi_token1", "gsm_token1", - //int blynk_port; - 8080, - // YOUR GSM / GPRS RELATED - //char apn [32]; - "rogers-core-appl1.apn", - //char gprsUser [32]; - "wapuser1", - //char gprsPass [32]; - "wap", - //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - "1245678", - // END OF YOUR GSM / GPRS RELATED - //char board_name [24]; - "ESP32-GSM-WiFi", - //int checkSum, dummy, not used - 0 -}; - -/////////// End Default Config Data ///////////// + //char apn [32]; + "rogers-core-appl1.apn", + //char gprsUser [32]; + "wapuser1", + //char gprsPass [32]; + "wap", + //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + "1245678", + // END OF YOUR GSM / GPRS RELATED + //char board_name [24]; + "ESP32-GSM-WiFi", + //int checkSum, dummy, not used + 0 + }; + + /////////// End Default Config Data ///////////// +#endif // #if USE_BLYNK_WM #endif //Credentials_h diff --git a/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino b/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino index 16d0062..1bdacc6 100644 --- a/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino +++ b/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino @@ -3,10 +3,10 @@ For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -21,6 +21,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #include "defines.h" @@ -86,7 +88,8 @@ void setup() while (!SerialMon); SerialMon.print(F("\nStart TTGO-TCALL-GSM using ")); - SerialMon.println(CurrentFileFS); + SerialMon.print(CurrentFileFS); + SerialMon.println(" on " + String(ARDUINO_BOARD)); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); @@ -106,11 +109,26 @@ void setup() Serial.println(F("Use WiFi to connect Blynk")); #if USE_BLYNK_WM + + // Set config portal SSID and Password + Blynk_WF.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); + // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 232, 1)); + // Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict Blynk_WF.setConfigPortalChannel(0); - // Set personalized Hostname + + // Select either one of these to set static IP + DNS + Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); + + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //Blynk_WF.begin(); + // Use this to personalize DHCP hostname (RFC952 conformed) + // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char Blynk_WF.begin("TTGO-TCALL-GSM"); #else Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT); diff --git a/examples/TTGO_TCALL_GSM/defines.h b/examples/TTGO_TCALL_GSM/defines.h index 9b885d3..8d623cd 100644 --- a/examples/TTGO_TCALL_GSM/defines.h +++ b/examples/TTGO_TCALL_GSM/defines.h @@ -1,13 +1,12 @@ /**************************************************************************************************************************** - defines.h for TTGO-TCALL.ino + defines.h For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -22,6 +21,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef defines_h diff --git a/examples/TTGO_TCALL_GSM/dynamicParams.h b/examples/TTGO_TCALL_GSM/dynamicParams.h index 4d911e1..6f30ee7 100644 --- a/examples/TTGO_TCALL_GSM/dynamicParams.h +++ b/examples/TTGO_TCALL_GSM/dynamicParams.h @@ -1,90 +1,96 @@ /**************************************************************************************************************************** - dynamicParams.h for TTGO-TCALL.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + dynamicParams.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef dynamicParams_h #define dynamicParams_h -#define USE_DYNAMIC_PARAMETERS true - -/////////////// Start dynamic Credentials /////////////// - -//Defined in -/************************************** - #define MAX_ID_LEN 5 - #define MAX_DISPLAY_NAME_LEN 16 - - typedef struct +#if USE_BLYNK_WM + + #define USE_DYNAMIC_PARAMETERS true + + /////////////// Start dynamic Credentials /////////////// + + //Defined in + /************************************** + #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] = "mqtt.ddns.net"; + + #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] = "mqtt-user"; + + #define MAX_MQTT_PW_LEN 34 + char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; + + #define MAX_MQTT_SUBS_TOPIC_LEN 34 + char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; + + #define MAX_MQTT_PUB_TOPIC_LEN 34 + char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; + + MenuItem myMenuItems [] = { - 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] = "mqtt.ddns.net"; - -#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] = "mqtt-user"; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; - -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 /////////// + { "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 // #if USE_BLYNK_WM #endif //dynamicParams_h diff --git a/examples/TTGO_TCALL_SHT3x/Credentials.h b/examples/TTGO_TCALL_SHT3x/Credentials.h index eff30c1..0d45a06 100644 --- a/examples/TTGO_TCALL_SHT3x/Credentials.h +++ b/examples/TTGO_TCALL_SHT3x/Credentials.h @@ -1,117 +1,121 @@ /**************************************************************************************************************************** - Credentials.h for TTGO-TCALL_SHT3x.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 + Credentials.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef Credentials_h #define Credentials_h -/// Start Default Config Data ////////////////// +#if USE_BLYNK_WM -/* - // Defined in - - #define SSID_MAX_LEN 32 - //From v1.0.10, WPA2 passwords can be up to 63 characters long. - #define PASS_MAX_LEN 64 - - typedef struct - { - char wifi_ssid[SSID_MAX_LEN]; - char wifi_pw [PASS_MAX_LEN]; - } WiFi_Credentials; + /// Start Default Config Data ////////////////// - #define BLYNK_SERVER_MAX_LEN 32 - #define BLYNK_TOKEN_MAX_LEN 36 + /* + // Defined in - typedef struct - { - char blynk_server [BLYNK_SERVER_MAX_LEN]; - char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; - char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; - } Blynk_Credentials; + #define SSID_MAX_LEN 32 + //From v1.0.10, WPA2 passwords can be up to 63 characters long. + #define PASS_MAX_LEN 64 + + typedef struct + { + char wifi_ssid[SSID_MAX_LEN]; + char wifi_pw [PASS_MAX_LEN]; + } WiFi_Credentials; + + #define BLYNK_SERVER_MAX_LEN 32 + #define BLYNK_TOKEN_MAX_LEN 36 + + typedef struct + { + char blynk_server [BLYNK_SERVER_MAX_LEN]; + char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN]; + char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN]; + } Blynk_Credentials; + + #define NUM_WIFI_CREDENTIALS 2 + #define NUM_BLYNK_CREDENTIALS 2 + + // Configurable items besides fixed Header + #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) + #define DEFAULT_GPRS_PIN "1234" + + typedef struct Configuration + { + char header [16]; + WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; + Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + int blynk_port; + // YOUR GSM / GPRS RELATED + char apn [32]; + char gprsUser [32]; + char gprsPass [32]; + char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + // END OF YOUR GSM / GPRS RELATED + char board_name [24]; + int checkSum; + } Blynk_WF_Configuration; - #define NUM_WIFI_CREDENTIALS 2 - #define NUM_BLYNK_CREDENTIALS 2 + */ - // Configurable items besides fixed Header - #define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) ) - #define DEFAULT_GPRS_PIN "1234" + //bool LOAD_DEFAULT_CONFIG_DATA = true; + bool LOAD_DEFAULT_CONFIG_DATA = false; - typedef struct Configuration + Blynk_WF_Configuration defaultConfig = { - char header [16]; - WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; - Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - int blynk_port; + //char header[16], dummy, not used + "GSM", + //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] + //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw + "SSID1", "password1", + "SSID2", "password2", + // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; + // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token + "account.ddns.net", "wifi_token", "gsm_token", + "account.duckdns.org", "wifi_token1", "gsm_token1", + //int blynk_port; + 8080, // YOUR GSM / GPRS RELATED - char apn [32]; - char gprsUser [32]; - char gprsPass [32]; - char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - // END OF YOUR GSM / GPRS RELATED - char board_name [24]; - int checkSum; - } Blynk_WF_Configuration; - -*/ - -bool LOAD_DEFAULT_CONFIG_DATA = true; -//bool LOAD_DEFAULT_CONFIG_DATA = false; - -Blynk_WF_Configuration defaultConfig = -{ - //char header[16], dummy, not used - "GSM", - //WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS] - //WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw - "SSID1", "password1", - "SSID2", "password2", - // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS]; - // Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token - "account.ddns.net", "wifi_token", "gsm_token", - "account.duckdns.org", "wifi_token1", "gsm_token1", - //int blynk_port; - 8080, - // YOUR GSM / GPRS RELATED - //char apn [32]; - "rogers-core-appl1.apn", - //char gprsUser [32]; - "wapuser1", - //char gprsPass [32]; - "wap", - //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode - "1245678", - // END OF YOUR GSM / GPRS RELATED - //char board_name [24]; - "ESP32-GSM-WiFi", - //int checkSum, dummy, not used - 0 -}; - -/////////// End Default Config Data ///////////// + //char apn [32]; + "rogers-core-appl1.apn", + //char gprsUser [32]; + "wapuser1", + //char gprsPass [32]; + "wap", + //char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode + "1245678", + // END OF YOUR GSM / GPRS RELATED + //char board_name [24]; + "ESP32-GSM-WiFi", + //int checkSum, dummy, not used + 0 + }; + + /////////// End Default Config Data ///////////// +#endif // #if USE_BLYNK_WM #endif //Credentials_h diff --git a/examples/TTGO_TCALL_SHT3x/TTGO_TCALL_SHT3x.ino b/examples/TTGO_TCALL_SHT3x/TTGO_TCALL_SHT3x.ino index b58ec2f..48e8132 100644 --- a/examples/TTGO_TCALL_SHT3x/TTGO_TCALL_SHT3x.ino +++ b/examples/TTGO_TCALL_SHT3x/TTGO_TCALL_SHT3x.ino @@ -1,16 +1,16 @@ /**************************************************************************************************************************** - TTGO-TCALL_SHT3x.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- + TTGO-TCALL_SHT3x.ino + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously @@ -22,6 +22,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #include "defines.h" @@ -143,7 +145,8 @@ void setup() while (!SerialMon); SerialMon.print(F("\nStart TTGO-TCALL-GSM_SHT3x using ")); - SerialMon.println(CurrentFileFS); + SerialMon.print(CurrentFileFS); + SerialMon.println(" on " + String(ARDUINO_BOARD)); Sensor.Begin(); @@ -165,12 +168,28 @@ void setup() Serial.println(F("Use WiFi to connect Blynk")); #if USE_BLYNK_WM + + // Set config portal SSID and Password + Blynk_WF.setConfigPortal("TestPortal-ESP32", "TestPortalPass"); + // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1)); - // Use channel = 0 => random Config Portal WiFi channel to avoid conflict + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 232, 1)); + // Set config portal channel, default = 1. Use 0 => random channel from 1-12 to avoid conflict Blynk_WF.setConfigPortalChannel(0); - // Set personalized Hostname + + // Select either one of these to set static IP + DNS + Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8)); + //Blynk_WF.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), + // IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8)); + + // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX + //Blynk_WF.begin(); + // Use this to personalize DHCP hostname (RFC952 conformed) + // 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char Blynk_WF.begin("TTGO-TCALL-GSM"); + #else Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT); diff --git a/examples/TTGO_TCALL_SHT3x/defines.h b/examples/TTGO_TCALL_SHT3x/defines.h index 56bfd73..d92b24b 100644 --- a/examples/TTGO_TCALL_SHT3x/defines.h +++ b/examples/TTGO_TCALL_SHT3x/defines.h @@ -1,28 +1,29 @@ /**************************************************************************************************************************** - defines.h for TTGO-TCALL_SHT3x.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + defines.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef defines_h diff --git a/examples/TTGO_TCALL_SHT3x/dynamicParams.h b/examples/TTGO_TCALL_SHT3x/dynamicParams.h index ce3f07a..6f30ee7 100644 --- a/examples/TTGO_TCALL_SHT3x/dynamicParams.h +++ b/examples/TTGO_TCALL_SHT3x/dynamicParams.h @@ -1,91 +1,96 @@ /**************************************************************************************************************************** - dynamicParams.h for TTGO-TCALL_SHT3x.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature - Uploading SHT3x temperature and humidity data to Blynk - - - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager - Licensed under MIT license - Version: 1.0.9 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. - 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size - 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously - 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() - 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. - 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md - 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch - 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. - 1.0.8 K Hoang 14/04/2020 Fix bug. - 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, - Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + dynamicParams.h + For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + Uploading SHT3x temperature and humidity data to Blynk + + Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager + Licensed under MIT license + Version: 1.0.10 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library. + 1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size + 1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously + 1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData() + 1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size. + 1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md + 1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch + 1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data. + 1.0.8 K Hoang 14/04/2020 Fix bug. + 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, + Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef dynamicParams_h #define dynamicParams_h -#define USE_DYNAMIC_PARAMETERS true - -/////////////// Start dynamic Credentials /////////////// - -//Defined in -/************************************** - #define MAX_ID_LEN 5 - #define MAX_DISPLAY_NAME_LEN 16 - - typedef struct +#if USE_BLYNK_WM + + #define USE_DYNAMIC_PARAMETERS true + + /////////////// Start dynamic Credentials /////////////// + + //Defined in + /************************************** + #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] = "mqtt.ddns.net"; + + #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] = "mqtt-user"; + + #define MAX_MQTT_PW_LEN 34 + char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; + + #define MAX_MQTT_SUBS_TOPIC_LEN 34 + char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; + + #define MAX_MQTT_PUB_TOPIC_LEN 34 + char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; + + MenuItem myMenuItems [] = { - 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] = "mqtt.ddns.net"; - -#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] = "mqtt-user"; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "mqtt-pass"; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "SubTopic_ESP32_GSM"; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; - -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 /////////// + { "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 // #if USE_BLYNK_WM #endif //dynamicParams_h diff --git a/keywords.txt b/keywords.txt index 421eee6..d38fc20 100644 --- a/keywords.txt +++ b/keywords.txt @@ -31,12 +31,6 @@ syncAll KEYWORD2 syncVirtual KEYWORD2 setProperty KEYWORD2 logEvent KEYWORD2 -loadConfigData KEYWORD2 -saveConfigData KEYWORD2 -getConfigData KEYWORD2 -connectToWifi KEYWORD2 -handleRequest KEYWORD2 -startConfigurationMode KEYWORD2 setConfigPortalIP KEYWORD2 setConfigPortal KEYWORD2 setConfigPortalChannel KEYWORD2 diff --git a/library.json b/library.json index 01caff4..a9faa42 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "name": "BlynkGSM_Manager", - "version": "1.0.9", - "description": "Build a smartphone app for your project in minutes. Blynk allows creating IoT solutions easily. It supports WiFi, BLE, Bluetooth, Ethernet, GSM, USB, Serial. Works with many boards like ESP8266, ESP32, Arduino UNO, Nano, Due, Mega, Zero, MKR100, Yun, Raspberry Pi, Particle, Energia, ARM mbed, Intel Edison/Galileo/Joule, BBC micro:bit, DFRobot, RedBearLab, Microduino, LinkIt ONE ...", + "version": "1.0.10", + "description": "Library for enabling GSM/GPRS and WiFi running simultaneously as well as configuring/auto(re)connecting at runtime GSM shields to Internet and Blynk and ESP8266/ESP32 WiFi modules to best or available MultiWiFi APs and MultiBlynk servers. 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. Optional default Credentials to be autoloaded into Config Portal to use or change instead of manually input. Static STA IP and DHCP Hostname as well as Config Portal AP channel, IP, SSID, Password can be configured. DoubleDetectDetector feature permits entering Config Portal as requested.", "keywords": "sensors, control, device, smartphone, mobile, app, web, cloud, communication, protocol, iot, m2m, wifi, ble, bluetooth, ethernet, usb, serial, gsm, gprs, 3g, data, esp8266, http", "authors": { diff --git a/library.properties b/library.properties index 35d7a50..1c06b08 100644 --- a/library.properties +++ b/library.properties @@ -1,12 +1,12 @@ name=BlynkGSM_Manager -version=1.0.9 +version=1.0.10 author=Khoi Hoang license=MIT maintainer=Khoi Hoang -sentence=Simple GSM shield Credentials Manager for Blynk and ESP32 / ESP8266 boards, with or without SSL, configuration data saved in LittleFS / SPIFFS / EEPROM -paragraph=Library for configuring/auto(re)connecting GSM shields to Internet and Blynk at runtime and enable GSM/GPRS and WiFi running simultaneously. +sentence=Simple GSM shield Credentials Manager for Blynk and ESP32 / ESP8266 boards, with or without SSL, configuration data saved in LittleFS / SPIFFS / EEPROM. +paragraph=Library for enabling GSM/GPRS and WiFi running simultaneously as well as configuring/auto(re)connecting at runtime GSM shields to Internet and Blynk and ESP8266/ESP32 WiFi modules to best or available MultiWiFi APs and MultiBlynk servers. 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. Optional default Credentials to be autoloaded into Config Portal to use or change instead of manually input. Static STA IP and DHCP Hostname as well as Config Portal AP channel, IP, SSID, Password can be configured. DoubleDetectDetector feature permits entering Config Portal as requested. category=Communication url=https://github.com/khoih-prog/BlynkGSM_Manager architectures=esp32,esp8266 -depends=Blynk,TinyGSM +depends=Blynk,TinyGSM,ESP_DoubleResetDetector includes=BlynkSimpleTinyGSM_M.h diff --git a/src/Adapters/BlynkGsm_ESP32M.h b/src/Adapters/BlynkGsm_ESP32M.h index a73d397..cb451d4 100644 --- a/src/Adapters/BlynkGsm_ESP32M.h +++ b/src/Adapters/BlynkGsm_ESP32M.h @@ -3,10 +3,10 @@ For ESP32 with GSM/GPRS and WiFi running simultaneously, with WiFi config portal Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -29,6 +29,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef ESP32 #error This code is designed to run on ESP32, not ESP8266 nor Arduino AVR platform! Please check your Tools->Board setting. diff --git a/src/Adapters/BlynkGsm_ESP8266M.h b/src/Adapters/BlynkGsm_ESP8266M.h index 8889ad0..a8a9a6f 100644 --- a/src/Adapters/BlynkGsm_ESP8266M.h +++ b/src/Adapters/BlynkGsm_ESP8266M.h @@ -1,12 +1,10 @@ /**************************************************************************************************************************** BlynkGsm_ESP8266M.h - For ESP8266 with GSM/GPRS and WiFi running simultaneously, with WiFi config portal - Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -29,6 +27,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef ESP8266 #error This code is designed to run on ESP8266, not ESP32 nor Arduino AVR platform! Please check your Tools->Board setting. diff --git a/src/BlynkSimpleEsp32_GSM_WF.h b/src/BlynkSimpleEsp32_GSM_WF.h index 8c4e733..aa36a5a 100644 --- a/src/BlynkSimpleEsp32_GSM_WF.h +++ b/src/BlynkSimpleEsp32_GSM_WF.h @@ -3,10 +3,10 @@ For ESP32 with GSM/GPRS and WiFi running simultaneously, with WiFi config portal Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -29,6 +29,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_GSM_WF_h diff --git a/src/BlynkSimpleEsp32_GSM_WFM.h b/src/BlynkSimpleEsp32_GSM_WFM.h index 27d7d5d..87361bb 100644 --- a/src/BlynkSimpleEsp32_GSM_WFM.h +++ b/src/BlynkSimpleEsp32_GSM_WFM.h @@ -3,10 +3,10 @@ For ESP32 with GSM/GPRS and WiFi running simultaneously, with WiFi config portal Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -29,25 +29,30 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_GSM_WFM_h #define BlynkSimpleEsp32_GSM_WFM_h #ifndef ESP32 -#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. #endif #define BLYNK_SEND_ATOMIC // KH #define BLYNK_GSM_ESP32_WFM_DEBUG 3 + #define BLYNK_TIMEOUT_MS 30000UL #include #include #include + #include +#include #include @@ -113,12 +118,11 @@ typedef struct } MenuItem; // -///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; #define SSID_MAX_LEN 32 -//From v1.0.10, WPA2 passwords can be up to 63 characters long. +// WPA2 passwords can be up to 63 characters long. #define PASS_MAX_LEN 64 typedef struct @@ -163,7 +167,6 @@ typedef struct Configuration uint16_t CONFIG_DATA_SIZE = sizeof(Blynk_WF_Configuration); -///New from v1.0.13 extern bool LOAD_DEFAULT_CONFIG_DATA; extern Blynk_WF_Configuration defaultConfig; @@ -227,7 +230,6 @@ class BlynkWifi BLYNK_LOG2(BLYNK_F("Con2:"), ssid); WiFi.mode(WIFI_STA); - // New from Blynk_WM v1.0.5 if (static_IP != IPAddress(0, 0, 0, 0)) { BLYNK_LOG1(BLYNK_F("Use statIP")); @@ -309,10 +311,14 @@ class BlynkWifi noConfigPortal = false; } //// New DRD //// -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG1(BLYNK_F("======= Start Default Config Data =======")); - displayConfigData(defaultConfig); -#endif + +#if ( BLYNK_WM_DEBUG > 2) + if (LOAD_DEFAULT_CONFIG_DATA) + { + BLYNK_LOG1(BLYNK_F("======= Start Default Config Data =======")); + displayConfigData(defaultConfig); + } +#endif WiFi.mode(WIFI_STA); @@ -332,10 +338,6 @@ class BlynkWifi BLYNK_LOG2(BLYNK_F("Hostname="), RFC952_hostname); -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG1(noConfigPortal? BLYNK_F("bg: noConfigPortal = true") : BLYNK_F("bg: noConfigPortal = false")); -#endif - //// New DRD //// // noConfigPortal when getConfigData() OK and no DRD'ed if (getConfigData() && noConfigPortal) @@ -347,7 +349,15 @@ class BlynkWifi BLYNK_LOG1(noConfigPortal? BLYNK_F("bg: noConfigPortal = true") : BLYNK_F("bg: noConfigPortal = false")); #endif - if (connectMultiWiFi(TIMEOUT_RECONNECT_WIFI)) + for (int i = 0; i < NUM_WIFI_CREDENTIALS; i++) + { + wifiMulti.addAP(BlynkGSM_ESP32_config.WiFi_Creds[i].wifi_ssid, BlynkGSM_ESP32_config.WiFi_Creds[i].wifi_pw); + } + + //Base::begin(BlynkGSM_ESP32_config.blynk_token); + //this->conn.begin(BlynkGSM_ESP32_config.blynk_server, BlynkGSM_ESP32_config.blynk_port); + + if (connectMultiWiFi() == WL_CONNECTED) { BLYNK_LOG1(BLYNK_F("bg: WiFi OK. Try Blynk")); @@ -386,18 +396,18 @@ class BlynkWifi } #ifndef TIMEOUT_RECONNECT_WIFI -#define TIMEOUT_RECONNECT_WIFI 10000L + #define TIMEOUT_RECONNECT_WIFI 10000L #else // Force range of user-defined TIMEOUT_RECONNECT_WIFI between 10-60s -#if (TIMEOUT_RECONNECT_WIFI < 10000L) -#warning TIMEOUT_RECONNECT_WIFI too low. Reseting to 10000 -#undef TIMEOUT_RECONNECT_WIFI -#define TIMEOUT_RECONNECT_WIFI 10000L -#elif (TIMEOUT_RECONNECT_WIFI > 60000L) -#warning TIMEOUT_RECONNECT_WIFI too high. Reseting to 60000 -#undef TIMEOUT_RECONNECT_WIFI -#define TIMEOUT_RECONNECT_WIFI 60000L -#endif + #if (TIMEOUT_RECONNECT_WIFI < 10000L) + #warning TIMEOUT_RECONNECT_WIFI too low. Reseting to 10000 + #undef TIMEOUT_RECONNECT_WIFI + #define TIMEOUT_RECONNECT_WIFI 10000L + #elif (TIMEOUT_RECONNECT_WIFI > 60000L) + #warning TIMEOUT_RECONNECT_WIFI too high. Reseting to 60000 + #undef TIMEOUT_RECONNECT_WIFI + #define TIMEOUT_RECONNECT_WIFI 60000L + #endif #endif #ifndef RESET_IF_CONFIG_TIMEOUT @@ -405,18 +415,18 @@ class BlynkWifi #endif #ifndef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET -#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 10 + #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 10 #else // Force range of user-defined TIMES_BEFORE_RESET between 2-100 -#if (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET < 2) -#warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too low. Reseting to 2 -#undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET -#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 2 -#elif (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET > 100) -#warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too high. Reseting to 100 -#undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET -#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 100 -#endif + #if (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET < 2) + #warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too low. Reseting to 2 + #undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET + #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 2 + #elif (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET > 100) + #warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too high. Reseting to 100 + #undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET + #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 100 + #endif #endif void run() @@ -441,9 +451,7 @@ class BlynkWifi retryTimes = 0; if (server) - { server->handleClient(); - } return; } @@ -469,7 +477,8 @@ class BlynkWifi if ( WiFi.status() != WL_CONNECTED ) { BLYNK_LOG1(BLYNK_F("r:Wlost.ReconW+B")); - if (connectMultiWiFi(TIMEOUT_RECONNECT_WIFI)) + + if (connectMultiWiFi() == WL_CONNECTED) { // turn the LED_BUILTIN OFF to tell us we exit configuration mode. digitalWrite(LED_BUILTIN, LED_OFF); @@ -507,9 +516,16 @@ class BlynkWifi digitalWrite(LED_BUILTIN, LED_OFF); } - if (this->connected()) + Base::run(); + } + + void setHostname(void) + { + if (RFC952_hostname[0] != 0) { - Base::run(); + // See https://github.com/espressif/arduino-esp32/issues/2537 + WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); + WiFi.setHostname(RFC952_hostname); } } @@ -525,7 +541,7 @@ class BlynkWifi } #define MIN_WIFI_CHANNEL 1 -#define MAX_WIFI_CHANNEL 13 +#define MAX_WIFI_CHANNEL 12 int setConfigPortalChannel(int channel = 1) { @@ -561,11 +577,6 @@ class BlynkWifi static_DNS2 = dns_address_2; } - String getBoardName() - { - return (String(BlynkGSM_ESP32_config.board_name)); - } - String getWiFiSSID(uint8_t index) { if (index >= NUM_WIFI_CREDENTIALS) @@ -623,37 +634,50 @@ class BlynkWifi String getAPN() { + if (!hadConfigData) + getConfigData(); + return (String(BlynkGSM_ESP32_config.apn)); } String getGPRSUser() { + if (!hadConfigData) + getConfigData(); + return (String(BlynkGSM_ESP32_config.gprsUser)); } String getGPRSPass() { + if (!hadConfigData) + getConfigData(); + return (BlynkGSM_ESP32_config.gprsPass); } String getGPRSPIN() { + if (!hadConfigData) + getConfigData(); + return (BlynkGSM_ESP32_config.gprsPin); } - int getHWPort() + String getBoardName() { - return (BlynkGSM_ESP32_config.blynk_port); + if (!hadConfigData) + getConfigData(); + + return (String(BlynkGSM_ESP32_config.board_name)); } - - void setHostname(void) + + int getHWPort() { - if (RFC952_hostname[0] != 0) - { - // See https://github.com/espressif/arduino-esp32/issues/2537 - WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); - WiFi.setHostname(RFC952_hostname); - } + if (!hadConfigData) + getConfigData(); + + return (BlynkGSM_ESP32_config.blynk_port); } Blynk_WF_Configuration* getFullConfigData(Blynk_WF_Configuration *configData) @@ -678,6 +702,8 @@ class BlynkWifi WebServer *server; bool configuration_mode = false; + WiFiMulti wifiMulti; + unsigned long configTimeout; bool hadConfigData = false; @@ -688,13 +714,13 @@ class BlynkWifi uint16_t totalDataSize = 0; - // For Config Portal, from Blynk_WM v1.0.5 + // For Config Portal IPAddress portal_apIP = IPAddress(192, 168, 4, 1); String portal_ssid = ""; String portal_pass = ""; - // For static IP, from Blynk_WM v1.0.5 + // For static IP IPAddress static_IP = IPAddress(0, 0, 0, 0); IPAddress static_GW = IPAddress(0, 0, 0, 0); IPAddress static_SN = IPAddress(255, 255, 255, 0); @@ -853,13 +879,16 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("OK")); file.close(); - BLYNK_LOG4(F("CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); // Free buffer if (readBuffer != NULL) { free(readBuffer); + +#if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Buffer freed")); +#endif } if ( checkSum != readCheckSum) @@ -919,7 +948,7 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("OK")); file.close(); - BLYNK_LOG4(F("CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); if ( checkSum != readCheckSum) { @@ -970,7 +999,7 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("failed")); } - BLYNK_LOG2(F("CrWCSum="), String(checkSum, HEX)); + BLYNK_LOG2(F("CrWCSum=0x"), String(checkSum, HEX)); // Trying open redundant Auth file file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "w"); @@ -1074,62 +1103,87 @@ class BlynkWifi saveDynamicData(); } + + void saveAllConfigData(void) + { + saveConfigData(); + saveDynamicData(); + } // Return false if init new EEPROM, or SPIFFS. No more need trying to connect. Go directly to config mode bool getConfigData() { - bool dynamicDataValid; + bool dynamicDataValid; + int calChecksum; hadConfigData = false; // Auto format SPIFFS if not yet formatted if (!FileFS.begin(true)) { - BLYNK_LOG1(BLYNK_F("SPIFFS failed!. Please use EEPROM.")); - - return false; + BLYNK_LOG1(BLYNK_F("SPIFFS failed! Formatting.")); + + if (!FileFS.begin()) + { + BLYNK_LOG1(BLYNK_F("SPIFFS failed! Pls use EEPROM.")); + return false; + } } - if ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) + if (LOAD_DEFAULT_CONFIG_DATA) + { + // Load Config Data from Sketch + memcpy(&BlynkGSM_ESP32_config, &defaultConfig, sizeof(BlynkGSM_ESP32_config)); + strcpy(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveAllConfigData(); + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("======= Start Loaded Config Data =======")); + displayConfigData(BlynkGSM_ESP32_config); +#endif + + // Don't need Config Portal anymore + return true; + } + else if ( ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) && + ( FileFS.exists(CREDENTIALS_FILENAME) || FileFS.exists(CREDENTIALS_FILENAME_BACKUP) ) ) { // if config file exists, load loadConfigData(); + #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("======= Start Stored Config Data =======")); displayConfigData(BlynkGSM_ESP32_config); -#endif - } - - int calChecksum = calcChecksum(); +#endif - BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), - BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP32_config.checkSum, HEX)); + calChecksum = calcChecksum(); - if (LOAD_DEFAULT_CONFIG_DATA) - { - // Load default dynamicData, if checkSum OK => valid data => load - // otherwise, use default in sketch and just assume it's OK - if (checkDynamicData()) + BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), + BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP32_config.checkSum, HEX)); + + // Load dynamic data + dynamicDataValid = loadDynamicData(); + + if (dynamicDataValid) { #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Valid Stored Dynamic Data")); -#endif - loadDynamicData(); - dynamicDataValid = true; +#endif } #if ( BLYNK_WM_DEBUG > 2) else { - BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data")); - dynamicDataValid = false; + BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data. Ignored")); } -#endif +#endif } - else - { - dynamicDataValid = loadDynamicData(); - } - + else + { + // Not loading Default config data, but having no config file => Config Portal + return false; + } if ( (strncmp(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) || (calChecksum != BlynkGSM_ESP32_config.checkSum) || !dynamicDataValid ) @@ -1146,13 +1200,7 @@ class BlynkWifi else { memset(&BlynkGSM_ESP32_config, 0, sizeof(BlynkGSM_ESP32_config)); - - for (int i = 0; i < NUM_MENU_ITEMS; i++) - { - // Actual size of pdata is [maxlen + 1] - memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); - } - + strcpy(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_ssid, NO_CONFIG); strcpy(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_pw, NO_CONFIG); strcpy(BlynkGSM_ESP32_config.WiFi_Creds[1].wifi_ssid, NO_CONFIG); @@ -1172,23 +1220,25 @@ class BlynkWifi for (int i = 0; i < NUM_MENU_ITEMS; i++) { + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); strncpy(myMenuItems[i].pdata, NO_CONFIG, myMenuItems[i].maxlen); } } strcpy(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE); - #if ( BLYNK_WM_DEBUG > 2) +#if ( BLYNK_WM_DEBUG > 2) for (int i = 0; i < NUM_MENU_ITEMS; i++) { BLYNK_LOG4(BLYNK_F("g:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); } - #endif +#endif // Don't need BlynkGSM_ESP32_config.checkSum = 0; - saveConfigData(); + saveAllConfigData(); return false; } @@ -1221,33 +1271,32 @@ class BlynkWifi #else -#ifndef EEPROM_SIZE -#define EEPROM_SIZE 2048 -#else -#if (EEPROM_SIZE > 4096) -#warning EEPROM_SIZE must be <= 2048. Reset to 2048 -#undef EEPROM_SIZE -#define EEPROM_SIZE 2048 -#endif -// FLAG_DATA_SIZE is 4, to store DRD flag -#if (EEPROM_SIZE < FLAG_DATA_SIZE + CONFIG_DATA_SIZE) -#warning EEPROM_SIZE must be > CONFIG_DATA_SIZE. Reset to 2048 -#undef EEPROM_SIZE -#define EEPROM_SIZE 2048 -#endif -#endif - -#ifndef EEPROM_START -#define EEPROM_START 0 -#else -#if (EEPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE) -#error EPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE. Please adjust. -#endif -#endif - -// Stating positon to store BlynkGSM_ESP32_config -#define BLYNK_EEPROM_START (EEPROM_START + FLAG_DATA_SIZE) - + #ifndef EEPROM_SIZE + #define EEPROM_SIZE 2048 + #else + #if (EEPROM_SIZE > 4096) + #warning EEPROM_SIZE must be <= 2048. Reset to 2048 + #undef EEPROM_SIZE + #define EEPROM_SIZE 2048 + #endif + // FLAG_DATA_SIZE is 4, to store DRD flag + #if (EEPROM_SIZE < FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + #warning EEPROM_SIZE must be > CONFIG_DATA_SIZE. Reset to 2048 + #undef EEPROM_SIZE + #define EEPROM_SIZE 2048 + #endif + #endif + + #ifndef EEPROM_START + #define EEPROM_START 0 + #else + #if (EEPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE) + #error EPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE. Please adjust. + #endif + #endif + + // Stating positon to store BlynkGSM_ESP32_config + #define BLYNK_EEPROM_START (EEPROM_START + FLAG_DATA_SIZE) bool checkDynamicData(void) { @@ -1299,7 +1348,7 @@ class BlynkWifi EEPROM.get(offset, readCheckSum); - BLYNK_LOG4(F("ChkCrR:CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("ChkCrR:CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); if ( checkSum != readCheckSum) { @@ -1339,7 +1388,7 @@ class BlynkWifi EEPROM.get(offset, readCheckSum); - BLYNK_LOG4(F("CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); if ( checkSum != readCheckSum) { @@ -1373,54 +1422,68 @@ class BlynkWifi EEPROM.put(offset, checkSum); //EEPROM.commit(); - BLYNK_LOG2(F("CrWCSum="), String(checkSum, HEX)); + BLYNK_LOG2(F("CrWCSum=0x"), String(checkSum, HEX)); } bool getConfigData() { - bool dynamicDataValid; + bool dynamicDataValid; + int calChecksum; hadConfigData = false; EEPROM.begin(EEPROM_SIZE); BLYNK_LOG2(BLYNK_F("EEPROMsz:"), EEPROM_SIZE); - EEPROM.get(BLYNK_EEPROM_START, BlynkGSM_ESP32_config); + + if (LOAD_DEFAULT_CONFIG_DATA) + { + // Load Config Data from Sketch + memcpy(&BlynkGSM_ESP32_config, &defaultConfig, sizeof(BlynkGSM_ESP32_config)); + strcpy(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveAllConfigData(); + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("======= Start Loaded Config Data =======")); + displayConfigData(BlynkGSM_ESP32_config); +#endif + // Don't need Config Portal anymore + return true; + } + else + { + // Load data from EEPROM + EEPROM.get(BLYNK_EEPROM_START, BlynkGSM_ESP32_config); + #if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG1(BLYNK_F("======= Start Stored Config Data =======")); - displayConfigData(BlynkGSM_ESP32_config); -#endif + BLYNK_LOG1(BLYNK_F("======= Start Stored Config Data =======")); + displayConfigData(BlynkGSM_ESP32_config); +#endif - int calChecksum = calcChecksum(); + calChecksum = calcChecksum(); - BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), - BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP32_config.checkSum, HEX)); + BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), + BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP32_config.checkSum, HEX)); - if (LOAD_DEFAULT_CONFIG_DATA) - { - // Load default dynamicData, if checkSum OK => valid data => load - // otherwise, use default in sketch and just assume it's OK - if (checkDynamicData()) + // Load dynamic data from EEPROM + dynamicDataValid = EEPROM_getDynamicData(); + + if (dynamicDataValid) { #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Valid Stored Dynamic Data")); #endif - EEPROM_getDynamicData(); - dynamicDataValid = true; } #if ( BLYNK_WM_DEBUG > 2) else { BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data. Ignored")); - dynamicDataValid = false; } -#endif +#endif } - else - { - dynamicDataValid = EEPROM_getDynamicData(); - } - + if ( (strncmp(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) || (calChecksum != BlynkGSM_ESP32_config.checkSum) || !dynamicDataValid ) { @@ -1435,13 +1498,7 @@ class BlynkWifi else { memset(&BlynkGSM_ESP32_config, 0, sizeof(BlynkGSM_ESP32_config)); - - for (int i = 0; i < NUM_MENU_ITEMS; i++) - { - // Actual size of pdata is [maxlen + 1] - memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); - } - + strcpy(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_ssid, NO_CONFIG); strcpy(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_pw, NO_CONFIG); strcpy(BlynkGSM_ESP32_config.WiFi_Creds[1].wifi_ssid, NO_CONFIG); @@ -1461,25 +1518,25 @@ class BlynkWifi for (int i = 0; i < NUM_MENU_ITEMS; i++) { + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); strncpy(myMenuItems[i].pdata, NO_CONFIG, myMenuItems[i].maxlen); } } strcpy(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE); - #if ( BLYNK_WM_DEBUG > 2) +#if ( BLYNK_WM_DEBUG > 2) for (int i = 0; i < NUM_MENU_ITEMS; i++) { BLYNK_LOG4(BLYNK_F("g:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); } - #endif +#endif // Don't need BlynkGSM_ESP32_config.checkSum = 0; - EEPROM.put(BLYNK_EEPROM_START, BlynkGSM_ESP32_config); - EEPROM_putDynamicData(); - EEPROM.commit(); + saveAllConfigData(); return false; } @@ -1513,13 +1570,24 @@ class BlynkWifi { int calChecksum = calcChecksum(); BlynkGSM_ESP32_config.checkSum = calChecksum; - BLYNK_LOG4(BLYNK_F("SaveEEPROM,sz="), EEPROM.length(), BLYNK_F(",CSum=0x"), String(calChecksum, HEX)) + BLYNK_LOG4(BLYNK_F("SaveEEPROM,sz="), EEPROM_SIZE, BLYNK_F(",CSum=0x"), String(calChecksum, HEX)) EEPROM.put(BLYNK_EEPROM_START, BlynkGSM_ESP32_config); + + EEPROM.commit(); + } + + void saveAllConfigData(void) + { + int calChecksum = calcChecksum(); + BlynkGSM_ESP32_config.checkSum = calChecksum; + BLYNK_LOG4(BLYNK_F("SaveEEPROM,sz="), EEPROM_SIZE, BLYNK_F(",CSum=0x"), String(calChecksum, HEX)) + + EEPROM.put(BLYNK_EEPROM_START, BlynkGSM_ESP32_config); EEPROM_putDynamicData(); EEPROM.commit(); - } + } #endif @@ -1546,66 +1614,45 @@ class BlynkWifi } - bool connectMultiWiFi(int timeout) - { - int sleep_time = 250; - int local_timeout; + uint8_t connectMultiWiFi(void) + { + // For ESP32, this better be 2000 to enable connect the 1st time +#define WIFI_MULTI_CONNECT_WAITING_MS 2000L + + uint8_t status; + BLYNK_LOG1(BLYNK_F("Connecting MultiWifi...")); WiFi.mode(WIFI_STA); - WiFi.persistent(false); + // To check setHostname(); + + int i = 0; + status = wifiMulti.run(); + delay(WIFI_MULTI_CONNECT_WAITING_MS); - // New from Blynk_WM v1.0.5 - if (static_IP != IPAddress(0, 0, 0, 0)) + while ( ( i++ < 10 ) && ( status != WL_CONNECTED ) ) { - BLYNK_LOG1(BLYNK_F("Use StatIP")); - WiFi.config(static_IP, static_GW, static_SN, static_DNS1, static_DNS2); - } - - for (int i = 0; i < NUM_WIFI_CREDENTIALS; i++) - { - if (BlynkGSM_ESP32_config.WiFi_Creds[i].wifi_pw && strlen(BlynkGSM_ESP32_config.WiFi_Creds[i].wifi_pw)) - { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG1(BLYNK_F("con2WF:begin")); -#endif - WiFi.begin(BlynkGSM_ESP32_config.WiFi_Creds[i].wifi_ssid, BlynkGSM_ESP32_config.WiFi_Creds[i].wifi_pw); - } - else - { - WiFi.begin(BlynkGSM_ESP32_config.WiFi_Creds[i].wifi_ssid); - } - - local_timeout = timeout; - - while ( (WiFi.status() != WL_CONNECTED) && (0 < local_timeout) ) - { - delay(sleep_time); - local_timeout -= sleep_time; - } + status = wifiMulti.run(); - if (WiFi.status() == WL_CONNECTED) - { -#if ( BLYNK_WM_DEBUG > 0) - BLYNK_LOG2(BLYNK_F("con2WF:OK, time="), i); -#endif - - displayWiFiData(); - return true; - } + if ( status == WL_CONNECTED ) + break; else - { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("con2WF:failed, time="), i); -#endif - } + delay(WIFI_MULTI_CONNECT_WAITING_MS); } - return (WiFi.status() == WL_CONNECTED); - - } + if ( status == WL_CONNECTED ) + { + BLYNK_LOG2(BLYNK_F("WiFi connected after time: "), i); + BLYNK_LOG4(BLYNK_F("SSID:"), WiFi.SSID(), BLYNK_F(",RSSI="), WiFi.RSSI()); + BLYNK_LOG4(BLYNK_F("Channel:"), WiFi.channel(), BLYNK_F(",IP address:"), WiFi.localIP() ); + } + else + BLYNK_LOG1(BLYNK_F("WiFi not connected")); + return status; + } + // NEW void createHTML(String &root_html_template) { @@ -1711,7 +1758,12 @@ class BlynkWifi if (key == "id") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("id="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_ssid) - 1) strcpy(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_ssid, value.c_str()); else @@ -1719,7 +1771,12 @@ class BlynkWifi } else if (key == "pw") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pw="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_pw) - 1) strcpy(BlynkGSM_ESP32_config.WiFi_Creds[0].wifi_pw, value.c_str()); else @@ -1727,7 +1784,12 @@ class BlynkWifi } else if (key == "id1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("id1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.WiFi_Creds[1].wifi_ssid) - 1) strcpy(BlynkGSM_ESP32_config.WiFi_Creds[1].wifi_ssid, value.c_str()); else @@ -1735,7 +1797,12 @@ class BlynkWifi } else if (key == "pw1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pw1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.WiFi_Creds[1].wifi_pw) - 1) strcpy(BlynkGSM_ESP32_config.WiFi_Creds[1].wifi_pw, value.c_str()); else @@ -1743,7 +1810,12 @@ class BlynkWifi } else if (key == "sv") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("sv="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.Blynk_Creds[0].blynk_server) - 1) strcpy(BlynkGSM_ESP32_config.Blynk_Creds[0].blynk_server, value.c_str()); else @@ -1751,7 +1823,12 @@ class BlynkWifi } else if (key == "wtk") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("wtk="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.Blynk_Creds[0].wifi_blynk_token) - 1) strcpy(BlynkGSM_ESP32_config.Blynk_Creds[0].wifi_blynk_token, value.c_str()); else @@ -1759,7 +1836,12 @@ class BlynkWifi } else if (key == "gtk") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("gtk="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.Blynk_Creds[0].gsm_blynk_token) - 1) strcpy(BlynkGSM_ESP32_config.Blynk_Creds[0].gsm_blynk_token, value.c_str()); else @@ -1767,7 +1849,12 @@ class BlynkWifi } else if (key == "sv1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("sv1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.Blynk_Creds[1].blynk_server) - 1) strcpy(BlynkGSM_ESP32_config.Blynk_Creds[1].blynk_server, value.c_str()); else @@ -1775,7 +1862,12 @@ class BlynkWifi } else if (key == "wtk1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("wtk1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.Blynk_Creds[1].wifi_blynk_token) - 1) strcpy(BlynkGSM_ESP32_config.Blynk_Creds[1].wifi_blynk_token, value.c_str()); else @@ -1783,7 +1875,12 @@ class BlynkWifi } else if (key == "gtk1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("gtk1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.Blynk_Creds[1].gsm_blynk_token) - 1) strcpy(BlynkGSM_ESP32_config.Blynk_Creds[1].gsm_blynk_token, value.c_str()); else @@ -1791,7 +1888,12 @@ class BlynkWifi } else if (key == "apn") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("apn="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.apn) - 1) strcpy(BlynkGSM_ESP32_config.apn, value.c_str()); else @@ -1799,7 +1901,12 @@ class BlynkWifi } else if (key == "usr") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("usr="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.gprsUser) - 1) strcpy(BlynkGSM_ESP32_config.gprsUser, value.c_str()); else @@ -1807,7 +1914,12 @@ class BlynkWifi } else if (key == "pwd") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pwd="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.gprsPass) - 1) strcpy(BlynkGSM_ESP32_config.gprsPass, value.c_str()); else @@ -1815,7 +1927,12 @@ class BlynkWifi } else if (key == "pin") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pin="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.gprsPin) - 1) strcpy(BlynkGSM_ESP32_config.gprsPin, value.c_str()); else @@ -1824,12 +1941,22 @@ class BlynkWifi else if (key == "pt") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pt="), value.toInt()); +#endif + number_items_Updated++; + BlynkGSM_ESP32_config.blynk_port = value.toInt(); } else if (key == "nm") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("nm="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP32_config.board_name) - 1) strcpy(BlynkGSM_ESP32_config.board_name, value.c_str()); else @@ -1853,6 +1980,10 @@ class BlynkWifi strcpy(myMenuItems[i].pdata, value.c_str()); else strncpy(myMenuItems[i].pdata, value.c_str(), myMenuItems[i].maxlen); + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG4(BLYNK_F("h2:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); +#endif } } @@ -1867,7 +1998,7 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("h: UpdEEPROM")); #endif - saveConfigData(); + saveAllConfigData(); BLYNK_LOG1(BLYNK_F("h:Rst")); @@ -1901,9 +2032,13 @@ class BlynkWifi delay(100); static int channel; + // Use random channel if WiFiAPChannel == 0 if (WiFiAPChannel == 0) - channel = random(MAX_WIFI_CHANNEL) + 1; + { + //channel = random(MAX_WIFI_CHANNEL) + 1; + channel = (millis() % MAX_WIFI_CHANNEL) + 1; + } else channel = WiFiAPChannel; @@ -1942,8 +2077,8 @@ static BlynkArduinoClient _blynkTransport_WF(_blynkWifiClient); BlynkWifi Blynk_WF(_blynkTransport_WF); #if defined(Blynk) -#undef Blynk -#define Blynk Blynk_WF + #undef Blynk + #define Blynk Blynk_WF #endif // diff --git a/src/BlynkSimpleEsp8266_GSM_WF.h b/src/BlynkSimpleEsp8266_GSM_WF.h index 4a8b32a..ef156de 100644 --- a/src/BlynkSimpleEsp8266_GSM_WF.h +++ b/src/BlynkSimpleEsp8266_GSM_WF.h @@ -3,10 +3,10 @@ For ESP8266 with GSM/GPRS and WiFi running simultaneously, with WiFi config portal Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -29,6 +29,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef BlynkSimpleESP8266_GSM_WF diff --git a/src/BlynkSimpleEsp8266_GSM_WFM.h b/src/BlynkSimpleEsp8266_GSM_WFM.h index 26bafd2..5aefd8f 100644 --- a/src/BlynkSimpleEsp8266_GSM_WFM.h +++ b/src/BlynkSimpleEsp8266_GSM_WFM.h @@ -3,10 +3,10 @@ For ESP8266 with GSM/GPRS and WiFi running simultaneously, with WiFi config portal Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -29,13 +29,15 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef BlynkSimpleESP8266_GSM_WFM #define BlynkSimpleESP8266_GSM_WFM #ifndef ESP8266 -#error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting. + #error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting. #endif #define BLYNK_SEND_ATOMIC @@ -44,8 +46,8 @@ #define BLYNK_GSM_ESP8266_WFM_DEBUG 3 #ifdef BLYNK_TIMEOUT_MS -#undef BLYNK_TIMEOUT_MS -#define BLYNK_TIMEOUT_MS 30000UL + #undef BLYNK_TIMEOUT_MS + #define BLYNK_TIMEOUT_MS 30000UL #endif #include @@ -55,6 +57,7 @@ #endif #include +#include #include #include @@ -65,16 +68,16 @@ //default to use EEPROM, otherwise, use LittleFS or SPIFFS #if ( USE_LITTLEFS || USE_SPIFFS ) -#if USE_LITTLEFS -#define FileFS LittleFS -#else -#define FileFS SPIFFS -#endif + #if USE_LITTLEFS + #define FileFS LittleFS + #else + #define FileFS SPIFFS + #endif -#include -#include + #include + #include #else -#include + #include #endif ///////// NEW for DRD ///////////// @@ -87,24 +90,24 @@ #define ESP8266_DRD_USE_RTC false //true #if ( USE_LITTLEFS || USE_SPIFFS ) -#define ESP_DRD_USE_EEPROM false + #define ESP_DRD_USE_EEPROM false -#if USE_LITTLEFS -#define ESP_DRD_USE_LITTLEFS true -#define ESP_DRD_USE_SPIFFS false -#else -#define ESP_DRD_USE_LITTLEFS false -#define ESP_DRD_USE_SPIFFS true -#endif + #if USE_LITTLEFS + #define ESP_DRD_USE_LITTLEFS true + #define ESP_DRD_USE_SPIFFS false + #else + #define ESP_DRD_USE_LITTLEFS false + #define ESP_DRD_USE_SPIFFS true + #endif #else -#define ESP_DRD_USE_EEPROM true -#define ESP_DRD_USE_LITTLEFS false -#define ESP_DRD_USE_SPIFFS false + #define ESP_DRD_USE_EEPROM true + #define ESP_DRD_USE_LITTLEFS false + #define ESP_DRD_USE_SPIFFS false #endif #ifndef DOUBLERESETDETECTOR_DEBUG -#define DOUBLERESETDETECTOR_DEBUG false + #define DOUBLERESETDETECTOR_DEBUG false #endif #include //https://github.com/khoih-prog/ESP_DoubleResetDetector @@ -125,7 +128,6 @@ DoubleResetDetector* drd; #define LED_ON LOW #define LED_OFF HIGH -//NEW #define MAX_ID_LEN 5 #define MAX_DISPLAY_NAME_LEN 16 @@ -136,14 +138,12 @@ typedef struct char *pdata; uint8_t maxlen; } MenuItem; -// -///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; #define SSID_MAX_LEN 32 -//From v1.0.10, WPA2 passwords can be up to 63 characters long. +// WPA2 passwords can be up to 63 characters long. #define PASS_MAX_LEN 64 typedef struct @@ -188,7 +188,6 @@ typedef struct Configuration uint16_t CONFIG_DATA_SIZE = sizeof(Blynk_WF_Configuration); -///New from v1.0.13 extern bool LOAD_DEFAULT_CONFIG_DATA; extern Blynk_WF_Configuration defaultConfig; @@ -252,7 +251,6 @@ class BlynkWifi BLYNK_LOG2(BLYNK_F("Con2:"), ssid); WiFi.mode(WIFI_STA); - // New from Blynk_WM v1.0.5 if (static_IP != IPAddress(0, 0, 0, 0)) { BLYNK_LOG1(BLYNK_F("Use statIP")); @@ -336,8 +334,9 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("Double Reset Detected")); #endif noConfigPortal = false; - } + } //// New DRD //// + #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("======= Start Default Config Data =======")); displayConfigData(defaultConfig); @@ -359,11 +358,7 @@ class BlynkWifi getRFC952_hostname(iHostname); } - BLYNK_LOG2(BLYNK_F("Hostname="), RFC952_hostname); - -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG1(noConfigPortal? BLYNK_F("bg: noConfigPortal = true") : BLYNK_F("bg: noConfigPortal = false")); -#endif + BLYNK_LOG2(BLYNK_F("Hostname="), RFC952_hostname); //// New DRD //// // noConfigPortal when getConfigData() OK and no DRD'ed @@ -372,12 +367,19 @@ class BlynkWifi { hadConfigData = true; - #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(noConfigPortal? BLYNK_F("bg: noConfigPortal = true") : BLYNK_F("bg: noConfigPortal = false")); #endif - if (connectMultiWiFi(TIMEOUT_RECONNECT_WIFI)) + for (int i = 0; i < NUM_WIFI_CREDENTIALS; i++) + { + wifiMulti.addAP(BlynkGSM_ESP8266_config.WiFi_Creds[i].wifi_ssid, BlynkGSM_ESP8266_config.WiFi_Creds[i].wifi_pw); + } + + //Base::begin(BlynkGSM_ESP8266_config.blynk_token); + //this->conn.begin(BlynkGSM_ESP8266_config.blynk_server, BlynkGSM_ESP8266_config.blynk_port); + + if (connectMultiWiFi() == WL_CONNECTED) { BLYNK_LOG1(BLYNK_F("bg: WiFi OK. Try Blynk")); @@ -405,29 +407,29 @@ class BlynkWifi } } else - { + { BLYNK_LOG2(BLYNK_F("bg: Stay forever in config portal."), noConfigPortal ? BLYNK_F("No configDat") : BLYNK_F("DRD detected")); // failed to connect to Blynk server, will start configuration mode hadConfigData = false; startConfigurationMode(); - } + } } #ifndef TIMEOUT_RECONNECT_WIFI -#define TIMEOUT_RECONNECT_WIFI 10000L + #define TIMEOUT_RECONNECT_WIFI 10000L #else // Force range of user-defined TIMEOUT_RECONNECT_WIFI between 10-60s -#if (TIMEOUT_RECONNECT_WIFI < 10000L) -#warning TIMEOUT_RECONNECT_WIFI too low. Reseting to 10000 -#undef TIMEOUT_RECONNECT_WIFI -#define TIMEOUT_RECONNECT_WIFI 10000L -#elif (TIMEOUT_RECONNECT_WIFI > 60000L) -#warning TIMEOUT_RECONNECT_WIFI too high. Reseting to 60000 -#undef TIMEOUT_RECONNECT_WIFI -#define TIMEOUT_RECONNECT_WIFI 60000L -#endif + #if (TIMEOUT_RECONNECT_WIFI < 10000L) + #warning TIMEOUT_RECONNECT_WIFI too low. Reseting to 10000 + #undef TIMEOUT_RECONNECT_WIFI + #define TIMEOUT_RECONNECT_WIFI 10000L + #elif (TIMEOUT_RECONNECT_WIFI > 60000L) + #warning TIMEOUT_RECONNECT_WIFI too high. Reseting to 60000 + #undef TIMEOUT_RECONNECT_WIFI + #define TIMEOUT_RECONNECT_WIFI 60000L + #endif #endif #ifndef RESET_IF_CONFIG_TIMEOUT @@ -435,18 +437,18 @@ class BlynkWifi #endif #ifndef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET -#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 10 + #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 10 #else // Force range of user-defined TIMES_BEFORE_RESET between 2-100 -#if (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET < 2) -#warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too low. Reseting to 2 -#undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET -#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 2 -#elif (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET > 100) -#warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too high. Reseting to 100 -#undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET -#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 100 -#endif + #if (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET < 2) + #warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too low. Reseting to 2 + #undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET + #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 2 + #elif (CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET > 100) + #warning CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET too high. Reseting to 100 + #undef CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET + #define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 100 + #endif #endif void run() @@ -471,9 +473,7 @@ class BlynkWifi retryTimes = 0; if (server) - { server->handleClient(); - } return; } @@ -499,7 +499,8 @@ class BlynkWifi if ( WiFi.status() != WL_CONNECTED ) { BLYNK_LOG1(BLYNK_F("r:Wlost.ReconW+B")); - if (connectMultiWiFi(TIMEOUT_RECONNECT_WIFI)) + + if (connectMultiWiFi() == WL_CONNECTED) { // turn the LED_BUILTIN OFF to tell us we exit configuration mode. digitalWrite(LED_BUILTIN, LED_OFF); @@ -537,9 +538,14 @@ class BlynkWifi digitalWrite(LED_BUILTIN, LED_OFF); } - if (this->connected()) + Base::run(); + } + + void setHostname(void) + { + if (RFC952_hostname[0] != 0) { - Base::run(); + WiFi.hostname(RFC952_hostname); } } @@ -555,7 +561,7 @@ class BlynkWifi } #define MIN_WIFI_CHANNEL 1 -#define MAX_WIFI_CHANNEL 13 +#define MAX_WIFI_CHANNEL 12 int setConfigPortalChannel(int channel = 1) { @@ -591,11 +597,6 @@ class BlynkWifi static_DNS2 = dns_address_2; } - String getBoardName() - { - return (String(BlynkGSM_ESP8266_config.board_name)); - } - String getWiFiSSID(uint8_t index) { if (index >= NUM_WIFI_CREDENTIALS) @@ -653,35 +654,50 @@ class BlynkWifi String getAPN() { + if (!hadConfigData) + getConfigData(); + return (String(BlynkGSM_ESP8266_config.apn)); } String getGPRSUser() { + if (!hadConfigData) + getConfigData(); + return (String(BlynkGSM_ESP8266_config.gprsUser)); } String getGPRSPass() { + if (!hadConfigData) + getConfigData(); + return (BlynkGSM_ESP8266_config.gprsPass); } String getGPRSPIN() { + if (!hadConfigData) + getConfigData(); + return (BlynkGSM_ESP8266_config.gprsPin); } - - int getHWPort() + + String getBoardName() { - return (BlynkGSM_ESP8266_config.blynk_port); + if (!hadConfigData) + getConfigData(); + + return (String(BlynkGSM_ESP8266_config.board_name)); } - - void setHostname(void) + + int getHWPort() { - if (RFC952_hostname[0] != 0) - { - WiFi.hostname(RFC952_hostname); - } + if (!hadConfigData) + getConfigData(); + + return (BlynkGSM_ESP8266_config.blynk_port); } Blynk_WF_Configuration* getFullConfigData(Blynk_WF_Configuration *configData) @@ -706,6 +722,8 @@ class BlynkWifi ESP8266WebServer *server; bool configuration_mode = false; + ESP8266WiFiMulti wifiMulti; + unsigned long configTimeout; bool hadConfigData = false; @@ -716,13 +734,13 @@ class BlynkWifi uint16_t totalDataSize = 0; - // For Config Portal, from Blynk_WM v1.0.5 + // For Config Portal IPAddress portal_apIP = IPAddress(192, 168, 4, 1); String portal_ssid = ""; String portal_pass = ""; - // For static IP, from Blynk_WM v1.0.5 + // For static IP IPAddress static_IP = IPAddress(0, 0, 0, 0); IPAddress static_GW = IPAddress(0, 0, 0, 0); IPAddress static_SN = IPAddress(255, 255, 255, 0); @@ -850,7 +868,7 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("ChkCrR: Error can't allocate buffer.")); return false; } -#if ( BLYNK_WM_DEBUG > 2) +#if ( BLYNK_WM_DEBUG > 2) else { BLYNK_LOG2(BLYNK_F("ChkCrR: Buffer allocated, sz="), maxBufferLength + 1); @@ -882,13 +900,16 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("OK")); file.close(); - BLYNK_LOG4(F("CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); // Free buffer if (readBuffer != NULL) { free(readBuffer); + +#if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Buffer freed")); +#endif } if ( checkSum != readCheckSum) @@ -948,7 +969,7 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("OK")); file.close(); - BLYNK_LOG4(F("CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); if ( checkSum != readCheckSum) { @@ -999,7 +1020,7 @@ class BlynkWifi BLYNK_LOG1(BLYNK_F("failed")); } - BLYNK_LOG2(F("CrWCSum="), String(checkSum, HEX)); + BLYNK_LOG2(F("CrWCSum=0x"), String(checkSum, HEX)); // Trying open redundant Auth file file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "w"); @@ -1103,65 +1124,91 @@ class BlynkWifi saveDynamicData(); } + + void saveAllConfigData(void) + { + saveConfigData(); + saveDynamicData(); + } // Return false if init new EEPROM, LittleFS or SPIFFS. No more need trying to connect. Go directly to config mode bool getConfigData() { - bool dynamicDataValid; + bool dynamicDataValid; + int calChecksum; hadConfigData = false; if (!FileFS.begin()) { + FileFS.format(); + + if (!FileFS.begin()) + { #if USE_LITTLEFS - BLYNK_LOG1(BLYNK_F("LittleFS failed!. Please use SPIFFS or EEPROM.")); + BLYNK_LOG1(BLYNK_F("LittleFS failed!. Please use SPIFFS or EEPROM.")); #else - BLYNK_LOG1(BLYNK_F("SPIFFS failed!. Please use LittleFS or EEPROM.")); -#endif - return false; + BLYNK_LOG1(BLYNK_F("SPIFFS failed!. Please use LittleFS or EEPROM.")); +#endif + return false; + } } - if ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) + if (LOAD_DEFAULT_CONFIG_DATA) + { + // Load Config Data from Sketch + memcpy(&BlynkGSM_ESP8266_config, &defaultConfig, sizeof(BlynkGSM_ESP8266_config)); + strcpy(BlynkGSM_ESP8266_config.header, BLYNK_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveAllConfigData(); + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("======= Start Loaded Config Data =======")); + displayConfigData(BlynkGSM_ESP8266_config); +#endif + + // Don't need Config Portal anymore + return true; + } + else if ( ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) && + ( FileFS.exists(CREDENTIALS_FILENAME) || FileFS.exists(CREDENTIALS_FILENAME_BACKUP) ) ) { // if config file exists, load loadConfigData(); + #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("======= Start Stored Config Data =======")); displayConfigData(BlynkGSM_ESP8266_config); -#endif - } - - int calChecksum = calcChecksum(); +#endif - BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), - BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP8266_config.checkSum, HEX)); + calChecksum = calcChecksum(); - if (LOAD_DEFAULT_CONFIG_DATA) - { - // Load default dynamicData, if checkSum OK => valid data => load - // otherwise, use default in sketch and just assume it's OK - if (checkDynamicData()) + BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), + BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP8266_config.checkSum, HEX)); + + // Load dynamic data + dynamicDataValid = loadDynamicData(); + + if (dynamicDataValid) { #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Valid Stored Dynamic Data")); -#endif - loadDynamicData(); - dynamicDataValid = true; +#endif } #if ( BLYNK_WM_DEBUG > 2) else { - BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data")); - dynamicDataValid = false; + BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data. Ignored")); } -#endif +#endif } - else - { - dynamicDataValid = loadDynamicData(); - } + else + { + // Not loading Default config data, but having no config file => Config Portal + return false; + } - if ( (strncmp(BlynkGSM_ESP8266_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) || (calChecksum != BlynkGSM_ESP8266_config.checkSum) || !dynamicDataValid ) @@ -1177,13 +1224,7 @@ class BlynkWifi else { memset(&BlynkGSM_ESP8266_config, 0, sizeof(BlynkGSM_ESP8266_config)); - - for (int i = 0; i < NUM_MENU_ITEMS; i++) - { - // Actual size of pdata is [maxlen + 1] - memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); - } - + strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_ssid, NO_CONFIG); strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_pw, NO_CONFIG); strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[1].wifi_ssid, NO_CONFIG); @@ -1203,23 +1244,25 @@ class BlynkWifi for (int i = 0; i < NUM_MENU_ITEMS; i++) { + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); strncpy(myMenuItems[i].pdata, NO_CONFIG, myMenuItems[i].maxlen); } } strcpy(BlynkGSM_ESP8266_config.header, BLYNK_BOARD_TYPE); - #if ( BLYNK_WM_DEBUG > 2) +#if ( BLYNK_WM_DEBUG > 2) for (int i = 0; i < NUM_MENU_ITEMS; i++) { BLYNK_LOG4(BLYNK_F("g:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); } - #endif +#endif // Don't need BlynkGSM_ESP8266_config.checkSum = 0; - saveConfigData(); + saveAllConfigData(); return false; } @@ -1252,32 +1295,32 @@ class BlynkWifi #else -#ifndef EEPROM_SIZE -#define EEPROM_SIZE 4096 -#else -#if (EEPROM_SIZE > 4096) -#warning EEPROM_SIZE must be <= 4096. Reset to 4096 -#undef EEPROM_SIZE -#define EEPROM_SIZE 4096 -#endif -// FLAG_DATA_SIZE is 4, to store DRD flag -#if (EEPROM_SIZE < FLAG_DATA_SIZE + CONFIG_DATA_SIZE) -#warning EEPROM_SIZE must be > CONFIG_DATA_SIZE. Reset to 4096 -#undef EEPROM_SIZE -#define EEPROM_SIZE 4096 -#endif -#endif - -#ifndef EEPROM_START -#define EEPROM_START 0 -#else -#if (EEPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE) -#error EPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE. Please adjust. -#endif -#endif - -// Stating positon to store BlynkGSM_ESP8266_config -#define BLYNK_EEPROM_START (EEPROM_START + FLAG_DATA_SIZE) + #ifndef EEPROM_SIZE + #define EEPROM_SIZE 4096 + #else + #if (EEPROM_SIZE > 4096) + #warning EEPROM_SIZE must be <= 4096. Reset to 4096 + #undef EEPROM_SIZE + #define EEPROM_SIZE 4096 + #endif + // FLAG_DATA_SIZE is 4, to store DRD flag + #if (EEPROM_SIZE < FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + #warning EEPROM_SIZE must be > CONFIG_DATA_SIZE. Reset to 4096 + #undef EEPROM_SIZE + #define EEPROM_SIZE 4096 + #endif + #endif + + #ifndef EEPROM_START + #define EEPROM_START 0 + #else + #if (EEPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE) + #error EPROM_START + FLAG_DATA_SIZE + CONFIG_DATA_SIZE > EEPROM_SIZE. Please adjust. + #endif + #endif + + // Stating positon to store BlynkGSM_ESP8266_config + #define BLYNK_EEPROM_START (EEPROM_START + FLAG_DATA_SIZE) bool checkDynamicData(void) @@ -1330,7 +1373,7 @@ class BlynkWifi EEPROM.get(offset, readCheckSum); - BLYNK_LOG4(F("ChkCrR:CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("ChkCrR:CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); if ( checkSum != readCheckSum) { @@ -1370,7 +1413,7 @@ class BlynkWifi EEPROM.get(offset, readCheckSum); - BLYNK_LOG4(F("CrCCsum="), String(checkSum, HEX), F(",CrRCsum="), String(readCheckSum, HEX)); + BLYNK_LOG4(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); if ( checkSum != readCheckSum) { @@ -1404,54 +1447,68 @@ class BlynkWifi EEPROM.put(offset, checkSum); //EEPROM.commit(); - BLYNK_LOG2(F("CrWCSum="), String(checkSum, HEX)); + BLYNK_LOG2(F("CrWCSum=0x"), String(checkSum, HEX)); } bool getConfigData() { - bool dynamicDataValid; + bool dynamicDataValid; + int calChecksum; hadConfigData = false; EEPROM.begin(EEPROM_SIZE); BLYNK_LOG2(BLYNK_F("EEPROMsz:"), EEPROM_SIZE); - EEPROM.get(BLYNK_EEPROM_START, BlynkGSM_ESP8266_config); + + if (LOAD_DEFAULT_CONFIG_DATA) + { + // Load Config Data from Sketch + memcpy(&BlynkGSM_ESP8266_config, &defaultConfig, sizeof(BlynkGSM_ESP8266_config)); + strcpy(BlynkGSM_ESP8266_config.header, BLYNK_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveAllConfigData(); + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG1(BLYNK_F("======= Start Loaded Config Data =======")); + displayConfigData(BlynkGSM_ESP8266_config); +#endif + // Don't need Config Portal anymore + return true; + } + else + { + // Load data from EEPROM + EEPROM.get(BLYNK_EEPROM_START, BlynkGSM_ESP8266_config); + #if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG1(BLYNK_F("======= Start Stored Config Data =======")); - displayConfigData(BlynkGSM_ESP8266_config); -#endif + BLYNK_LOG1(BLYNK_F("======= Start Stored Config Data =======")); + displayConfigData(BlynkGSM_ESP8266_config); +#endif - int calChecksum = calcChecksum(); + calChecksum = calcChecksum(); - BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), - BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP8266_config.checkSum, HEX)); + BLYNK_LOG4(BLYNK_F("CCSum=0x"), String(calChecksum, HEX), + BLYNK_F(",RCSum=0x"), String(BlynkGSM_ESP8266_config.checkSum, HEX)); - if (LOAD_DEFAULT_CONFIG_DATA) - { - // Load default dynamicData, if checkSum OK => valid data => load - // otherwise, use default in sketch and just assume it's OK - if (checkDynamicData()) + // Load dynamic data from EEPROM + dynamicDataValid = EEPROM_getDynamicData(); + + if (dynamicDataValid) { #if ( BLYNK_WM_DEBUG > 2) BLYNK_LOG1(BLYNK_F("Valid Stored Dynamic Data")); #endif - EEPROM_getDynamicData(); - dynamicDataValid = true; } #if ( BLYNK_WM_DEBUG > 2) else { BLYNK_LOG1(BLYNK_F("Invalid Stored Dynamic Data. Ignored")); - dynamicDataValid = false; } -#endif +#endif } - else - { - dynamicDataValid = EEPROM_getDynamicData(); - } - + if ( (strncmp(BlynkGSM_ESP8266_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) || (calChecksum != BlynkGSM_ESP8266_config.checkSum) || !dynamicDataValid ) { @@ -1466,13 +1523,7 @@ class BlynkWifi else { memset(&BlynkGSM_ESP8266_config, 0, sizeof(BlynkGSM_ESP8266_config)); - - for (int i = 0; i < NUM_MENU_ITEMS; i++) - { - // Actual size of pdata is [maxlen + 1] - memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); - } - + strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_ssid, NO_CONFIG); strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_pw, NO_CONFIG); strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[1].wifi_ssid, NO_CONFIG); @@ -1492,25 +1543,25 @@ class BlynkWifi for (int i = 0; i < NUM_MENU_ITEMS; i++) { + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); strncpy(myMenuItems[i].pdata, NO_CONFIG, myMenuItems[i].maxlen); } } strcpy(BlynkGSM_ESP8266_config.header, BLYNK_BOARD_TYPE); - #if ( BLYNK_WM_DEBUG > 2) +#if ( BLYNK_WM_DEBUG > 2) for (int i = 0; i < NUM_MENU_ITEMS; i++) { BLYNK_LOG4(BLYNK_F("g:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); } - #endif +#endif // Don't need BlynkGSM_ESP8266_config.checkSum = 0; - EEPROM.put(BLYNK_EEPROM_START, BlynkGSM_ESP8266_config); - EEPROM_putDynamicData(); - EEPROM.commit(); + saveAllConfigData(); return false; } @@ -1550,7 +1601,19 @@ class BlynkWifi EEPROM_putDynamicData(); EEPROM.commit(); - } + } + + void saveAllConfigData(void) + { + int calChecksum = calcChecksum(); + BlynkGSM_ESP8266_config.checkSum = calChecksum; + BLYNK_LOG4(BLYNK_F("SaveEEPROM,sz="), EEPROM_SIZE, BLYNK_F(",CSum=0x"), String(calChecksum, HEX)) + + EEPROM.put(BLYNK_EEPROM_START, BlynkGSM_ESP8266_config); + EEPROM_putDynamicData(); + + EEPROM.commit(); + } #endif @@ -1577,64 +1640,42 @@ class BlynkWifi } - bool connectMultiWiFi(int timeout) - { - int sleep_time = 250; - int local_timeout; + uint8_t connectMultiWiFi(void) + { + // For ESP8266, this better be 3000 to enable connect the 1st time +#define WIFI_MULTI_CONNECT_WAITING_MS 3000L + + uint8_t status; + BLYNK_LOG1(BLYNK_F("Connecting MultiWifi...")); WiFi.mode(WIFI_STA); - WiFi.persistent(false); setHostname(); + + int i = 0; + status = wifiMulti.run(); + delay(WIFI_MULTI_CONNECT_WAITING_MS); - // New from Blynk_WM v1.0.5 - if (static_IP != IPAddress(0, 0, 0, 0)) + while ( ( i++ < 10 ) && ( status != WL_CONNECTED ) ) { - BLYNK_LOG1(BLYNK_F("Use StatIP")); - WiFi.config(static_IP, static_GW, static_SN, static_DNS1, static_DNS2); - } - - for (int i = 0; i < NUM_WIFI_CREDENTIALS; i++) - { - if (BlynkGSM_ESP8266_config.WiFi_Creds[i].wifi_pw && strlen(BlynkGSM_ESP8266_config.WiFi_Creds[i].wifi_pw)) - { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG1(BLYNK_F("con2WF:begin")); -#endif - WiFi.begin(BlynkGSM_ESP8266_config.WiFi_Creds[i].wifi_ssid, BlynkGSM_ESP8266_config.WiFi_Creds[i].wifi_pw); - } - else - { - WiFi.begin(BlynkGSM_ESP8266_config.WiFi_Creds[i].wifi_ssid); - } - - local_timeout = timeout; - - while ( (WiFi.status() != WL_CONNECTED) && (0 < local_timeout) ) - { - delay(sleep_time); - local_timeout -= sleep_time; - } + status = wifiMulti.run(); - if (WiFi.status() == WL_CONNECTED) - { -#if ( BLYNK_WM_DEBUG > 0) - BLYNK_LOG2(BLYNK_F("con2WF:OK, time="), i); -#endif - - displayWiFiData(); - return true; - } + if ( status == WL_CONNECTED ) + break; else - { -#if ( BLYNK_WM_DEBUG > 2) - BLYNK_LOG2(BLYNK_F("con2WF:failed, time="), i); -#endif - } + delay(WIFI_MULTI_CONNECT_WAITING_MS); } - return (WiFi.status() == WL_CONNECTED); - + if ( status == WL_CONNECTED ) + { + BLYNK_LOG2(BLYNK_F("WiFi connected after time: "), i); + BLYNK_LOG4(BLYNK_F("SSID="), WiFi.SSID(), BLYNK_F(",RSSI="), WiFi.RSSI()); + BLYNK_LOG4(BLYNK_F("Channel="), WiFi.channel(), BLYNK_F(",IP="), WiFi.localIP() ); + } + else + BLYNK_LOG1(BLYNK_F("WiFi not connected")); + + return status; } // NEW @@ -1690,16 +1731,16 @@ class BlynkWifi // Reset configTimeout to stay here until finished. configTimeout = 0; - + if ( RFC952_hostname[0] != 0 ) { // Replace only if Hostname is valid - result.replace("BlynkGSM_ESP8266", RFC952_hostname); + result.replace("BlynkGSM_ESP32", RFC952_hostname); } else if ( BlynkGSM_ESP8266_config.board_name[0] != 0 ) { // Or replace only if board_name is valid. Otherwise, keep intact - result.replace("BlynkGSM_ESP8266", BlynkGSM_ESP8266_config.board_name); + result.replace("BlynkGSM_ESP32", BlynkGSM_ESP8266_config.board_name); } result.replace("[[id]]", BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_ssid); @@ -1722,7 +1763,6 @@ class BlynkWifi result.replace("[[pt]]", String(BlynkGSM_ESP8266_config.blynk_port)); result.replace("[[nm]]", BlynkGSM_ESP8266_config.board_name); - for (int i = 0; i < NUM_MENU_ITEMS; i++) { @@ -1743,7 +1783,12 @@ class BlynkWifi if (key == "id") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("id="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_ssid) - 1) strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_ssid, value.c_str()); else @@ -1751,7 +1796,12 @@ class BlynkWifi } else if (key == "pw") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pw="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_pw) - 1) strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[0].wifi_pw, value.c_str()); else @@ -1759,7 +1809,12 @@ class BlynkWifi } else if (key == "id1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("id1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.WiFi_Creds[1].wifi_ssid) - 1) strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[1].wifi_ssid, value.c_str()); else @@ -1767,7 +1822,12 @@ class BlynkWifi } else if (key == "pw1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pw1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.WiFi_Creds[1].wifi_pw) - 1) strcpy(BlynkGSM_ESP8266_config.WiFi_Creds[1].wifi_pw, value.c_str()); else @@ -1775,7 +1835,12 @@ class BlynkWifi } else if (key == "sv") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("sv="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.Blynk_Creds[0].blynk_server) - 1) strcpy(BlynkGSM_ESP8266_config.Blynk_Creds[0].blynk_server, value.c_str()); else @@ -1783,7 +1848,12 @@ class BlynkWifi } else if (key == "wtk") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("wtk="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.Blynk_Creds[0].wifi_blynk_token) - 1) strcpy(BlynkGSM_ESP8266_config.Blynk_Creds[0].wifi_blynk_token, value.c_str()); else @@ -1791,7 +1861,12 @@ class BlynkWifi } else if (key == "gtk") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("gtk="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.Blynk_Creds[0].gsm_blynk_token) - 1) strcpy(BlynkGSM_ESP8266_config.Blynk_Creds[0].gsm_blynk_token, value.c_str()); else @@ -1799,7 +1874,12 @@ class BlynkWifi } else if (key == "sv1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("sv1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.Blynk_Creds[1].blynk_server) - 1) strcpy(BlynkGSM_ESP8266_config.Blynk_Creds[1].blynk_server, value.c_str()); else @@ -1807,7 +1887,12 @@ class BlynkWifi } else if (key == "wtk1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("wtk1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.Blynk_Creds[1].wifi_blynk_token) - 1) strcpy(BlynkGSM_ESP8266_config.Blynk_Creds[1].wifi_blynk_token, value.c_str()); else @@ -1815,7 +1900,12 @@ class BlynkWifi } else if (key == "gtk1") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("gtk1="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.Blynk_Creds[1].gsm_blynk_token) - 1) strcpy(BlynkGSM_ESP8266_config.Blynk_Creds[1].gsm_blynk_token, value.c_str()); else @@ -1823,7 +1913,12 @@ class BlynkWifi } else if (key == "apn") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("apn="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.apn) - 1) strcpy(BlynkGSM_ESP8266_config.apn, value.c_str()); else @@ -1831,7 +1926,12 @@ class BlynkWifi } else if (key == "usr") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("usr="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.gprsUser) - 1) strcpy(BlynkGSM_ESP8266_config.gprsUser, value.c_str()); else @@ -1839,7 +1939,12 @@ class BlynkWifi } else if (key == "pwd") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pwd="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.gprsPass) - 1) strcpy(BlynkGSM_ESP8266_config.gprsPass, value.c_str()); else @@ -1847,7 +1952,12 @@ class BlynkWifi } else if (key == "pin") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pin="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.gprsPin) - 1) strcpy(BlynkGSM_ESP8266_config.gprsPin, value.c_str()); else @@ -1856,12 +1966,22 @@ class BlynkWifi else if (key == "pt") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("pt="), value.toInt()); +#endif + number_items_Updated++; + BlynkGSM_ESP8266_config.blynk_port = value.toInt(); } else if (key == "nm") { +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG2(BLYNK_F("nm="), value.c_str()); +#endif + number_items_Updated++; + if (strlen(value.c_str()) < sizeof(BlynkGSM_ESP8266_config.board_name) - 1) strcpy(BlynkGSM_ESP8266_config.board_name, value.c_str()); else @@ -1872,7 +1992,10 @@ class BlynkWifi { if (key == myMenuItems[i].id) { - //BLYNK_LOG4(F("h:"), myMenuItems[i].id, F("="), value.c_str() ); +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG4(F("h:"), myMenuItems[i].id, F("="), value.c_str() ); +#endif + number_items_Updated++; // Actual size of pdata is [maxlen + 1] @@ -1882,6 +2005,10 @@ class BlynkWifi strcpy(myMenuItems[i].pdata, value.c_str()); else strncpy(myMenuItems[i].pdata, value.c_str(), myMenuItems[i].maxlen); + +#if ( BLYNK_WM_DEBUG > 2) + BLYNK_LOG4(BLYNK_F("h2:myMenuItems["), i, BLYNK_F("]="), myMenuItems[i].pdata ); +#endif } } @@ -1890,15 +2017,13 @@ class BlynkWifi // NEW if (number_items_Updated == NUM_CONFIGURABLE_ITEMS + NUM_MENU_ITEMS) { -#if USE_LITTLEFS - BLYNK_LOG2(BLYNK_F("h:UpdLittleFS:"), CONFIG_FILENAME); -#elif USE_SPIFFS +#if USE_SPIFFS BLYNK_LOG2(BLYNK_F("h:UpdSPIFFS:"), CONFIG_FILENAME); #else - BLYNK_LOG1(BLYNK_F("h:UpdEEPROM")); + BLYNK_LOG1(BLYNK_F("h: UpdEEPROM")); #endif - saveConfigData(); + saveAllConfigData(); BLYNK_LOG1(BLYNK_F("h:Rst")); @@ -1932,9 +2057,13 @@ class BlynkWifi delay(100); static int channel; + // Use random channel if WiFiAPChannel == 0 if (WiFiAPChannel == 0) - channel = random(MAX_WIFI_CHANNEL) + 1; + { + //channel = random(MAX_WIFI_CHANNEL) + 1; + channel = (millis() % MAX_WIFI_CHANNEL) + 1; + } else channel = WiFiAPChannel; @@ -1973,8 +2102,8 @@ static BlynkArduinoClient _blynkTransport_WF(_blynkWifiClient); BlynkWifi Blynk_WF(_blynkTransport_WF); #if defined(Blynk) -#undef Blynk -#define Blynk Blynk_WF + #undef Blynk + #define Blynk Blynk_WF #endif // diff --git a/src/BlynkSimpleTinyGSM_M.h b/src/BlynkSimpleTinyGSM_M.h index 398dea3..6a81d48 100644 --- a/src/BlynkSimpleTinyGSM_M.h +++ b/src/BlynkSimpleTinyGSM_M.h @@ -3,10 +3,10 @@ For ESP32 / ESP8266 with GSM/GPRS and WiFi running simultaneously, with WiFi config portal Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal. - Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases - Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager + Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases + Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_Manager Licensed under MIT license - Version: 1.0.9 + Version: 1.0.10 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -29,6 +29,8 @@ 1.0.8 K Hoang 14/04/2020 Fix bug. 1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title, Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM + 1.0.10 K Hoang 26/08/2020 Use MultiWiFi. Auto format SPIFFS/LittleFS for first time usage. + Fix bug and logic of USE_DEFAULT_CONFIG_DATA. *****************************************************************************************************************************/ #ifndef BlynkSimpleTinyGSM_M_h