Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit 9999c90

Browse files
authored
Major release v1.0.9
### 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.
1 parent eba3b86 commit 9999c90

25 files changed

+3402
-1196
lines changed

README.md

Lines changed: 627 additions & 138 deletions
Large diffs are not rendered by default.

examples/ESP32_GSM/Credentials.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/****************************************************************************************************************************
2+
Credentials.h for ESP32_GSM.ino
3+
For ESP32 boards to run GSM/GPRS and WiFi simultaneously, using config portal feature
4+
5+
Library to enable GSM/GPRS and WiFi running simultaneously , with WiFi config portal.
6+
Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
7+
Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager
8+
Licensed under MIT license
9+
Version: 1.0.9
10+
11+
Version Modified By Date Comments
12+
------- ----------- ---------- -----------
13+
1.0.0 K Hoang 17/01/2020 Initial coding. Add config portal similar to Blynk_WM library.
14+
1.0.1 K Hoang 27/01/2020 Change Synch XMLHttpRequest to Async (https://xhr.spec.whatwg.org/). Reduce code size
15+
1.0.2 K Hoang 08/02/2020 Enable GSM/GPRS and WiFi running simultaneously
16+
1.0.3 K Hoang 18/02/2020 Add checksum. Add clearConfigData()
17+
1.0.4 K Hoang 14/03/2020 Enhance Config Portal GUI. Reduce code size.
18+
1.0.5 K Hoang 20/03/2020 Add more modem supports. See the list in README.md
19+
1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch
20+
1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data.
21+
1.0.8 K Hoang 14/04/2020 Fix bug.
22+
1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title,
23+
Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM
24+
*****************************************************************************************************************************/
25+
26+
#ifndef Credentials_h
27+
#define Credentials_h
28+
29+
/// Start Default Config Data //////////////////
30+
31+
/*
32+
// Defined in <BlynkSimpleESP8266_GSM_WFM.h>
33+
34+
#define SSID_MAX_LEN 32
35+
//From v1.0.10, WPA2 passwords can be up to 63 characters long.
36+
#define PASS_MAX_LEN 64
37+
38+
typedef struct
39+
{
40+
char wifi_ssid[SSID_MAX_LEN];
41+
char wifi_pw [PASS_MAX_LEN];
42+
} WiFi_Credentials;
43+
44+
#define BLYNK_SERVER_MAX_LEN 32
45+
#define BLYNK_TOKEN_MAX_LEN 36
46+
47+
typedef struct
48+
{
49+
char blynk_server [BLYNK_SERVER_MAX_LEN];
50+
char wifi_blynk_token [BLYNK_TOKEN_MAX_LEN];
51+
char gsm_blynk_token [BLYNK_TOKEN_MAX_LEN];
52+
} Blynk_Credentials;
53+
54+
#define NUM_WIFI_CREDENTIALS 2
55+
#define NUM_BLYNK_CREDENTIALS 2
56+
57+
// Configurable items besides fixed Header
58+
#define NUM_CONFIGURABLE_ITEMS ( 6 + (2 * NUM_WIFI_CREDENTIALS) + (3 * NUM_BLYNK_CREDENTIALS) )
59+
#define DEFAULT_GPRS_PIN "1234"
60+
61+
typedef struct Configuration
62+
{
63+
char header [16];
64+
WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
65+
Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
66+
int blynk_port;
67+
// YOUR GSM / GPRS RELATED
68+
char apn [32];
69+
char gprsUser [32];
70+
char gprsPass [32];
71+
char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode
72+
// END OF YOUR GSM / GPRS RELATED
73+
char board_name [24];
74+
int checkSum;
75+
} Blynk_WF_Configuration;
76+
77+
*/
78+
79+
bool LOAD_DEFAULT_CONFIG_DATA = true;
80+
//bool LOAD_DEFAULT_CONFIG_DATA = false;
81+
82+
Blynk_WF_Configuration defaultConfig =
83+
{
84+
//char header[16], dummy, not used
85+
"GSM",
86+
//WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]
87+
//WiFi_Creds.wifi_ssid and WiFi_Creds.wifi_pw
88+
"SSID1", "password1",
89+
"SSID2", "password2",
90+
// Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
91+
// Blynk_Creds.blynk_server, Blynk_Creds.wifi_blynk_token and Blynk_Creds.gsm_blynk_token
92+
"account.ddns.net", "wifi_token", "gsm_token",
93+
"account.duckdns.org", "wifi_token1", "gsm_token1",
94+
//int blynk_port;
95+
8080,
96+
// YOUR GSM / GPRS RELATED
97+
//char apn [32];
98+
"rogers-core-appl1.apn",
99+
//char gprsUser [32];
100+
"wapuser1",
101+
//char gprsPass [32];
102+
"wap",
103+
//char gprsPin [12]; // A PIN (Personal Identification Number) is a 4-8 digit passcode
104+
"1245678",
105+
// END OF YOUR GSM / GPRS RELATED
106+
//char board_name [24];
107+
"ESP32-GSM-WiFi",
108+
//int checkSum, dummy, not used
109+
0
110+
};
111+
112+
/////////// End Default Config Data /////////////
113+
114+
115+
#endif //Credentials_h

