To help you to eliminate hardcoding your Wifi and Blynk credentials for Mega/Teensy boards running ESP8266 AT shields, and updating/reflashing every time when you need to change them. Configuration data are saved in configurable locatioon in EEPROM.
With version v1.0.0 or later, you now can configure:
Config Portal Static IP address, Name and Password.
Static IP address, Gateway, Subnet Mask and 2 DNS Servers IP addresses.
Sample Code
#define BLYNK_PRINT Serial
#if ( defined(ESP8266) || defined(ESP32) || defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || !defined(CORE_TEENSY) )
#error This code is intended to run on Teensy platform! Please check your Tools->Board setting.
#endif
#ifdef CORE_TEENSY
// For Teensy 4.0
#define EspSerial Serial2 //Serial2, Pin RX2 : 7, TX2 : 8
#if defined(__IMXRT1062__)
#define BOARD_TYPE "TEENSY 4.0"
#else
#define BOARD_TYPE BLYNK_INFO_DEVICE
#endif
#else
// For Mega
#define EspSerial Serial3
#define BOARD_TYPE "AVR Mega"
#endif
#include <ESP8266_Lib.h>
// Start location in EEPROM to store config data. Default 0
// Config data Size currently is 128 bytes)
#define EEPROM_START 48
#define USE_BLYNK_WM true
//#define USE_BLYNK_WM false
#if USE_BLYNK_WM
#include <BlynkSimpleShieldEsp8266_Teensy_WM.h>
#else
#include <BlynkSimpleShieldEsp8266_Teensy.h>
#define USE_LOCAL_SERVER true
#if USE_LOCAL_SERVER
char auth[] = "****";
String BlynkServer = "account.duckdns.org";
//String BlynkServer = "192.168.2.112";
#else
char auth[] = "******";
String BlynkServer = "blynk-cloud.com";
#endif
#define BLYNK_SERVER_HARDWARE_PORT 8080
// Your WiFi credentials.
char ssid[] = "****";
char pass[] = "****";
#endif
// Your Teensy <-> ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
void heartBeatPrint(void)
{
static int num = 1;
if (Blynk.connected())
{
Serial.print("B");
}
else
{
Serial.print("F");
}
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(" ");
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 15000L
// 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;
}
}
void setup()
{
// Debug console
Serial.begin(115200);
delay(1000);
// initialize serial for ESP module
EspSerial.begin(ESP8266_BAUD);
Serial.println("\nStart Blynk WiFiManager using ESP8266_AT_Shield on " + String(BOARD_TYPE));
#if USE_BLYNK_WM
Serial.println("Start Blynk_WM");
// Set Config Portal AP IP Address
Blynk.setConfigPortalIP(IPAddress(192, 168, 100, 1));
// Set Config Portal SSID and Password
//Blynk.setConfigPortal("Teensy4", "MyTeensy4");
Blynk.begin(wifi);
#else
Serial.println("Start Blynk");
Blynk.begin(auth, wifi, ssid, pass, BlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
#endif
}
void loop()
{
Blynk.run();
check_status();
}
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.
Reduce html and code size for faster Config Portal response.
Enhance GUI.
So, how it works?
If 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 configurable access point, default called Teensy4_XXXXXX, SAMD_XXXXXX, DUE_XXXXXX,Mega_XXXXXX or STM32_XXXXXX. Connect to it using password MyTeensy4_XXXXXX, MySAMD_XXXXXX, MyDUE_XXXXXX, MyMega_XXXXXX or MySTM32_XXXXXX.
After you connected, please, go to http://192.168.4.1 or the AP IP you specified.
New logic for USE_DEFAULT_CONFIG_DATA to autoload Config / Dynamic Data in developing stage.
Major Releases v1.0.5
Add support to nRF52 (AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc.). Dynamic custom parameters to be saved automatically in LittleFS.
Add support to Adafruit SAMD21/SAM51 (Itsy-Bitsy M0/M4, Metro M0/M4, Grand Central M4, Feather M0/M4 Express, etc.). Dynamic custom parameters to be saved automatically in FlashStorage.
Add MultiWiFi features for WiFi
Add DoubleResetDetector (DRD) feature.
Increase WPA2 SSID and PW to 63 chars. Permit special chars such as !,@,#,$,%,^,&,* into data fields.