Simple GSM/GPRS shield Credentials Manager for Blynk
Posted: Sun Mar 22, 2020 12:01 am
https://github.com/khoih-prog/BlynkGSM_Manager
How To Install Using Arduino Library Manager
This library is a simple GSM shield Manager for Blynk and ESP32 / ESP8266 boards, with or without SSL, configuration data saved in SPIFFS / EEPROM. The 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).
- 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.
So, how it works?
If it detects no valid stored Credentials or it cannot connect to the Blynk server in 30 seconds, it will switch to Configuration Mode. You will see your built-in LED turned ON. In Configuration Mode, it starts a WiFi access point called ESP_xxxxxx. Connect to it using password MyESP_xxxxxx.
You can set:
1. static Config Portal IP address by using Blynk_WF.setConfigPortalIP(IPAddress(xxx, xxx, xxx, xxx))
2. random Config Portal WiFi channel by using Blynk_WF.setConfigPortalChannel(0)
3. selected Config Portal WiFi channel by using Blynk_WF.setConfigPortalChannel(channel)

After you connected, go to http://192.168.4.1., the Browser will display the following page:

Enter your credentials (APN, GPRS User, GPRS Pass, GPRS PIN, Blynk Token, Server and Port).

Then click Save. After the board auto-restarted, you will see if it's connected to your Blynk server successfully.
Sample Code
This is the link to Blynk
Blynk IoT Platform
Blynk was designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, visualize it and do many other cool things.

You can install and use Local Blynk Server (RPi Zero W, 3B+, 4, Laptop, PC, etc) to have full control.
The Server source code is in Public Domain and written in Java. You can download, compile and use to be sure having full control.
Use Local Blynk Server
Blynk Server
Blynk Server Source Code
Releases v1.0.5
1. Add more modem supports. Thanks to new TinyGSM library v0.10.1
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 LTE Modules (SIM7100E, SIM7500E, SIM7500A, SIM7600C, SIM7600E)
- SIMCom SIM7000E 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_)
- Sequans Monarch LTE Cat M1/NB1 (VZM20Q)
- Quectel BG96
- Quectel M95
- Quectel MC60 (alpha)
Supported boards/modules
- Arduino MKR GSM 1400
- GPRSbee
- Microduino GSM
- Adafruit FONA (Mini Cellular GSM Breakout)
- Adafruit FONA 800/808 Shield
- Industruino GSM
- RAK WisLTE (alpha)
- ... other modules, based on supported modems. Some boards require special configuration.
More modems may be supported later:
- [ ] Quectel M10, UG95
- [ ] SIMCom SIM7020
- [ ] Telit GL865
- [ ] ZTE MG2639
- [ ] Hi-Link HLK-RM04
How To Install Using Arduino Library Manager
This library is a simple GSM shield Manager for Blynk and ESP32 / ESP8266 boards, with or without SSL, configuration data saved in SPIFFS / EEPROM. The 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).
- 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.
So, how it works?
If it detects no valid stored Credentials or it cannot connect to the Blynk server in 30 seconds, it will switch to Configuration Mode. You will see your built-in LED turned ON. In Configuration Mode, it starts a WiFi access point called ESP_xxxxxx. Connect to it using password MyESP_xxxxxx.
You can set:
1. static Config Portal IP address by using Blynk_WF.setConfigPortalIP(IPAddress(xxx, xxx, xxx, xxx))
2. random Config Portal WiFi channel by using Blynk_WF.setConfigPortalChannel(0)
3. selected Config Portal WiFi channel by using Blynk_WF.setConfigPortalChannel(channel)

After you connected, go to http://192.168.4.1., the Browser will display the following page:

Enter your credentials (APN, GPRS User, GPRS Pass, GPRS PIN, Blynk Token, Server and Port).

