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

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
### Releases v1.0.3

1. Add checksum for more reliable data
2. Add clearConfigData() to enable forcing into ConfigPortal Mode when necessary
  • Loading branch information
khoih-prog authored Feb 25, 2020
1 parent d683b9b commit f5682ce
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 46 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![arduino-library-badge](https://www.ardu-badge.com/badge/BlynkGSM_Manager.svg?)](https://www.ardu-badge.com/BlynkGSM_Manager)

By design, Blynk user can run ESP32/ESP8266 boards with either WiFi or GSM/GPRS by using different sketches, and have to upload / update firmware to change. This library enables user to include both Blynk GSM/GPRS and WiFi libraries in one sketch, run both WiFi and GSM/GPRS simultaneously, or select one to use at runtime after reboot.
By design, Blynk user can run ESP32/ESP8266 boards with either WiFi or GSM/GPRS by using different sketches, and have to upload / update firmware to change. This library enables user to include both Blynk GSM/GPRS and WiFi libraries in one sketch, run ***both WiFi and GSM/GPRS simultaneously***, or select one to use at runtime after reboot.

- This is 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).

Expand All @@ -17,7 +17,8 @@ By design, Blynk user can run ESP32/ESP8266 boards with either WiFi or GSM/GPRS

#### Use Arduino Library Manager

