diff --git a/README.md b/README.md index aa41718..1dfa87b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,31 @@ [![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. + +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. + +- This is the new library, adding to the current Blynk_WiFiManager. It's designed to help you eliminate `hardcoding` your Blynk credentials in `ESP32 and ESP8266` boards using GSM shield (SIM800, SIM900, etc). + +- You can update GSM Modem and Blynk Credentials any time you need to change via Configure Portal. Data are saved in LittleFS / SPIFFS or configurable locations in EEPROM. + +New recent features: + +- Optional default ***Credentials as well as Dynamic parameters to be optionally autoloaded into Config Portal*** to use or change instead of manually input. +- ***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. + + +### Major Releases v1.0.9 + +1. Add MultiWiFi/Blynk features for WiFi +2. Add MultiBlynk feature for GPRS/GSM +3. Add DoubleResetDetector (DRD) feature. +4. Update to use LittleFS for ESP8266 core 2.7.1+ to replace deprecated SPIFFS on ESP8266 +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. @@ -27,21 +52,21 @@ ### Releases v1.0.5 -1. Add more modem supports. Thanks to new [TinyGSM library v0.10.1+](https://github.com/vshymanskyy/TinyGSM). +1. Add more modem supports. Thanks to new [TinyGSM library v0.10.5+](https://github.com/vshymanskyy/TinyGSM). ## Supported modems - SIMCom SIM800 series (SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868) - SIMCom SIM900 series (SIM900A, SIM900D, SIM908, SIM968) -- SIMCom WCDMA/HSPA/HSPA+ Modules (SIM5360, SIM5320, SIM5300E, SIM5300EA) +- SIMCom WCDMA/HSPA/HSPA+ Modules (SIM5360, SIM5320, SIM5300E, SIM5300E/A) - SIMCom LTE Modules (SIM7100E, SIM7500E, SIM7500A, SIM7600C, SIM7600E) -- SIMCom SIM7000E CAT-M1/NB-IoT Module +- SIMCom SIM7000E/A/G CAT-M1/NB-IoT Module - AI-Thinker A6, A6C, A7, A20 - ESP8266 (AT commands interface, similar to GSM modems) - Digi XBee WiFi and Cellular (using XBee command mode) - Neoway M590 - u-blox 2G, 3G, 4G, and LTE Cat1 Cellular Modems (many modules including LEON-G100, LISA-U2xx, SARA-G3xx, SARA-U2xx, TOBY-L2xx, LARA-R2xx, MPCI-L2xx) -- u-blox LTE-M Modems (SARA-R4xx, SARA-N4xx, _but NOT SARA-N2xx_) +- u-blox LTE-M/NB-IoT Modems (SARA-R4xx, SARA-N4xx, _but NOT SARA-N2xx_) - Sequans Monarch LTE Cat M1/NB1 (VZM20Q) - Quectel BG96 - Quectel M95 @@ -69,18 +94,14 @@ More modems may be supported later: 1. Enhance Config Portal GUI. 2. Reduce code size. -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 the new library, adding to the current Blynk_WiFiManager. It's designed to help you eliminate `hardcoding` your Blynk credentials in `ESP32 and ESP8266` boards using GSM shield (SIM800, SIM900, etc). - -- You can update GSM Modem and Blynk Credentials any time you need to change via Configure Portal. Data are saved in SPIFFS or configurable locations in EEPROM. +--- ## 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.1 or later`](https://github.com/vshymanskyy/TinyGSM) +4. [`TinyGSM library 0.10.5 or later`](https://github.com/vshymanskyy/TinyGSM) #### Use Arduino Library Manager @@ -95,6 +116,12 @@ By design, Blynk user can run ESP32/ESP8266 boards with either WiFi or GSM/GPRS 4. Copy whole - `BlynkGSM_Manager-master` folder to Arduino libraries directory such as `~/Arduino/libraries`. +### Important information + +Please read more information in [TinyGSM Library](https://github.com/vshymanskyy/TinyGSM) + +--- + ### How to use For ESP32 and ESP8266, in your code : @@ -116,9 +143,60 @@ For ESP32 and ESP8266, in your code : #endif ``` -4. Change `Blynk.run()` for WiFi to `Blynk_WF.run()`. +4. then add + +``` +// Only for ESP8266 +#define USE_LITTLEFS true +#define USE_SPIFFS false +``` +to use LittleFS (for ESP8266), or + +``` +#define USE_LITTLEFS false +#define USE_SPIFFS true +``` +to use SPIFFS or + +``` +#define USE_LITTLEFS false +#define USE_SPIFFS false +``` +to use EEPROM. Currently, data size in v1.0.9, with DRD and not including dynamic params, is 556 bytes from address EEPROM_START ) to save your configuration data. EEPROM_SIZE can be specified from 1024 to 4096 (2048 for ESP32) bytes. + + +5. + +``` +// 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 +#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 + +``` +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); +``` + +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)); +``` + +8. Change `Blynk.run()` for WiFi to `Blynk_WF.run()`. -5. Change `Blynk.run()` for GSM/GPRS to `Blynk_GSM.run()`. +9. Change `Blynk.run()` for GSM/GPRS to `Blynk_GSM.run()`. That's it. @@ -192,6 +270,7 @@ Also see examples: 2. [ESP32_GSM](examples/ESP32_GSM) 3. [ESP8266_GSM](examples/ESP8266_GSM) +--- ## So, how it works? @@ -245,69 +324,129 @@ void loop() ... } ``` +--- -## Example [TTGO_TCALL_GSM](examples/TTGO_TCALL_GSM) -Please take a look at other examples, as well. +### Important notes +1. Now you can use special chars such as ***~, !, @, #, $, %, ^, &, _, -, space,etc.***. +2. The SSIDs, Passwords, BlynkServers and Tokens must be input (or to make them different from ***blank***). Otherwise, the Config Portal will re-open until those fields have been changed. If you don't need any field, just input anything or use duplicated data from similar field. +3. WiFi password max length now is 63 chars according to WPA2 standard. Minimum password length is 8 chars. +4. Sometimes, it's hard or not possible to connect to Config Portal WiFi AP, the majority cases are caused by WiFi channel conflict if there are too many WiFi APs running around. Please use ***random ConfigPortal WiFi AP channel*** in sketch (see code snippet below) and reset the board so that another channel is used. Repeat until connection is OK ``` -#ifndef ESP32 -#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. -#endif +// Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict + Blynk.setConfigPortalChannel(0); +``` -#define BLYNK_PRINT Serial -#define BLYNK_HEARTBEAT 60 +--- -// TTGO T-Call pin definitions -#define MODEM_RST 5 // Pin D5 mapped to pin GPIO5/SPISS/VSPI_SS of ESP32 -#define MODEM_PWKEY 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 -#define MODEM_POWER_ON 23 // Pin D23 mapped to pin GPIO23/VSPI_MOSI of ESP32 -#define MODEM_TX 27 // Pin D27 mapped to pin GPIO27/ADC17/TOUCH7 of ESP32 -#define MODEM_RX 26 // Pin D26 mapped to pin GPIO26/ADC19/DAC2 of ESP32 -#define I2C_SDA 21 // Pin D21 mapped to pin GPIO21/SDA of ESP32 -#define I2C_SCL 22 // Pin D22 mapped to pin GPIO22/SCL of ESP32 +### How to use default Credentials and have them pre-loaded onto Config Portal -// Select your modem: -#define TINY_GSM_MODEM_SIM800 -//#define TINY_GSM_MODEM_SIM808 -//#define TINY_GSM_MODEM_SIM868 -//#define TINY_GSM_MODEM_SIM900 -//#define TINY_GSM_MODEM_SIM5300 -//#define TINY_GSM_MODEM_SIM5320 -//#define TINY_GSM_MODEM_SIM5360 -//#define TINY_GSM_MODEM_SIM7000 -//#define TINY_GSM_MODEM_SIM7100 -//#define TINY_GSM_MODEM_SIM7500 -//#define TINY_GSM_MODEM_SIM7600 -//#define TINY_GSM_MODEM_SIM7800 -//#define TINY_GSM_MODEM_UBLOX -//#define TINY_GSM_MODEM_SARAR4 -//#define TINY_GSM_MODEM_M95 -//#define TINY_GSM_MODEM_BG96 -//#define TINY_GSM_MODEM_A6 -//#define TINY_GSM_MODEM_A7 -//#define TINY_GSM_MODEM_M590 -//#define TINY_GSM_MODEM_MC60 -//#define TINY_GSM_MODEM_MC60E -//#define TINY_GSM_MODEM_XBEE -//#define TINY_GSM_MODEM_SEQUANS_MONARCH +See this example and modify as necessary -// Increase RX buffer if needed -#define TINY_GSM_RX_BUFFER 1024 +1. To load [Default Credentials](examples/TTGO_TCALL_GSM/Credentials.h) +``` +bool LOAD_DEFAULT_CONFIG_DATA = true; +``` -//#define USE_BLYNK_WM false -#define USE_BLYNK_WM true +2. To use system default to load "blank" when there is no valid Credentials +``` +bool LOAD_DEFAULT_CONFIG_DATA = false; +``` -#define USE_SPIFFS false -//#define USE_SPIFFS true +3. Example of [Default Credentials](examples/TTGO_TCALL_GSM/Credentials.h) -#define EEPROM_SIZE 2048 -#define EEPROM_START 256 +```cpp +/// Start Default Config Data ////////////////// -#include +/* + // Defined in -#if USE_BLYNK_WM -#include + #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 /////////////// @@ -329,22 +468,22 @@ Please take a look at other examples, as well. #if USE_DYNAMIC_PARAMETERS #define MAX_MQTT_SERVER_LEN 34 -char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = ""; +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] = ""; +char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; #define MAX_MQTT_USERNAME_LEN 34 -char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = ""; +char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "mqtt-user"; #define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = ""; +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] = ""; +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] = ""; +char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP32_GSM"; MenuItem myMenuItems [] = { @@ -368,53 +507,62 @@ uint16_t NUM_MENU_ITEMS = 0; /////// // End dynamic Credentials /////////// -#else -#include +``` +- If you don't need to add dynamic parameters, use the following in sketch -// Your WiFi credentials. -#define ssid "****" -#define pass "****" +``` +#define USE_DYNAMIC_PARAMETERS false +``` -#define USE_LOCAL_SERVER true -//#define USE_LOCAL_SERVER false +or -#if USE_LOCAL_SERVER -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -//#define blynk_server "account.duckdns.org" -// Usedirect IPAddress in case GPRS can't use DDNS fast enough and can't connect -#define blynk_server "xxx.xxx.xxx.xxx" -#else -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -#define blynk_server "blynk-cloud.com" -#endif +``` +/////////////// Start dynamic Credentials /////////////// -#define apn "rogers-core-appl1.apn" -#define gprsUser "" //"wapuser1" -#define gprsPass "" //"wap" -#endif +MenuItem myMenuItems [] = {}; -#define BLYNK_HARDWARE_PORT 8080 +uint16_t NUM_MENU_ITEMS = 0; +/////// // End dynamic Credentials /////////// -#include +``` -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial +### Important Notes for using Dynamic Parameters' ids -// Use ESP32 Serial2 for GSM, Serial1 for TTGO T-Call -#define SerialAT Serial1 +1. These ids (such as "mqtt" in example) must be ***unique***. -// Uncomment this if you want to see all AT commands -#define DUMP_AT_COMMANDS false +Please be noted that the following ***reserved names are already used in library***: -#if DUMP_AT_COMMANDS -#include -StreamDebugger debugger(SerialAT, SerialMon); -TinyGsm modem(debugger); -#else -TinyGsm modem(SerialAT); -#endif +``` +"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) + +``` +#include "defines.h" +#include "Credentials.h" +#include "dynamicParams.h" void heartBeatPrint(void) { @@ -474,7 +622,8 @@ void setup() SerialMon.begin(115200); while (!SerialMon); - SerialMon.println(F("\nStart TTGO-TCALL-GSM")); + SerialMon.print(F("\nStart TTGO-TCALL-GSM using ")); + SerialMon.println(CurrentFileFS); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); @@ -518,7 +667,7 @@ void setup() Serial.print(F("gprs apn = ")); Serial.println(localBlynkGSM_ESP32_config.apn); - if (String(localBlynkGSM_ESP32_config.apn) == String("nothing")) + if (String(localBlynkGSM_ESP32_config.apn) == NO_CONFIG) { Serial.println(F("No valid stored apn. Must run WiFi to Open config portal")); valid_apn = false; @@ -527,12 +676,20 @@ void setup() { valid_apn = true; - Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.gsm_blynk_tok, localBlynkGSM_ESP32_config.blynk_server, BLYNK_HARDWARE_PORT); - GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser, - localBlynkGSM_ESP32_config.gprsPass); + for (int index = 0; index < NUM_BLYNK_CREDENTIALS; index++) + { + Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.Blynk_Creds[index].gsm_blynk_token, + localBlynkGSM_ESP32_config.Blynk_Creds[index].blynk_server, localBlynkGSM_ESP32_config.blynk_port); + + GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser, + localBlynkGSM_ESP32_config.gprsPass); - if (GSM_CONNECT_OK) - Blynk_GSM.connect(); + if (GSM_CONNECT_OK) + { + if ( Blynk_GSM.connect() == true ) + break; + } + } } #endif } @@ -540,7 +697,7 @@ void setup() #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) void displayCredentials(void) { - Serial.println("Your stored Credentials :"); + Serial.println("\nYour stored Credentials :"); for (int i = 0; i < NUM_MENU_ITEMS; i++) { @@ -585,50 +742,369 @@ void loop() } ``` -and 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) +2. File [defines.h](examples/TTGO_TCALL_GSM/defines.h) + +```cpp +#ifndef defines_h +#define defines_h + +#ifndef ESP32 + #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. +#endif + +#define BLYNK_PRINT Serial +#define BLYNK_HEARTBEAT 60 + +#define DOUBLERESETDETECTOR_DEBUG true //false +#define BLYNK_WM_DEBUG 1 + +//#define USE_SPIFFS false +#define USE_SPIFFS true + +#if USE_SPIFFS + #define CurrentFileFS F("SPIFFS") +#else + #define CurrentFileFS F("EEPROM") +// 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 +#endif + +// 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 +#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 +// Those above #define's must be placed before #include + +// TTGO T-Call pin definitions +#define MODEM_RST 5 +#define MODEM_PWKEY 4 +#define MODEM_POWER_ON 23 + +#define MODEM_TX 27 +#define MODEM_RX 26 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +// Select your modem: +#define TINY_GSM_MODEM_SIM800 +//#define TINY_GSM_MODEM_SIM808 +//#define TINY_GSM_MODEM_SIM868 +//#define TINY_GSM_MODEM_SIM900 +//#define TINY_GSM_MODEM_SIM5300 +//#define TINY_GSM_MODEM_SIM5320 +//#define TINY_GSM_MODEM_SIM5360 +//#define TINY_GSM_MODEM_SIM7000 +//#define TINY_GSM_MODEM_SIM7100 +//#define TINY_GSM_MODEM_SIM7500 +//#define TINY_GSM_MODEM_SIM7600 +//#define TINY_GSM_MODEM_SIM7800 +//#define TINY_GSM_MODEM_UBLOX +//#define TINY_GSM_MODEM_SARAR4 +//#define TINY_GSM_MODEM_M95 +//#define TINY_GSM_MODEM_BG96 +//#define TINY_GSM_MODEM_A6 +//#define TINY_GSM_MODEM_A7 +//#define TINY_GSM_MODEM_M590 +//#define TINY_GSM_MODEM_MC60 +//#define TINY_GSM_MODEM_MC60E +//#define TINY_GSM_MODEM_XBEE +//#define TINY_GSM_MODEM_SEQUANS_MONARCH + +// Increase RX buffer if needed +#define TINY_GSM_RX_BUFFER 1024 + +#include + +//#define USE_BLYNK_WM false +#define USE_BLYNK_WM true + +#include + +#if USE_BLYNK_WM + + #include + +#else + #include + + // Your WiFi credentials. + #define ssid "****" + #define pass "****" + + #define USE_LOCAL_SERVER true + //#define USE_LOCAL_SERVER false + + #if USE_LOCAL_SERVER + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + //#define blynk_server "account.duckdns.org" + // Use direct IPAddress in case GPRS can't use DDNS fast enough and can't connect + #define blynk_server "xxx.xxx.xxx.xxx" + #else + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + #define blynk_server "blynk-cloud.com" + #endif + + #define apn "rogers-core-appl1.apn" + #define gprsUser "" //"wapuser1" + #define gprsPass "" //"wap" + +#endif //USE_BLYNK_WM + +#define BLYNK_HARDWARE_PORT 8080 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +#define RXD2 16 +#define TXD2 17 + +// Use ESP32 Serial2 for GSM, Serial1 for TTGO T-Call +#define SerialAT Serial1 + +// Uncomment this if you want to see all AT commands +#define DUMP_AT_COMMANDS false + +#if DUMP_AT_COMMANDS + #include + StreamDebugger debugger(SerialAT, SerialMon); + TinyGsm modem(debugger); +#else + TinyGsm modem(SerialAT); +#endif + +#define HOST_NAME "ESP32-GSM-WiFi" + +#endif //defines_h + +``` + +3. File [Credentials.h](examples/TTGO_TCALL_GSM/Credentials.h) + +```cpp +#ifndef Credentials_h +#define Credentials_h + +/// 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 ///////////// + + +#endif //Credentials_h +``` + +4. File [dynamicParams.h](examples/TTGO_TCALL_GSM/dynamicParams.h) + +```cpp +#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 + { + 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 /////////// + +#endif //dynamicParams_h +``` +--- + +#### 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 Set GSM module baud rate Use WiFi to connect Blynk [3108] Hostname=TTGO-TCALL-GSM -[3114] CCSum=0x37d8,RCSum=0x37d8 -[3114] CrCCsum=5323,CrRCsum=5323 -[3114] Hdr=ESP32_GSM_WFM,SSID=your-ssid,PW=your-pass -[3114] Svr=account.duckdns.org,Prt=8080,WiFiToken=wifi-token -[3120] APN=rogers-core-appl1.apn,User=wapuser1 -[3124] PW=wap,PIN=12345678,GSMToken=gsm-token -[3130] BrdName=TTGO-TCALL -[3133] +[3169] LoadCfgFile +[3169] OK +[3169] CCSum=0x5ae8,RCSum=0x5ae8 +[3171] LoadCredFile +[3171] OK +[3171] CrCCsum=15b9,CrRCsum=15b9 +[3171] Buffer freed +[3173] LoadCredFile +[3173] OK +[3174] CrCCsum=15b9,CrRCsum=15b9 +[3177] Hdr=ESP32_GSM_WFM,BrdName=ESP32-GSM-WiFi +[3181] SSID=HueNet1,PW=**** +[3184] SSID1=HueNet2,PW1=**** +[3187] APN=rogers-core-appl1.apn,User=wapuser1 +[3191] PW=wap,PIN=1245678 +[3194] Server=account.ddns.net,WiFi_Token=****,GSM_Token=**** +[3204] Server1=account.duckdns.org,WiFi_Token1=****,GSM_Token1=**** +[3214] Port=8080 +[3216] ======= End Config Data ======= +[3220] Connecting MultiWifi... +[9463] WiFi connected after time: 1 +[9463] SSID=HueNet1,RSSI=-40 +[9463] Channel=2,IP=192.168.2.81 +[9464] bg: WiFi OK. Try Blynk +[9464] ___ __ __ / _ )/ /_ _____ / /__ / _ / / // / _ \/ '_/ /____/_/\_, /_//_/_/\_\ /___/ v0.6.1 on ESP32 -[3150] con2WF:start -[4651] con2WF:OK -[4651] IP=192.168.2.142,GW=192.168.2.1,SN=255.255.0.0 -[4651] DNS1=192.168.2.1,DNS2=0.0.0.0 -[4651] b:WOK.TryB -[4651] BlynkArduinoClient.connect: Connecting to account.duckdns.org:8080 -[4778] Ready (ping: 5ms). -[4846] b:WBOK +[9477] BlynkArduinoClient.connect: Connecting to account.ddns.net:8080 +[9609] Ready (ping: 12ms). +[9676] Connected to BlynkServer=account.ddns.net,Token=**** +[9677] bg: WiFi+Blynk OK gprs apn = rogers-core-appl1.apn -[4846] +[9678] ___ __ __ / _ )/ /_ _____ / /__ / _ / / // / _ \/ '_/ /____/_/\_, /_//_/_/\_\ /___/ v0.6.1 on ESP32 -[4852] InitModem -[4974] Con2Network -[4985] Network:Rogers Wireless -[4985] Conn2 rogers-core-appl1.apn -[10114] GPRSConOK -[10124] BlynkArduinoClient.connect: Connecting to account.duckdns.org:8080 -[10768] Ready (ping: 315ms). +[9691] InitModem +[9713] Con2Network +[9724] Network:Rogers Wireless +[9724] Conn2 rogers-core-appl1.apn +[14955] GPRSConOK +[14965] BlynkArduinoClient.connect: Connecting to account.duckdns.org:8080 +[15609] Ready (ping: 315ms). Your stored Credentials : MQTT Server = mqtt.duckdns.org Port = 1883 @@ -639,6 +1115,17 @@ Pubs Topics = PubsTopic1 BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG ``` +--- + +### Major Releases v1.0.9 + +1. Add MultiWiFi/Blynk features for WiFi +2. Add MultiBlynk feature for GPRS/GSM +3. Add DoubleResetDetector (DRD) feature. +4. Update to use LittleFS for ESP8266 core 2.7.1+ to replace deprecated SPIFFS on ESP8266 +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. @@ -691,6 +1178,8 @@ BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGB 1. Change Synch XMLHttpRequest to Async to avoid ["InvalidAccessError" DOMException](https://xhr.spec.whatwg.org/) 2. Reduce memory usage. +--- + ## TO DO 1. Same features for other boards with GSM/GPRS shield as well as other GSM/GPRS shields (SIM7x00, etc.). diff --git a/examples/ESP32_GSM/Credentials.h b/examples/ESP32_GSM/Credentials.h new file mode 100644 index 0000000..3156e68 --- /dev/null +++ b/examples/ESP32_GSM/Credentials.h @@ -0,0 +1,115 @@ +/**************************************************************************************************************************** + 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 + + 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 + *****************************************************************************************************************************/ + +#ifndef Credentials_h +#define Credentials_h + +/// 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 ///////////// + + +#endif //Credentials_h diff --git a/examples/ESP32_GSM/ESP32_GSM.ino b/examples/ESP32_GSM/ESP32_GSM.ino index 15a49ee..5a8e9f2 100644 --- a/examples/ESP32_GSM/ESP32_GSM.ino +++ b/examples/ESP32_GSM/ESP32_GSM.ino @@ -6,7 +6,7 @@ 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.8 + Version: 1.0.9 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,182 +19,13 @@ 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 *****************************************************************************************************************************/ -#ifndef ESP32 -#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. -#endif - -#define BLYNK_PRINT Serial -#define BLYNK_HEARTBEAT 60 - -// TTGO T-Call pin definitions -#define MODEM_RST 5 -#define MODEM_PWKEY 4 -#define MODEM_POWER_ON 23 - -#define MODEM_TX 27 -#define MODEM_RX 26 - -#define I2C_SDA 21 -#define I2C_SCL 22 - -// Select your modem: -#define TINY_GSM_MODEM_SIM800 -//#define TINY_GSM_MODEM_SIM808 -//#define TINY_GSM_MODEM_SIM868 -//#define TINY_GSM_MODEM_SIM900 -//#define TINY_GSM_MODEM_SIM5300 -//#define TINY_GSM_MODEM_SIM5320 -//#define TINY_GSM_MODEM_SIM5360 -//#define TINY_GSM_MODEM_SIM7000 -//#define TINY_GSM_MODEM_SIM7100 -//#define TINY_GSM_MODEM_SIM7500 -//#define TINY_GSM_MODEM_SIM7600 -//#define TINY_GSM_MODEM_SIM7800 -//#define TINY_GSM_MODEM_UBLOX -//#define TINY_GSM_MODEM_SARAR4 -//#define TINY_GSM_MODEM_M95 -//#define TINY_GSM_MODEM_BG96 -//#define TINY_GSM_MODEM_A6 -//#define TINY_GSM_MODEM_A7 -//#define TINY_GSM_MODEM_M590 -//#define TINY_GSM_MODEM_MC60 -//#define TINY_GSM_MODEM_MC60E -//#define TINY_GSM_MODEM_XBEE -//#define TINY_GSM_MODEM_SEQUANS_MONARCH - - -// Increase RX buffer if needed -#define TINY_GSM_RX_BUFFER 1024 - -#include - -#define USE_SPIFFS true -//#define USE_SPIFFS false - -//#define USE_BLYNK_WM false -#define USE_BLYNK_WM true - -#define EEPROM_SIZE 2048 -#define EEPROM_START 512 - -#include - -#if USE_BLYNK_WM -#include - -#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] = ""; - -#define MAX_MQTT_PORT_LEN 6 -char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = ""; - -#define MAX_MQTT_USERNAME_LEN 34 -char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = ""; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = ""; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = ""; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = ""; - -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 /////////// - -#else -#include - -// Your WiFi credentials. -#define ssid "****" -#define pass "****" - -#define USE_LOCAL_SERVER true -//#define USE_LOCAL_SERVER false - -#if USE_LOCAL_SERVER -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -//#define blynk_server "account.duckdns.org" -#define blynk_server "xxx.xxx.xxx.xxx" -#else -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -#define blynk_server "blynk-cloud.com" -#endif - -#define apn "rogers-core-appl1.apn" -#define gprsUser "" //"wapuser1" -#define gprsPass "" //"wap" -#endif - -#define BLYNK_HARDWARE_PORT 8080 - -#include - -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial - -#define RXD2 16 -#define TXD2 17 -// Use ESP32 Serial2 for GSM -#define SerialAT Serial2 - -// Uncomment this if you want to see all AT commands -#define DUMP_AT_COMMANDS false - -//#include -//SoftwareSerial SerialAT(MODEM_RX, MODEM_TX); // RX, TX - -#if DUMP_AT_COMMANDS -#include -StreamDebugger debugger(SerialAT, SerialMon); -TinyGsm modem(debugger); -#else -TinyGsm modem(SerialAT); -#endif +#include "defines.h" +#include "Credentials.h" +#include "dynamicParams.h" void heartBeatPrint(void) { @@ -254,7 +85,8 @@ void setup() SerialMon.begin(115200); while (!SerialMon); - SerialMon.println(F("\nStart ESP32-WIFI-GSM")); + SerialMon.print(F("\nStart ESP32-WIFI-GSM using ")); + SerialMon.println(CurrentFileFS); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); @@ -276,7 +108,7 @@ void setup() #if USE_BLYNK_WM // Use configurable AP IP, instead of default IP 192.168.4.1 - Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1)); + Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 240, 1)); // Use channel = 0 => random Config Portal WiFi channel to avoid conflict Blynk_WF.setConfigPortalChannel(0); // Set personalized Hostname @@ -299,7 +131,7 @@ void setup() Serial.print(F("gprs apn = ")); Serial.println(localBlynkGSM_ESP32_config.apn); - if (String(localBlynkGSM_ESP32_config.apn) == String("nothing")) + if (String(localBlynkGSM_ESP32_config.apn) == NO_CONFIG) { Serial.println(F("No valid stored apn. Must run WiFi to Open config portal")); valid_apn = false; @@ -308,12 +140,20 @@ void setup() { valid_apn = true; - Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.gsm_blynk_tok, localBlynkGSM_ESP32_config.blynk_server, BLYNK_HARDWARE_PORT); - GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser, - localBlynkGSM_ESP32_config.gprsPass); + for (int index = 0; index < NUM_BLYNK_CREDENTIALS; index++) + { + Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.Blynk_Creds[index].gsm_blynk_token, + localBlynkGSM_ESP32_config.Blynk_Creds[index].blynk_server, localBlynkGSM_ESP32_config.blynk_port); - if (GSM_CONNECT_OK) - Blynk_GSM.connect(); + GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser, + localBlynkGSM_ESP32_config.gprsPass); + + if (GSM_CONNECT_OK) + { + if ( Blynk_GSM.connect() == true ) + break; + } + } } #endif } @@ -321,7 +161,7 @@ void setup() #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) void displayCredentials(void) { - Serial.println("Your stored Credentials :"); + Serial.println("\nYour stored Credentials :"); for (int i = 0; i < NUM_MENU_ITEMS; i++) { diff --git a/examples/ESP32_GSM/defines.h b/examples/ESP32_GSM/defines.h new file mode 100644 index 0000000..5d8f806 --- /dev/null +++ b/examples/ESP32_GSM/defines.h @@ -0,0 +1,160 @@ +/**************************************************************************************************************************** + defines.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 + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#ifndef ESP32 + #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. +#endif + +#define BLYNK_PRINT Serial +#define BLYNK_HEARTBEAT 60 + +#define DOUBLERESETDETECTOR_DEBUG true //false +#define BLYNK_WM_DEBUG 1 + +//#define USE_SPIFFS false +#define USE_SPIFFS true + +#if USE_SPIFFS + #define CurrentFileFS F("SPIFFS") +#else + #define CurrentFileFS F("EEPROM") +// 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 +#endif + +// 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 +#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 +// Those above #define's must be placed before #include + +// TTGO T-Call pin definitions +#define MODEM_RST 5 +#define MODEM_PWKEY 4 +#define MODEM_POWER_ON 23 + +#define MODEM_TX 27 +#define MODEM_RX 26 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +// Select your modem: +#define TINY_GSM_MODEM_SIM800 +//#define TINY_GSM_MODEM_SIM808 +//#define TINY_GSM_MODEM_SIM868 +//#define TINY_GSM_MODEM_SIM900 +//#define TINY_GSM_MODEM_SIM5300 +//#define TINY_GSM_MODEM_SIM5320 +//#define TINY_GSM_MODEM_SIM5360 +//#define TINY_GSM_MODEM_SIM7000 +//#define TINY_GSM_MODEM_SIM7100 +//#define TINY_GSM_MODEM_SIM7500 +//#define TINY_GSM_MODEM_SIM7600 +//#define TINY_GSM_MODEM_SIM7800 +//#define TINY_GSM_MODEM_UBLOX +//#define TINY_GSM_MODEM_SARAR4 +//#define TINY_GSM_MODEM_M95 +//#define TINY_GSM_MODEM_BG96 +//#define TINY_GSM_MODEM_A6 +//#define TINY_GSM_MODEM_A7 +//#define TINY_GSM_MODEM_M590 +//#define TINY_GSM_MODEM_MC60 +//#define TINY_GSM_MODEM_MC60E +//#define TINY_GSM_MODEM_XBEE +//#define TINY_GSM_MODEM_SEQUANS_MONARCH + +// Increase RX buffer if needed +#define TINY_GSM_RX_BUFFER 1024 + +#include + +//#define USE_BLYNK_WM false +#define USE_BLYNK_WM true + +#include + +#if USE_BLYNK_WM + + #include + +#else + #include + + // Your WiFi credentials. + #define ssid "****" + #define pass "****" + + #define USE_LOCAL_SERVER true + //#define USE_LOCAL_SERVER false + + #if USE_LOCAL_SERVER + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + //#define blynk_server "account.duckdns.org" + // Use direct IPAddress in case GPRS can't use DDNS fast enough and can't connect + #define blynk_server "xxx.xxx.xxx.xxx" + #else + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + #define blynk_server "blynk-cloud.com" + #endif + + #define apn "rogers-core-appl1.apn" + #define gprsUser "" //"wapuser1" + #define gprsPass "" //"wap" + +#endif //USE_BLYNK_WM + +#define BLYNK_HARDWARE_PORT 8080 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +#define RXD2 16 +#define TXD2 17 + +// Use ESP32 Serial2 for GSM +#define SerialAT Serial2 + +// Uncomment this if you want to see all AT commands +#define DUMP_AT_COMMANDS false + +#if DUMP_AT_COMMANDS + #include + StreamDebugger debugger(SerialAT, SerialMon); + TinyGsm modem(debugger); +#else + TinyGsm modem(SerialAT); +#endif + +#define HOST_NAME "ESP32-GSM-WiFi" + +#endif //defines_h diff --git a/examples/ESP32_GSM/dynamicParams.h b/examples/ESP32_GSM/dynamicParams.h new file mode 100644 index 0000000..8f528c7 --- /dev/null +++ b/examples/ESP32_GSM/dynamicParams.h @@ -0,0 +1,89 @@ +/**************************************************************************************************************************** + 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 + *****************************************************************************************************************************/ + +#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 + { + 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 /////////// + +#endif //dynamicParams_h diff --git a/examples/ESP8266_GSM/Credentials.h b/examples/ESP8266_GSM/Credentials.h new file mode 100644 index 0000000..39f6885 --- /dev/null +++ b/examples/ESP8266_GSM/Credentials.h @@ -0,0 +1,115 @@ +/**************************************************************************************************************************** + 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 + + 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 + *****************************************************************************************************************************/ + +#ifndef Credentials_h +#define Credentials_h + +/// 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]; + "8266-GSM-WiFi", + //int checkSum, dummy, not used + 0 +}; + +/////////// End Default Config Data ///////////// + + +#endif //Credentials_h diff --git a/examples/ESP8266_GSM/ESP8266_GSM.ino b/examples/ESP8266_GSM/ESP8266_GSM.ino index b7a678d..b85d669 100644 --- a/examples/ESP8266_GSM/ESP8266_GSM.ino +++ b/examples/ESP8266_GSM/ESP8266_GSM.ino @@ -1,12 +1,12 @@ /**************************************************************************************************************************** - ESP8266_GSM.ino_Config.ino - For ESP32 TTGO-TCALL boards to run GSM/GPRS and WiFi simultaneously, using config portal feature + 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.8 + Version: 1.0.9 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,173 +19,14 @@ 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 *****************************************************************************************************************************/ -#ifndef ESP8266 -#error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting. -#endif - -#define BLYNK_PRINT Serial -#define BLYNK_HEARTBEAT 60 - -#define MODEM_RST D0 // Pin D0 mapped to pin GPIO16/USER/WAKE of ESP8266. This pin is also used for Onboard-Blue LED. -#define MODEM_PWKEY D5 // Pin D5 mapped to pin GPIO14/HSCLK of ESP8266 -#define MODEM_POWER_ON D6 // Pin D6 mapped to pin GPIO12/HMISO of ESP8266 - -#define MODEM_TX D8 // Pin D8 mapped to pin GPIO15/TXD2/HCS of ESP8266 -#define MODEM_RX D7 // Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266 - -#define I2C_SDA D2 // Pin D2 mapped to pin GPIO4/SDA of ESP8266 -#define I2C_SCL D1 // Pin D1 mapped to pin GPIO5/SCL of ESP8266 - -// Select your modem: -#define TINY_GSM_MODEM_SIM800 -//#define TINY_GSM_MODEM_SIM808 -//#define TINY_GSM_MODEM_SIM868 -//#define TINY_GSM_MODEM_SIM900 -//#define TINY_GSM_MODEM_SIM5300 -//#define TINY_GSM_MODEM_SIM5320 -//#define TINY_GSM_MODEM_SIM5360 -//#define TINY_GSM_MODEM_SIM7000 -//#define TINY_GSM_MODEM_SIM7100 -//#define TINY_GSM_MODEM_SIM7500 -//#define TINY_GSM_MODEM_SIM7600 -//#define TINY_GSM_MODEM_SIM7800 -//#define TINY_GSM_MODEM_UBLOX -//#define TINY_GSM_MODEM_SARAR4 -//#define TINY_GSM_MODEM_M95 -//#define TINY_GSM_MODEM_BG96 -//#define TINY_GSM_MODEM_A6 -//#define TINY_GSM_MODEM_A7 -//#define TINY_GSM_MODEM_M590 -//#define TINY_GSM_MODEM_MC60 -//#define TINY_GSM_MODEM_MC60E -//#define TINY_GSM_MODEM_XBEE -//#define TINY_GSM_MODEM_SEQUANS_MONARCH - -// Increase RX buffer if needed -#define TINY_GSM_RX_BUFFER 1024 - -#include - -#define USE_SPIFFS true -//#define USE_SPIFFS false - -#define EEPROM_SIZE 2048 -#define EEPROM_START 512 - -//#define USE_BLYNK_WM false -#define USE_BLYNK_WM true - -#include - -#if USE_BLYNK_WM -#include - -#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] = ""; - -#define MAX_MQTT_PORT_LEN 6 -char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = ""; - -#define MAX_MQTT_USERNAME_LEN 34 -char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = ""; +#include "defines.h" +#include "Credentials.h" +#include "dynamicParams.h" -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = ""; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = ""; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = ""; - -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 /////////// - -#else -#include - -// Your WiFi credentials. -#define ssid "****" -#define pass "****" - -#define USE_LOCAL_SERVER true -//#define USE_LOCAL_SERVER false - -#if USE_LOCAL_SERVER -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -//#define blynk_server "account.duckdns.org" -#define blynk_server "xxx.xxx.xxx.xxx" -#else -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -#define blynk_server "blynk-cloud.com" -#endif - -#define apn "rogers-core-appl1.apn" -#define gprsUser "" //"wapuser1" -#define gprsPass "" //"wap" -#endif - -#define BLYNK_HARDWARE_PORT 8080 - -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial - -#include -SoftwareSerial SerialAT(MODEM_RX, MODEM_TX); // RX, TX - -// Uncomment this if you want to see all AT commands -#define DUMP_AT_COMMANDS false - -#if DUMP_AT_COMMANDS -#include -StreamDebugger debugger(SerialAT, SerialMon); -TinyGsm modem(debugger); -#else -TinyGsm modem(SerialAT); -#endif void heartBeatPrint(void) { @@ -244,9 +85,10 @@ void setup() // Set console baud rate SerialMon.begin(115200); while (!SerialMon); - - SerialMon.println(F("\nStart ESP8266-WIFI-GSM")); + SerialMon.print(F("\nStart ESP8266-WIFI-GSM using ")); + SerialMon.println(CurrentFileFS); + // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); pinMode(MODEM_RST, OUTPUT); @@ -290,7 +132,7 @@ void setup() Serial.print(F("gprs apn = ")); Serial.println(localBlynkGSM_ESP8266_config.apn); - if (String(localBlynkGSM_ESP8266_config.apn) == String("nothing")) + if (String(localBlynkGSM_ESP8266_config.apn) == NO_CONFIG) { Serial.println(F("No valid stored apn. Must run WiFi to Open config portal")); valid_apn = false; @@ -299,12 +141,20 @@ void setup() { valid_apn = true; - Blynk_GSM.config(modem, localBlynkGSM_ESP8266_config.gsm_blynk_tok, localBlynkGSM_ESP8266_config.blynk_server, BLYNK_HARDWARE_PORT); - GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP8266_config.apn, localBlynkGSM_ESP8266_config.gprsUser, - localBlynkGSM_ESP8266_config.gprsPass); + for (int index = 0; index < NUM_BLYNK_CREDENTIALS; index++) + { + Blynk_GSM.config(modem, localBlynkGSM_ESP8266_config.Blynk_Creds[index].gsm_blynk_token, + localBlynkGSM_ESP8266_config.Blynk_Creds[index].blynk_server, localBlynkGSM_ESP8266_config.blynk_port); - if (GSM_CONNECT_OK) - Blynk_GSM.connect(); + GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP8266_config.apn, localBlynkGSM_ESP8266_config.gprsUser, + localBlynkGSM_ESP8266_config.gprsPass); + + if (GSM_CONNECT_OK) + { + if ( Blynk_GSM.connect() == true ) + break; + } + } } #endif } @@ -312,7 +162,7 @@ void setup() #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) void displayCredentials(void) { - Serial.println("Your stored Credentials :"); + Serial.println("\nYour stored Credentials :"); for (int i = 0; i < NUM_MENU_ITEMS; i++) { @@ -334,7 +184,7 @@ void loop() } check_status(); - + #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) static bool displayedCredentials = false; diff --git a/examples/ESP8266_GSM/defines.h b/examples/ESP8266_GSM/defines.h new file mode 100644 index 0000000..fa9fb1d --- /dev/null +++ b/examples/ESP8266_GSM/defines.h @@ -0,0 +1,174 @@ +/**************************************************************************************************************************** + 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 + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + + +#ifndef ESP8266 + #error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting. +#endif + +#define BLYNK_PRINT Serial +#define BLYNK_HEARTBEAT 60 + +#define DOUBLERESETDETECTOR_DEBUG true //false +#define BLYNK_WM_DEBUG 1 + +// #define USE_SPIFFS and USE_LITTLEFS false => using EEPROM for configuration data in WiFiManager +// #define USE_LITTLEFS true => using LITTLEFS for configuration data in WiFiManager +// #define USE_LITTLEFS false and USE_SPIFFS true => using SPIFFS for configuration data in WiFiManager +// Be sure to define USE_LITTLEFS and USE_SPIFFS before #include +// From ESP8266 core 2.7.1, SPIFFS will be deprecated and to be replaced by LittleFS +// Select USE_LITTLEFS (higher priority) or USE_SPIFFS + +//#define USE_LITTLEFS true +//#define USE_LITTLEFS false +//#define USE_SPIFFS false +//#define USE_SPIFFS true + +#if USE_LITTLEFS + //LittleFS has higher priority + #define CurrentFileFS F("LittleFS") + #ifdef USE_SPIFFS + #undef USE_SPIFFS + #endif + #define USE_SPIFFS false +#elif USE_SPIFFS + #define CurrentFileFS F("SPIFFS") +#else + #define CurrentFileFS F("EEPROM") + // EEPROM_SIZE must be <= 4096 and >= CONFIG_DATA_SIZE (currently 172 bytes) + #define EEPROM_SIZE (4 * 1024) + // EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE + #define EEPROM_START 0 +#endif + +// 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 +#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 +// Those above #define's must be placed before #include + + +#define MODEM_RST D0 // Pin D0 mapped to pin GPIO16/USER/WAKE of ESP8266. This pin is also used for Onboard-Blue LED. +#define MODEM_PWKEY D5 // Pin D5 mapped to pin GPIO14/HSCLK of ESP8266 +#define MODEM_POWER_ON D6 // Pin D6 mapped to pin GPIO12/HMISO of ESP8266 + +#define MODEM_TX D8 // Pin D8 mapped to pin GPIO15/TXD2/HCS of ESP8266 +#define MODEM_RX D7 // Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266 + +#define I2C_SDA D2 // Pin D2 mapped to pin GPIO4/SDA of ESP8266 +#define I2C_SCL D1 // Pin D1 mapped to pin GPIO5/SCL of ESP8266 + +// Select your modem: +#define TINY_GSM_MODEM_SIM800 +//#define TINY_GSM_MODEM_SIM808 +//#define TINY_GSM_MODEM_SIM868 +//#define TINY_GSM_MODEM_SIM900 +//#define TINY_GSM_MODEM_SIM5300 +//#define TINY_GSM_MODEM_SIM5320 +//#define TINY_GSM_MODEM_SIM5360 +//#define TINY_GSM_MODEM_SIM7000 +//#define TINY_GSM_MODEM_SIM7100 +//#define TINY_GSM_MODEM_SIM7500 +//#define TINY_GSM_MODEM_SIM7600 +//#define TINY_GSM_MODEM_SIM7800 +//#define TINY_GSM_MODEM_UBLOX +//#define TINY_GSM_MODEM_SARAR4 +//#define TINY_GSM_MODEM_M95 +//#define TINY_GSM_MODEM_BG96 +//#define TINY_GSM_MODEM_A6 +//#define TINY_GSM_MODEM_A7 +//#define TINY_GSM_MODEM_M590 +//#define TINY_GSM_MODEM_MC60 +//#define TINY_GSM_MODEM_MC60E +//#define TINY_GSM_MODEM_XBEE +//#define TINY_GSM_MODEM_SEQUANS_MONARCH + +// Increase RX buffer if needed +#define TINY_GSM_RX_BUFFER 1024 + +#include + +//#define USE_BLYNK_WM false +#define USE_BLYNK_WM true + +#include + +#if USE_BLYNK_WM + + #include + +#else + #include + + // Your WiFi credentials. + #define ssid "****" + #define pass "****" + + #define USE_LOCAL_SERVER true + //#define USE_LOCAL_SERVER false + + #if USE_LOCAL_SERVER + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + //#define blynk_server "account.duckdns.org" + // Use direct IPAddress in case GPRS can't use DDNS fast enough and can't connect + #define blynk_server "xxx.xxx.xxx.xxx" + #else + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + #define blynk_server "blynk-cloud.com" + #endif + + #define apn "rogers-core-appl1.apn" + #define gprsUser "" //"wapuser1" + #define gprsPass "" //"wap" + +#endif //USE_BLYNK_WM + +#define BLYNK_HARDWARE_PORT 8080 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +#include +SoftwareSerial SerialAT(MODEM_RX, MODEM_TX); // RX, TX + +// Uncomment this if you want to see all AT commands +#define DUMP_AT_COMMANDS false + +#if DUMP_AT_COMMANDS + #include + StreamDebugger debugger(SerialAT, SerialMon); + TinyGsm modem(debugger); +#else + TinyGsm modem(SerialAT); +#endif + +#define HOST_NAME "8266-GSM-WiFi" + +#endif //defines_h diff --git a/examples/ESP8266_GSM/dynamicParams.h b/examples/ESP8266_GSM/dynamicParams.h new file mode 100644 index 0000000..e5adc9c --- /dev/null +++ b/examples/ESP8266_GSM/dynamicParams.h @@ -0,0 +1,89 @@ +/**************************************************************************************************************************** + 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 + *****************************************************************************************************************************/ + +#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 + { + 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_ESP8266_GSM"; + +#define MAX_MQTT_PUB_TOPIC_LEN 34 +char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "PubTopic_ESP8266_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 /////////// + +#endif //dynamicParams_h diff --git a/examples/TTGO_TCALL_GSM/Credentials.h b/examples/TTGO_TCALL_GSM/Credentials.h new file mode 100644 index 0000000..4ecf34e --- /dev/null +++ b/examples/TTGO_TCALL_GSM/Credentials.h @@ -0,0 +1,116 @@ +/**************************************************************************************************************************** + 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 + + 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 + *****************************************************************************************************************************/ + +#ifndef Credentials_h +#define Credentials_h + +/// 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 ///////////// + + +#endif //Credentials_h diff --git a/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino b/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino index 5c58190..16d0062 100644 --- a/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino +++ b/examples/TTGO_TCALL_GSM/TTGO_TCALL_GSM.ino @@ -6,7 +6,7 @@ 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.8 + Version: 1.0.9 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,173 +19,13 @@ 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 *****************************************************************************************************************************/ -#ifndef ESP32 -#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. -#endif - -#define BLYNK_PRINT Serial -#define BLYNK_HEARTBEAT 60 - -// TTGO T-Call pin definitions -#define MODEM_RST 5 // Pin D5 mapped to pin GPIO5/SPISS/VSPI_SS of ESP32 -#define MODEM_PWKEY 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 -#define MODEM_POWER_ON 23 // Pin D23 mapped to pin GPIO23/VSPI_MOSI of ESP32 -#define MODEM_TX 27 // Pin D27 mapped to pin GPIO27/ADC17/TOUCH7 of ESP32 -#define MODEM_RX 26 // Pin D26 mapped to pin GPIO26/ADC19/DAC2 of ESP32 -#define I2C_SDA 21 // Pin D21 mapped to pin GPIO21/SDA of ESP32 -#define I2C_SCL 22 // Pin D22 mapped to pin GPIO22/SCL of ESP32 - -// Select your modem: -#define TINY_GSM_MODEM_SIM800 -//#define TINY_GSM_MODEM_SIM808 -//#define TINY_GSM_MODEM_SIM868 -//#define TINY_GSM_MODEM_SIM900 -//#define TINY_GSM_MODEM_SIM5300 -//#define TINY_GSM_MODEM_SIM5320 -//#define TINY_GSM_MODEM_SIM5360 -//#define TINY_GSM_MODEM_SIM7000 -//#define TINY_GSM_MODEM_SIM7100 -//#define TINY_GSM_MODEM_SIM7500 -//#define TINY_GSM_MODEM_SIM7600 -//#define TINY_GSM_MODEM_SIM7800 -//#define TINY_GSM_MODEM_UBLOX -//#define TINY_GSM_MODEM_SARAR4 -//#define TINY_GSM_MODEM_M95 -//#define TINY_GSM_MODEM_BG96 -//#define TINY_GSM_MODEM_A6 -//#define TINY_GSM_MODEM_A7 -//#define TINY_GSM_MODEM_M590 -//#define TINY_GSM_MODEM_MC60 -//#define TINY_GSM_MODEM_MC60E -//#define TINY_GSM_MODEM_XBEE -//#define TINY_GSM_MODEM_SEQUANS_MONARCH - -// Increase RX buffer if needed -#define TINY_GSM_RX_BUFFER 1024 - -//#define USE_BLYNK_WM false -#define USE_BLYNK_WM true - -#define USE_SPIFFS false -//#define USE_SPIFFS true - -#define EEPROM_SIZE 2048 -#define EEPROM_START 256 - -#include - -#if USE_BLYNK_WM -#include - -#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] = ""; - -#define MAX_MQTT_PORT_LEN 6 -char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = ""; - -#define MAX_MQTT_USERNAME_LEN 34 -char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = ""; - -#define MAX_MQTT_PW_LEN 34 -char MQTT_PW [MAX_MQTT_PW_LEN + 1] = ""; - -#define MAX_MQTT_SUBS_TOPIC_LEN 34 -char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = ""; - -#define MAX_MQTT_PUB_TOPIC_LEN 34 -char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = ""; - -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 /////////// - -#else -#include - -// Your WiFi credentials. -#define ssid "****" -#define pass "****" - -#define USE_LOCAL_SERVER true -//#define USE_LOCAL_SERVER false - -#if USE_LOCAL_SERVER -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -//#define blynk_server "account.duckdns.org" -// Usedirect IPAddress in case GPRS can't use DDNS fast enough and can't connect -#define blynk_server "xxx.xxx.xxx.xxx" -#else -#define wifi_blynk_tok "****" -#define gsm_blynk_tok "****" -#define blynk_server "blynk-cloud.com" -#endif - -#define apn "rogers-core-appl1.apn" -#define gprsUser "" //"wapuser1" -#define gprsPass "" //"wap" -#endif - -#define BLYNK_HARDWARE_PORT 8080 - -#include - -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial - -// Use ESP32 Serial2 for GSM, Serial1 for TTGO T-Call -#define SerialAT Serial1 - -// Uncomment this if you want to see all AT commands -#define DUMP_AT_COMMANDS false - -#if DUMP_AT_COMMANDS -#include -StreamDebugger debugger(SerialAT, SerialMon); -TinyGsm modem(debugger); -#else -TinyGsm modem(SerialAT); -#endif +#include "defines.h" +#include "Credentials.h" +#include "dynamicParams.h" void heartBeatPrint(void) { @@ -245,7 +85,8 @@ void setup() SerialMon.begin(115200); while (!SerialMon); - SerialMon.println(F("\nStart TTGO-TCALL-GSM")); + SerialMon.print(F("\nStart TTGO-TCALL-GSM using ")); + SerialMon.println(CurrentFileFS); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); @@ -289,7 +130,7 @@ void setup() Serial.print(F("gprs apn = ")); Serial.println(localBlynkGSM_ESP32_config.apn); - if (String(localBlynkGSM_ESP32_config.apn) == String("nothing")) + if (String(localBlynkGSM_ESP32_config.apn) == NO_CONFIG) { Serial.println(F("No valid stored apn. Must run WiFi to Open config portal")); valid_apn = false; @@ -298,12 +139,20 @@ void setup() { valid_apn = true; - Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.gsm_blynk_tok, localBlynkGSM_ESP32_config.blynk_server, BLYNK_HARDWARE_PORT); - GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser, - localBlynkGSM_ESP32_config.gprsPass); + for (int index = 0; index < NUM_BLYNK_CREDENTIALS; index++) + { + Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.Blynk_Creds[index].gsm_blynk_token, + localBlynkGSM_ESP32_config.Blynk_Creds[index].blynk_server, localBlynkGSM_ESP32_config.blynk_port); + + GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser, + localBlynkGSM_ESP32_config.gprsPass); - if (GSM_CONNECT_OK) - Blynk_GSM.connect(); + if (GSM_CONNECT_OK) + { + if ( Blynk_GSM.connect() == true ) + break; + } + } } #endif } @@ -311,7 +160,7 @@ void setup() #if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS) void displayCredentials(void) { - Serial.println("Your stored Credentials :"); + Serial.println("\nYour stored Credentials :"); for (int i = 0; i < NUM_MENU_ITEMS; i++) { diff --git a/examples/TTGO_TCALL_GSM/defines.h b/examples/TTGO_TCALL_GSM/defines.h new file mode 100644 index 0000000..9b885d3 --- /dev/null +++ b/examples/TTGO_TCALL_GSM/defines.h @@ -0,0 +1,161 @@ +/**************************************************************************************************************************** + defines.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 + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#ifndef ESP32 + #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. +#endif + +#define BLYNK_PRINT Serial +#define BLYNK_HEARTBEAT 60 + +#define DOUBLERESETDETECTOR_DEBUG true //false +#define BLYNK_WM_DEBUG 1 + +//#define USE_SPIFFS false +#define USE_SPIFFS true + +#if USE_SPIFFS + #define CurrentFileFS F("SPIFFS") +#else + #define CurrentFileFS F("EEPROM") +// 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 +#endif + +// 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 +#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5 +// Those above #define's must be placed before #include + +// TTGO T-Call pin definitions +#define MODEM_RST 5 +#define MODEM_PWKEY 4 +#define MODEM_POWER_ON 23 + +#define MODEM_TX 27 +#define MODEM_RX 26 + +#define I2C_SDA 21 +#define I2C_SCL 22 + +// Select your modem: +#define TINY_GSM_MODEM_SIM800 +//#define TINY_GSM_MODEM_SIM808 +//#define TINY_GSM_MODEM_SIM868 +//#define TINY_GSM_MODEM_SIM900 +//#define TINY_GSM_MODEM_SIM5300 +//#define TINY_GSM_MODEM_SIM5320 +//#define TINY_GSM_MODEM_SIM5360 +//#define TINY_GSM_MODEM_SIM7000 +//#define TINY_GSM_MODEM_SIM7100 +//#define TINY_GSM_MODEM_SIM7500 +//#define TINY_GSM_MODEM_SIM7600 +//#define TINY_GSM_MODEM_SIM7800 +//#define TINY_GSM_MODEM_UBLOX +//#define TINY_GSM_MODEM_SARAR4 +//#define TINY_GSM_MODEM_M95 +//#define TINY_GSM_MODEM_BG96 +//#define TINY_GSM_MODEM_A6 +//#define TINY_GSM_MODEM_A7 +//#define TINY_GSM_MODEM_M590 +//#define TINY_GSM_MODEM_MC60 +//#define TINY_GSM_MODEM_MC60E +//#define TINY_GSM_MODEM_XBEE +//#define TINY_GSM_MODEM_SEQUANS_MONARCH + +// Increase RX buffer if needed +#define TINY_GSM_RX_BUFFER 1024 + +#include + +//#define USE_BLYNK_WM false +#define USE_BLYNK_WM true + +#include + +#if USE_BLYNK_WM + + #include + +#else + #include + + // Your WiFi credentials. + #define ssid "****" + #define pass "****" + + #define USE_LOCAL_SERVER true + //#define USE_LOCAL_SERVER false + + #if USE_LOCAL_SERVER + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + //#define blynk_server "account.duckdns.org" + // Use direct IPAddress in case GPRS can't use DDNS fast enough and can't connect + #define blynk_server "xxx.xxx.xxx.xxx" + #else + #define wifi_blynk_tok "****" + #define gsm_blynk_tok "****" + #define blynk_server "blynk-cloud.com" + #endif + + #define apn "rogers-core-appl1.apn" + #define gprsUser "" //"wapuser1" + #define gprsPass "" //"wap" + +#endif //USE_BLYNK_WM + +#define BLYNK_HARDWARE_PORT 8080 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +#define RXD2 16 +#define TXD2 17 + +// Use ESP32 Serial2 for GSM, Serial1 for TTGO T-Call +#define SerialAT Serial1 + +// Uncomment this if you want to see all AT commands +#define DUMP_AT_COMMANDS false + +#if DUMP_AT_COMMANDS + #include + StreamDebugger debugger(SerialAT, SerialMon); + TinyGsm modem(debugger); +#else + TinyGsm modem(SerialAT); +#endif + +#define HOST_NAME "ESP32-GSM-WiFi" + +#endif //defines_h diff --git a/examples/TTGO_TCALL_GSM/dynamicParams.h b/examples/TTGO_TCALL_GSM/dynamicParams.h new file mode 100644 index 0000000..4d911e1 --- /dev/null +++ b/examples/TTGO_TCALL_GSM/dynamicParams.h @@ -0,0 +1,90 @@ +/**************************************************************************************************************************** + 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 + *****************************************************************************************************************************/ + +#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 + { + 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 /////////// + +#endif //dynamicParams_h diff --git a/keywords.txt b/keywords.txt index c185f76..421eee6 100644 --- a/keywords.txt +++ b/keywords.txt @@ -44,13 +44,13 @@ setSTAStaticIPConfig KEYWORD2 getBoardName KEYWORD2 getWiFiSSID KEYWORD2 getWiFiPW KEYWORD2 +getServerName KEYWORD2 getWiFiToken KEYWORD2 +getGSMToken KEYWORD2 getAPN KEYWORD2 getGPRSUser KEYWORD2 getGPRSPass KEYWORD2 getGPRSPIN KEYWORD2 -getServerName KEYWORD2 -getGSMToken KEYWORD2 getHWPort KEYWORD2 setHostname KEYWORD2 getFullConfigData KEYWORD2 diff --git a/library.json b/library.json index 6c0f083..01caff4 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "BlynkGSM_Manager", - "version": "1.0.8", + "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 ...", "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 02d9d3b..35d7a50 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=BlynkGSM_Manager -version=1.0.8 +version=1.0.9 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 SPIFFS / EEPROM +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. category=Communication url=https://github.com/khoih-prog/BlynkGSM_Manager diff --git a/pics/Selection_2.png b/pics/Selection_2.png index 504104c..5d1cca8 100644 Binary files a/pics/Selection_2.png and b/pics/Selection_2.png differ diff --git a/pics/Selection_3.png b/pics/Selection_3.png index 323e8ac..6153470 100644 Binary files a/pics/Selection_3.png and b/pics/Selection_3.png differ diff --git a/src/Adapters/BlynkGsm_ESP32M.h b/src/Adapters/BlynkGsm_ESP32M.h index e25f2f1..a73d397 100644 --- a/src/Adapters/BlynkGsm_ESP32M.h +++ b/src/Adapters/BlynkGsm_ESP32M.h @@ -6,7 +6,7 @@ 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.8 + Version: 1.0.9 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -27,6 +27,8 @@ 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 *****************************************************************************************************************************/ #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 420f709..8889ad0 100644 --- a/src/Adapters/BlynkGsm_ESP8266M.h +++ b/src/Adapters/BlynkGsm_ESP8266M.h @@ -6,7 +6,7 @@ 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.8 + Version: 1.0.9 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -27,6 +27,8 @@ 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 *****************************************************************************************************************************/ #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 43eb9ee..8c4e733 100644 --- a/src/BlynkSimpleEsp32_GSM_WF.h +++ b/src/BlynkSimpleEsp32_GSM_WF.h @@ -6,7 +6,7 @@ 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.8 + Version: 1.0.9 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -27,6 +27,8 @@ 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 *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_GSM_WF_h diff --git a/src/BlynkSimpleEsp32_GSM_WFM.h b/src/BlynkSimpleEsp32_GSM_WFM.h index 5c3500f..27d7d5d 100644 --- a/src/BlynkSimpleEsp32_GSM_WFM.h +++ b/src/BlynkSimpleEsp32_GSM_WFM.h @@ -6,7 +6,7 @@ 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.8 + Version: 1.0.9 Original Blynk Library author: @file BlynkSimpleESP8266.h @@ -27,6 +27,8 @@ 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 *****************************************************************************************************************************/ #ifndef BlynkSimpleEsp32_GSM_WFM_h @@ -51,12 +53,47 @@ //default to use EEPROM, otherwise, use SPIFFS #if USE_SPIFFS -#include -#include "SPIFFS.h" + #include + #include "SPIFFS.h" + #define FileFS SPIFFS #else -#include + #include #endif +///////// NEW for DRD ///////////// +// These defines must be put before #include +// to select where to store DoubleResetDetector's variable. +// For ESP32, You must select one to be true (EEPROM or SPIFFS) +// For ESP8266, You must select one to be true (RTC, EEPROM or SPIFFS) +// Otherwise, library will use default EEPROM storage +#define ESP8266_DRD_USE_RTC false //true + +#if USE_SPIFFS +#define ESP_DRD_USE_EEPROM false +#define ESP_DRD_USE_SPIFFS true +#else +#define ESP_DRD_USE_EEPROM true +#define ESP_DRD_USE_SPIFFS false +#endif + +#ifndef DOUBLERESETDETECTOR_DEBUG +#define DOUBLERESETDETECTOR_DEBUG false +#endif + +#include //https://github.com/khoih-prog/ESP_DoubleResetDetector + +// Number of seconds after reset during which a +// subseqent reset will be considered a double reset. +#define DRD_TIMEOUT 10 + +// RTC Memory Address for the DoubleResetDetector to use +#define DRD_ADDRESS 0 + +//DoubleResetDetector drd(DRD_TIMEOUT, DRD_ADDRESS); +DoubleResetDetector* drd; + +///////// NEW for DRD ///////////// + #include #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) @@ -80,32 +117,55 @@ typedef struct 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. +#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 11 +#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 related - char wifi_ssid [32]; - char wifi_pw [64]; //From v1.0.7, WPA2 passwords can be up to 63 characters long. - char wifi_blynk_tok [36]; + 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 - // YOUR GSM / GPRS RELATED - char blynk_server [32]; - int blynk_port; - char gsm_blynk_tok [36]; + 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; +// Currently CONFIG_DATA_SIZE = ( 156 + (96 * NUM_WIFI_CREDENTIALS) + (104 * NUM_BLYNK_CREDENTIALS) ) = 556 +uint16_t CONFIG_DATA_SIZE = sizeof(Blynk_WF_Configuration); -// Currently CONFIG_DATA_SIZE = 356 -uint16_t CONFIG_DATA_SIZE = sizeof(struct Configuration); +///New from v1.0.13 +extern bool LOAD_DEFAULT_CONFIG_DATA; +extern Blynk_WF_Configuration defaultConfig; // -- HTML page fragments const char BLYNK_GSM_HTML_HEAD[] /*PROGMEM*/ = "BlynkGSM_ESP32
\
\
\ -
\ +
\ +
\
\
\
\
\
\ -
\ -
\ +
\ +
\ +
\ +
\ +
\ +
\
"; const char BLYNK_GSM_FLDSET_START[] /*PROGMEM*/ = "
"; const char BLYNK_GSM_FLDSET_END[] /*PROGMEM*/ = "
"; @@ -129,11 +194,14 @@ const char BLYNK_GSM_HTML_BUTTON[] /*PROGMEM*/ = "