Then click Save. After the board auto-restarted, you will see if it's connected to your Blynk server successfully.
Sample Code
Code: Select all
#define BLYNK_PRINT Serial
// Select your modem:
#define TINY_GSM_MODEM_SIM800
// Increase RX buffer if needed
#define TINY_GSM_RX_BUFFER 1024
// 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
// EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE
#define EEPROM_START 1024
//#define USE_BLYNK_WM false
#define USE_BLYNK_WM true
#define USE_SPIFFS false
#define EEPROM_SIZE 2048
#define EEPROM_START 256
#include <BlynkSimpleTinyGSM_M.h>
#if USE_BLYNK_WM
#include <BlynkSimpleEsp32_GSM_WFM.h>
#else
#include <BlynkSimpleEsp32_GSM_WF.h>
// 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 <TinyGsmClient.h>
// 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.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
void heartBeatPrint(void)
{
static int num = 1;
if (Blynk_WF.connected())
{
Serial.print(F("B"));
}
else
{
Serial.print(F("F"));
}
if (Blynk_GSM.connected())
{
Serial.print(F("G"));
}
else
{
Serial.print(F("F"));
}
if (num == 40)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 60000L
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
// report status to Blynk
heartBeatPrint();
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}
bool valid_apn = false;
bool GSM_CONNECT_OK = false;
void setup()
{
// Set console baud rate
SerialMon.begin(115200);
SerialMon.println(F("\nStart TTGO-TCALL-GSM"));
// Set-up modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
SerialMon.println(F("Set GSM module baud rate"));
// Set GSM module baud rate
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
Serial.println(F("Use WiFi to connect Blynk"));
#if USE_BLYNK_WM
// Use channel = 0 => random Config Portal WiFi channel to avoid conflict
Blynk_WF.setConfigPortalIP(IPAddress(192, 168, 100, 1));
Blynk_WF.setConfigPortalChannel(0);
Blynk_WF.begin("TTGO-TCALL-GSM");
#else
Blynk_WF.begin(wifi_blynk_tok, ssid, pass, blynk_server, BLYNK_HARDWARE_PORT);
Blynk_GSM.config(modem, gsm_blynk_tok, blynk_server, BLYNK_HARDWARE_PORT);
GSM_CONNECT_OK = Blynk_GSM.connectNetwork(apn, gprsUser, gprsPass);
if (GSM_CONNECT_OK)
Blynk_GSM.connect();
#endif
#if USE_BLYNK_WM
Blynk_WF_Configuration localBlynkGSM_ESP32_config;
Blynk_WF.getFullConfigData(&localBlynkGSM_ESP32_config);
Serial.print(F("gprs apn = "));
Serial.println(localBlynkGSM_ESP32_config.apn);
if (String(localBlynkGSM_ESP32_config.apn) == String("nothing"))
{
Serial.println(F("No valid stored apn. Have to run WiFi then enter config portal"));
valid_apn = false;
}
else
{
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);
if (GSM_CONNECT_OK)
Blynk_GSM.connect();
}
#endif
}
void loop()
{
Blynk_WF.run();
#if USE_BLYNK_WM
if (valid_apn)
#endif
Blynk_GSM.run();
check_status();
}
Blynk IoT Platform
Blynk was designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, visualize it and do many other cool things.

You can install and use Local Blynk Server (RPi Zero W, 3B+, 4, Laptop, PC, etc) to have full control.
The Server source code is in Public Domain and written in Java. You can download, compile and use to be sure having full control.
Use Local Blynk Server
Blynk Server
Blynk Server Source Code
Releases v1.0.5
1. Add more modem supports. Thanks to new TinyGSM library v0.10.1
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 LTE Modules (SIM7100E, SIM7500E, SIM7500A, SIM7600C, SIM7600E)
- SIMCom SIM7000E 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_)
- Sequans Monarch LTE Cat M1/NB1 (VZM20Q)
- Quectel BG96
- Quectel M95
- Quectel MC60 (alpha)
Supported boards/modules
- Arduino MKR GSM 1400
- GPRSbee
- Microduino GSM
- Adafruit FONA (Mini Cellular GSM Breakout)
- Adafruit FONA 800/808 Shield
- Industruino GSM
- RAK WisLTE (alpha)
- ... other modules, based on supported modems. Some boards require special configuration.
More modems may be supported later:
- [ ] Quectel M10, UG95
- [ ] SIMCom SIM7020
- [ ] Telit GL865
- [ ] ZTE MG2639
- [ ] Hi-Link HLK-RM04