examples/ESP32_GSM/ESP32_GSM.ino

Lines changed: 24 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Forked from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
77
Built by Khoi Hoang https://github.com/khoih-prog/BlynkGSM_ESPManager
88
Licensed under MIT license
9-
Version: 1.0.8
9+
Version: 1.0.9
1010
1111
Version Modified By Date Comments
1212
------- ----------- ---------- -----------
@@ -19,182 +19,13 @@
1919
1.0.6 K Hoang 07/04/2020 Enable adding dynamic custom parameters from sketch
2020
1.0.7 K Hoang 09/04/2020 SSID password maxlen is 63 now. Permit special chars # and % in input data.
2121
1.0.8 K Hoang 14/04/2020 Fix bug.
22+
1.0.9 K Hoang 31/05/2020 Update to use LittleFS for ESP8266 core 2.7.1+. Add Configurable Config Portal Title,
23+
Default Config Data and DRD. Add MultiWiFi/Blynk features for WiFi and GPRS/GSM
2224
*****************************************************************************************************************************/
2325

24-
#ifndef ESP32
25-
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
26-
#endif
27-
28-
#define BLYNK_PRINT Serial
29-
#define BLYNK_HEARTBEAT 60
30-
31-
// TTGO T-Call pin definitions
32-
#define MODEM_RST 5
33-
#define MODEM_PWKEY 4
34-
#define MODEM_POWER_ON 23
35-
36-
#define MODEM_TX 27
37-
#define MODEM_RX 26
38-
39-
#define I2C_SDA 21
40-
#define I2C_SCL 22
41-
42-
// Select your modem:
43-
#define TINY_GSM_MODEM_SIM800
44-
//#define TINY_GSM_MODEM_SIM808
45-
//#define TINY_GSM_MODEM_SIM868
46-
//#define TINY_GSM_MODEM_SIM900
47-
//#define TINY_GSM_MODEM_SIM5300
48-
//#define TINY_GSM_MODEM_SIM5320
49-
//#define TINY_GSM_MODEM_SIM5360
50-
//#define TINY_GSM_MODEM_SIM7000
51-
//#define TINY_GSM_MODEM_SIM7100
52-
//#define TINY_GSM_MODEM_SIM7500
53-
//#define TINY_GSM_MODEM_SIM7600
54-
//#define TINY_GSM_MODEM_SIM7800
55-
//#define TINY_GSM_MODEM_UBLOX
56-
//#define TINY_GSM_MODEM_SARAR4
57-
//#define TINY_GSM_MODEM_M95
58-
//#define TINY_GSM_MODEM_BG96
59-
//#define TINY_GSM_MODEM_A6
60-
//#define TINY_GSM_MODEM_A7
61-
//#define TINY_GSM_MODEM_M590
62-
//#define TINY_GSM_MODEM_MC60
63-
//#define TINY_GSM_MODEM_MC60E
64-
//#define TINY_GSM_MODEM_XBEE
65-
//#define TINY_GSM_MODEM_SEQUANS_MONARCH
66-
67-
68-
// Increase RX buffer if needed
69-
#define TINY_GSM_RX_BUFFER 1024
70-
71-
#include <TinyGsmClient.h>
72-
73-
#define USE_SPIFFS true
74-
//#define USE_SPIFFS false
75-
76-
//#define USE_BLYNK_WM false
77-
#define USE_BLYNK_WM true
78-
79-
#define EEPROM_SIZE 2048
80-
#define EEPROM_START 512
81-
82-
#include <BlynkSimpleTinyGSM_M.h>
83-
84-
#if USE_BLYNK_WM
85-
#include <BlynkSimpleEsp32_GSM_WFM.h>
86-
87-
#define USE_DYNAMIC_PARAMETERS true
88-
89-
/////////////// Start dynamic Credentials ///////////////
90-
91-
//Defined in <BlynkSimpleEsp32_GSM_WFM.h>
92-
/**************************************
93-
#define MAX_ID_LEN 5
94-
#define MAX_DISPLAY_NAME_LEN 16
95-
96-
typedef struct
97-
{
98-
char id [MAX_ID_LEN + 1];
99-
char displayName [MAX_DISPLAY_NAME_LEN + 1];
100-
char *pdata;
101-
uint8_t maxlen;
102-
} MenuItem;
103-
**************************************/
104-
105-
#if USE_DYNAMIC_PARAMETERS
106-
107-
#define MAX_MQTT_SERVER_LEN 34
108-
char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "";
109-
110-
#define MAX_MQTT_PORT_LEN 6
111-
char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "";
112-
113-
#define MAX_MQTT_USERNAME_LEN 34
114-
char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "";
115-
116-
#define MAX_MQTT_PW_LEN 34
117-
char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "";
118-
119-
#define MAX_MQTT_SUBS_TOPIC_LEN 34
120-
char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "";
121-
122-
#define MAX_MQTT_PUB_TOPIC_LEN 34
123-
char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "";
124-
125-
MenuItem myMenuItems [] =
126-
{
127-
{ "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },
128-
{ "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN },
129-
{ "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN },
130-
{ "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN },
131-
{ "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN },
132-
{ "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN },
133-
};
134-
135-
uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;
136-
137-
#else
138-
139-
MenuItem myMenuItems [] = {};
140-
141-
uint16_t NUM_MENU_ITEMS = 0;
142-
#endif
143-
144-
145-
/////// // End dynamic Credentials ///////////
146-
147-
#else
148-
#include <BlynkSimpleEsp32_GSM_WF.h>
149-
150-
// Your WiFi credentials.
151-
#define ssid "****"
152-
#define pass "****"
153-
154-
#define USE_LOCAL_SERVER true
155-
//#define USE_LOCAL_SERVER false
156-
157-
#if USE_LOCAL_SERVER
158-
#define wifi_blynk_tok "****"
159-
#define gsm_blynk_tok "****"
160-
//#define blynk_server "account.duckdns.org"
161-
#define blynk_server "xxx.xxx.xxx.xxx"
162-
#else
163-
#define wifi_blynk_tok "****"
164-
#define gsm_blynk_tok "****"
165-
#define blynk_server "blynk-cloud.com"
166-
#endif
167-
168-
#define apn "rogers-core-appl1.apn"
169-
#define gprsUser "" //"wapuser1"
170-
#define gprsPass "" //"wap"
171-
#endif
172-
173-
#define BLYNK_HARDWARE_PORT 8080
174-
175-
#include <TinyGsmClient.h>
176-
177-
// Set serial for debug console (to the Serial Monitor, default speed 115200)
178-
#define SerialMon Serial
179-
180-
#define RXD2 16
181-
#define TXD2 17
182-
// Use ESP32 Serial2 for GSM
183-
#define SerialAT Serial2
184-
185-
// Uncomment this if you want to see all AT commands
186-
#define DUMP_AT_COMMANDS false
187-
188-
//#include <SoftwareSerial.h>
189-
//SoftwareSerial SerialAT(MODEM_RX, MODEM_TX); // RX, TX
190-
191-
#if DUMP_AT_COMMANDS
192-
#include <StreamDebugger.h>
193-
StreamDebugger debugger(SerialAT, SerialMon);
194-
TinyGsm modem(debugger);
195-
#else
196-
TinyGsm modem(SerialAT);
197-
#endif
26+
#include "defines.h"
27+
#include "Credentials.h"
28+
#include "dynamicParams.h"
19829

19930
void heartBeatPrint(void)
20031
{
@@ -254,7 +85,8 @@ void setup()
25485
SerialMon.begin(115200);
25586
while (!SerialMon);
25687

257-
SerialMon.println(F("\nStart ESP32-WIFI-GSM"));
88+
SerialMon.print(F("\nStart ESP32-WIFI-GSM using "));
89+
SerialMon.println(CurrentFileFS);
25890

25991
// Set-up modem reset, enable, power pins
26092
pinMode(MODEM_PWKEY, OUTPUT);
@@ -276,7 +108,7 @@ void setup()
276108

277109
#if USE_BLYNK_WM
278110
// Use configurable AP IP, instead of default IP 192.168.4.1
279-
Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1));
111+
Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 240, 1));
280112
// Use channel = 0 => random Config Portal WiFi channel to avoid conflict
281113
Blynk_WF.setConfigPortalChannel(0);
282114
// Set personalized Hostname
@@ -299,7 +131,7 @@ void setup()
299131
Serial.print(F("gprs apn = "));
300132
Serial.println(localBlynkGSM_ESP32_config.apn);
301133

302-
if (String(localBlynkGSM_ESP32_config.apn) == String("nothing"))
134+
if (String(localBlynkGSM_ESP32_config.apn) == NO_CONFIG)
303135
{
304136
Serial.println(F("No valid stored apn. Must run WiFi to Open config portal"));
305137
valid_apn = false;
@@ -308,20 +140,28 @@ void setup()
308140
{
309141
valid_apn = true;
310142

311-
Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.gsm_blynk_tok, localBlynkGSM_ESP32_config.blynk_server, BLYNK_HARDWARE_PORT);
312-
GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser,
313-
localBlynkGSM_ESP32_config.gprsPass);
143+
for (int index = 0; index < NUM_BLYNK_CREDENTIALS; index++)
144+
{
145+
Blynk_GSM.config(modem, localBlynkGSM_ESP32_config.Blynk_Creds[index].gsm_blynk_token,
146+
localBlynkGSM_ESP32_config.Blynk_Creds[index].blynk_server, localBlynkGSM_ESP32_config.blynk_port);
314147

315-
if (GSM_CONNECT_OK)
316-
Blynk_GSM.connect();
148+
GSM_CONNECT_OK = Blynk_GSM.connectNetwork(localBlynkGSM_ESP32_config.apn, localBlynkGSM_ESP32_config.gprsUser,
149+
localBlynkGSM_ESP32_config.gprsPass);
150+
151+
if (GSM_CONNECT_OK)
152+
{
153+
if ( Blynk_GSM.connect() == true )
154+
break;
155+
}
156+
}
317157
}
318158
#endif
319159
}
320160

321161
#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
322162
void displayCredentials(void)
323163
{
324-
Serial.println("Your stored Credentials :");
164+
Serial.println("\nYour stored Credentials :");
325165

326166
for (int i = 0; i < NUM_MENU_ITEMS; i++)
327167
{

0 commit comments

Comments
 (0)