The easiest way is to use `Arduino Library Manager`. Search for `BlynkGSM_Manager`, then select / install the latest version.
1. The easiest way is to use `Arduino Library Manager`. Search for `BlynkGSM_Manager`, then select / install the latest version.
2. More detailed instructions at [![arduino-library-badge](https://www.ardu-badge.com/badge/BlynkGSM_Manager.svg?)](https://www.ardu-badge.com/BlynkGSM_Manager)

#### Manual Install

Expand Down Expand Up @@ -388,6 +389,12 @@ gprs apn = rogers-core-appl1.apn
BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG BGBGBGBGBGBGBGBGBGBG
```
### Releases v1.0.3

***New in this version***

1. Add checksum for more reliable data
2. Add clearConfigData() to enable forcing into ConfigPortal Mode when necessary

### Releases v1.0.2

Expand Down
15 changes: 13 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ getServerName KEYWORD2
getGSMToken KEYWORD2
getHWPort KEYWORD2
setHostname KEYWORD2
getFullConfigData

getFullConfigData KEYWORD2
clearConfigData KEYWORD2

#######################################
# Handler helpers
#######################################

BLYNK_READ KEYWORD2
BLYNK_WRITE KEYWORD2
BLYNK_READ_DEFAULT KEYWORD2
Expand All @@ -72,13 +75,17 @@ BLYNK_INPUT KEYWORD2
BLYNK_OUTPUT_DEFAULT KEYWORD2
BLYNK_INPUT_DEFAULT KEYWORD2

#######################################
# Variables binding
#######################################
BLYNK_VAR_INT KEYWORD2
BLYNK_VAR_LONG KEYWORD2
BLYNK_VAR_DOUBLE KEYWORD2
BLYNK_VAR_STRING KEYWORD2

#######################################
# Special defines
#######################################
BLYNK_DEBUG KEYWORD2
BLYNK_DEBUG_ALL KEYWORD2
BLYNK_PRINT KEYWORD2
Expand All @@ -93,7 +100,9 @@ BLYNK_USE_DIRECT_CONNECT KEYWORD2
BLYNK_MAX_SENDBYTES KEYWORD2
BLYNK_MAX_READBYTES KEYWORD2

#######################################
# Periodic actions
#######################################
#BLYNK_EVERY_N_MILLIS KEYWORD2
#BLYNK_EVERY_N_SECONDS KEYWORD2
#BLYNK_EVERY_N_MINUTES KEYWORD2
Expand All @@ -103,7 +112,9 @@ BLYNK_MAX_READBYTES KEYWORD2
# Literals (LITERAL1)
#######################################

#######################################
# Virtual pins
#######################################
V0 LITERAL1
V1 LITERAL1
V2 LITERAL1
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BlynkGSM_Manager",
"version": "1.0.2",
"version": "1.0.3",
"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":
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=BlynkGSM_Manager
version=1.0.2
version=1.0.3
author=Khoi Hoang
license=MIT
maintainer=Khoi Hoang <[email protected]>
sentence=Simple GSM shield Credentials Manager for Blynk and ESP32 / ESP8266 boards, with or without SSL, configuration data saved in SPIFFS / EEPROM
paragraph=Library for configuring/auto(re)connecting GSM shields to Internet and Blynk at runtime. 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.
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
architectures=esp32,esp8266
Expand Down
5 changes: 3 additions & 2 deletions src/Adapters/BlynkGsm_ESP32M.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* 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.2
* Version: 1.0.3
*
* Original Blynk Library author:
* @file BlynkSimpleESP32.h
* @file BlynkSimpleESP8266.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
Expand All @@ -21,6 +21,7 @@
* 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()
*****************************************************************************************************************************/
#ifndef ESP32
#error This code is designed to run on ESP32, not ESP8266 nor Arduino AVR platform! Please check your Tools->Board setting.
Expand Down
5 changes: 3 additions & 2 deletions src/Adapters/BlynkGsm_ESP8266M.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* 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.2
* Version: 1.0.3
*
* Original Blynk Library author:
* @file BlynkSimpleESP32.h
* @file BlynkSimpleESP8266.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
Expand All @@ -21,6 +21,7 @@
* 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()
*****************************************************************************************************************************/
#ifndef ESP8266
#error This code is designed to run on ESP8266, not ESP32 nor Arduino AVR platform! Please check your Tools->Board setting.
Expand Down
5 changes: 3 additions & 2 deletions src/BlynkSimpleEsp32_GSM_WF.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* 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.2
* Version: 1.0.3
*
* Original Blynk Library author:
* @file BlynkSimpleESP32.h
* @file BlynkSimpleESP8266.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
Expand All @@ -21,6 +21,7 @@
* 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()
*****************************************************************************************************************************/

#ifndef BlynkSimpleEsp32_GSM_WF_h
Expand Down
74 changes: 58 additions & 16 deletions src/BlynkSimpleEsp32_GSM_WFM.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* 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.2
* Version: 1.0.3
*
* Original Blynk Library author:
* @file BlynkSimpleESP32.h
* @file BlynkSimpleESP8266.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
Expand All @@ -21,6 +21,7 @@
* 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()
*****************************************************************************************************************************/

#ifndef BlynkSimpleEsp32_GSM_WFM_h
Expand Down Expand Up @@ -77,10 +78,11 @@ typedef struct Configuration
int blynk_port;
char gsm_blynk_tok [36];
char board_name [24];
int checkSum;
} Blynk_WF_Configuration;


// Currently CONFIG_DATA_SIZE = 320 //216
// Currently CONFIG_DATA_SIZE = 324
uint16_t CONFIG_DATA_SIZE = sizeof(struct Configuration);

#define root_html_template " \
Expand Down Expand Up @@ -188,8 +190,8 @@ alert('Updated. Reset'); \

#define BLYNK_SERVER_HARDWARE_PORT 8080

#define BOARD_TYPE "ESP32_GSM_WFM"
#define NO_CONFIG "nothing"
#define BLYNK_BOARD_TYPE "ESP32_GSM_WFM"
#define NO_CONFIG "nothing"

class BlynkWifi
: public BlynkProtocol<BlynkArduinoClient>
Expand Down Expand Up @@ -275,6 +277,8 @@ class BlynkWifi
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_OFF);

WiFi.mode(WIFI_STA);

if (iHostname[0] == 0)
{
#ifdef ESP8266
Expand Down Expand Up @@ -597,10 +601,16 @@ class BlynkWifi

// Check if NULL pointer
if (configData)
memcpy(configData, &BlynkGSM_ESP32_config, sizeof(Blynk_WF_Configuration));
memcpy(configData, &BlynkGSM_ESP32_config, sizeof(BlynkGSM_ESP32_config));

return (configData);
}

void clearConfigData()
{
memset(&BlynkGSM_ESP32_config, 0, sizeof(BlynkGSM_ESP32_config));
saveConfigData();
}

private:
WebServer *server;
Expand Down Expand Up @@ -672,6 +682,17 @@ class BlynkWifi
BLYNK_LOG4(BLYNK_F("DNS1 = "), WiFi.dnsIP(0).toString(), BLYNK_F(", DNS2 = "), WiFi.dnsIP(1).toString());
}

int calcChecksum()
{
int checkSum = 0;
for (uint16_t index = 0; index < (sizeof(BlynkGSM_ESP32_config) - sizeof(BlynkGSM_ESP32_config.checkSum)); index++)
{
checkSum += * ( ( (byte*) &BlynkGSM_ESP32_config ) + index);
}

return checkSum;
}

#if USE_SPIFFS

#define CONFIG_FILENAME BLYNK_F("/gsm_config.dat")
Expand Down Expand Up @@ -708,6 +729,10 @@ class BlynkWifi
File file = SPIFFS.open(CONFIG_FILENAME, "w");
BLYNK_LOG1(BLYNK_F("Save configfile "));

int calChecksum = calcChecksum();
BlynkGSM_ESP32_config.checkSum = calChecksum;
BLYNK_LOG2(BLYNK_F("chkSum = 0x"), String(calChecksum, HEX));

if (file)
{
file.write((uint8_t*) &BlynkGSM_ESP32_config, sizeof(BlynkGSM_ESP32_config));
Expand Down Expand Up @@ -750,15 +775,21 @@ class BlynkWifi
loadConfigData();
}

displayConfigData();
int calChecksum = calcChecksum();

BLYNK_LOG4(BLYNK_F("Calc Cksum = 0x"), String(calChecksum, HEX),
BLYNK_F(", Read Cksum = 0x"), String(BlynkGSM_ESP32_config.checkSum, HEX));

//displayConfigData();

if (strncmp(BlynkGSM_ESP32_config.header, BOARD_TYPE, strlen(BOARD_TYPE)) != 0)
if ( (strncmp(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) ||
(calChecksum != BlynkGSM_ESP32_config.checkSum) )
{
memset(&BlynkGSM_ESP32_config, 0, sizeof(BlynkGSM_ESP32_config));

BLYNK_LOG2(BLYNK_F("Init new configfile, size = "), sizeof(BlynkGSM_ESP32_config));
// doesn't have any configuration
strcpy(BlynkGSM_ESP32_config.header, BOARD_TYPE);
strcpy(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE);
strcpy(BlynkGSM_ESP32_config.wifi_ssid, NO_CONFIG);
strcpy(BlynkGSM_ESP32_config.wifi_pw, NO_CONFIG);
strcpy(BlynkGSM_ESP32_config.wifi_blynk_tok, NO_CONFIG);
Expand All @@ -770,6 +801,8 @@ class BlynkWifi
BlynkGSM_ESP32_config.blynk_port = BLYNK_SERVER_HARDWARE_PORT;
strcpy(BlynkGSM_ESP32_config.gsm_blynk_tok, NO_CONFIG);
strcpy(BlynkGSM_ESP32_config.board_name, NO_CONFIG);
// Don't need
BlynkGSM_ESP32_config.checkSum = 0;

saveConfigData();

Expand Down Expand Up @@ -828,15 +861,19 @@ class BlynkWifi
EEPROM.begin(EEPROM_SIZE);
EEPROM.get(EEPROM_START, BlynkGSM_ESP32_config);

displayConfigData();

if (strncmp(BlynkGSM_ESP32_config.header, BOARD_TYPE, strlen(BOARD_TYPE)) != 0)
int calChecksum = calcChecksum();

BLYNK_LOG4(BLYNK_F("Calc Cksum = 0x"), String(calChecksum, HEX),
BLYNK_F(", Read Cksum = 0x"), String(BlynkGSM_ESP32_config.checkSum, HEX));

if ( (strncmp(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE, strlen(BLYNK_BOARD_TYPE)) != 0) ||
(calChecksum != BlynkGSM_ESP32_config.checkSum) )
{
memset(&BlynkGSM_ESP32_config, 0, sizeof(BlynkGSM_ESP32_config));

BLYNK_LOG2(BLYNK_F("Init new EEPROM, size = "), EEPROM_SIZE /*EEPROM.length()*/);
// doesn't have any configuration
strcpy(BlynkGSM_ESP32_config.header, BOARD_TYPE);
strcpy(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE);
strcpy(BlynkGSM_ESP32_config.wifi_ssid, NO_CONFIG);
strcpy(BlynkGSM_ESP32_config.wifi_pw, NO_CONFIG);
strcpy(BlynkGSM_ESP32_config.wifi_blynk_tok, NO_CONFIG);
Expand All @@ -848,6 +885,8 @@ class BlynkWifi
BlynkGSM_ESP32_config.blynk_port = BLYNK_SERVER_HARDWARE_PORT;
strcpy(BlynkGSM_ESP32_config.gsm_blynk_tok, NO_CONFIG);
strcpy(BlynkGSM_ESP32_config.board_name, NO_CONFIG);
// Don't need
BlynkGSM_ESP32_config.checkSum = 0;

EEPROM.put(EEPROM_START, BlynkGSM_ESP32_config);
EEPROM.commit();
Expand Down Expand Up @@ -876,7 +915,10 @@ class BlynkWifi

void saveConfigData()
{
BLYNK_LOG2(BLYNK_F("Save EEPROM, size = "), EEPROM_SIZE /*EEPROM.length()*/);
int calChecksum = calcChecksum();
BlynkGSM_ESP32_config.checkSum = calChecksum;
BLYNK_LOG4(BLYNK_F("Save EEPROM, size = "), EEPROM.length(), BLYNK_F(", chkSum = 0x"), String(calChecksum, HEX));

EEPROM.put(EEPROM_START, BlynkGSM_ESP32_config);
EEPROM.commit();
}
Expand Down Expand Up @@ -965,7 +1007,7 @@ class BlynkWifi
if (number_items_Updated == 0)
{
memset(&BlynkGSM_ESP32_config, 0, sizeof(BlynkGSM_ESP32_config));
strcpy(BlynkGSM_ESP32_config.header, BOARD_TYPE);
strcpy(BlynkGSM_ESP32_config.header, BLYNK_BOARD_TYPE);
}

if (key == "wf_id")
Expand Down Expand Up @@ -1114,7 +1156,7 @@ class BlynkWifi

BLYNK_LOG1(BLYNK_F("hR: Reset"));

// Delay then reset the ESP8266 after save data
// Delay then reset the ESP32 after save data
delay(1000);
ESP.restart();
}
Expand Down
5 changes: 3 additions & 2 deletions src/BlynkSimpleEsp8266_GSM_WF.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* 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.2
* Version: 1.0.3
*
* Original Blynk Library author:
* @file BlynkSimpleESP32.h
* @file BlynkSimpleESP8266.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
Expand All @@ -21,6 +21,7 @@
* 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()
*****************************************************************************************************************************/

#ifndef BlynkSimpleESP8266_GSM_WF
Expand Down
Loading

0 comments on commit f5682ce

Please sign in to comment.