Thanks khoih-prog for Blynk_WM.
Questions and observations on your Blynk_WM.
I’m old at ESP8266, older on Arduino, still pretty much a newbie at Blynk. I am on Win 10 using Arduino IDE 1.8.12, Blynk Lib 0.6.1, and Blynk_WiFiManager 1.0.12. I compile to a generic NODE MCU ESP8266 and an Adafruit ESP32 HUZZAH.
I find the <BlynkSimpleEsp32/8266.h> non-_WM versions work wonderfully for me, both SSL and non-SSL, both on ESP32 and ESP8266. Love it. Thanks.
I’m struggling with <BlynkSimpleEsp32/8266_SSL_WM.h> and <BlynkSimpleEsp32/8266_SSL_WM.h> with ESP8266 and ESP32.
On the _WM versions, I can get the WM Config Portal to post and can enter values to get Blynk connected and running. Thanks. It works.
Questions and observations:
-
How can my sketch pre-program default values for the WM Config Portal? It would be nice to not start with blanks everywhere in the Portal.
-
When using correct SSID and WiFi Password entered into the WM Config Portal, once WiFi connects, the device AP Config Portal WiFi signal shuts down, even if the device cannot connect to the Blynk server. So if the WM connects to WiFi but not to Blynk, there is no WM Portal WiFi signal from the ESP32 or ESP8266 to allow the user to change or update the WM Config Portal info for Blynk servers. Is there a way to change this behavior, keep the WM Config Portal WiFi running, or turn it on for a few minutes after reboot for changes to parameters?
-
I have been unable to get the WM Config Portal AP SSID and Password to set, keep getting the default WiFi name and password. (The Config Portal IP Address worked for me, thanks!) Any ideas?
My overly switched code is attached. It’s a simple demo program that pulses a heartbeat LED. It works for SSL, non-SSL, ESP32 and 8266.
If someone has time to look through this, I’d love to be able to use the WM Config Portal on my devices.
Thanks again and in advance.
#define SERIAL_SPEED 230400
#define PROGRAM_NAME "AAA-Blynk WiFiMgr Demo_ESP32_ESP8266"
// Uses ESP32 and ESP8266 to select compile choices
//BLYNK Stuff here
#define BLYNK_PRINT Serial
#define USE_SSL true // to easily select SSL or not
#define USE_WM true // to easily select WiFi Manager or not
// REMEMBER: not using _WM means we manage our own initial WiFi connection
#if USE_WM
#define USE_SPIFFS false // Choosing EEPROM over SPIFFS here
#if (!USE_SPIFFS)
// 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 512
#endif
#define USE_DYNAMIC_PARAMETERS false // see Github doc
// Force some params in Blynk, only valid for library version 1.0.1 and later
// (from the Github doc)
#define TIMEOUT_RECONNECT_WIFI 10000L
#define RESET_IF_CONFIG_TIMEOUT true
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET 5
#endif
#if USE_SSL
#ifdef ESP8266
#if USE_WM
#include <BlynkSimpleEsp8266_SSL_WM.h>
#else
#include <BlynkSimpleEsp8266_SSL.h>
#endif
#endif
#ifdef ESP32
#if USE_WM
#include <BlynkSimpleEsp32_SSL_WM.h>
#else
#include <BlynkSimpleEsp32_SSL.h>
#endif
#endif
#else // NOT using SSL
#ifdef ESP8266
#if USE_WM
#include <BlynkSimpleEsp8266_WM.h>
#else
#include <BlynkSimpleEsp8266.h>
#endif
#endif
#ifdef ESP32
#if USE_WM
#include <BlynkSimpleEsp32_WM.h>
#else
#include <BlynkSimpleEsp32.h>
#endif
#endif
#endif
#if USE_WM
#define USE_DYNAMIC_PARAMETERS false
MenuItem myMenuItems [] = {};
uint16_t NUM_MENU_ITEMS = 0;
#endif // USE_WM
char blynkAuth[] = "<my auth>"; // BLYNK Auth
char WiFiSSID[] = "<my ssid"; // network SSID (name)
char WiFiPass[] = "<my passcode>"; // network password
BlynkTimer myTimer;
// Blynk timers to blink a heartbeat LED on and off
int heartbeatLEDinterval = 3000; // interval between heartbeats for onboard and Blynk Virtual LED in millisec
int heartbeatLEDtimerID;
int heartbeatLEDduration = 750; // duraction of each blink in millisec (set as an interval timer)
int heartbeatLEDdurationTimerID;
bool heartbeatLEDon = false; // this lets me use the same routine for the turn-on timer and the turn-off interval
#define BLYNK_HEARTBEAT_LED V2
WidgetLED heartbeatLED( BLYNK_HEARTBEAT_LED ); // want a blinking LED on the display to show we're live
/* setup
* Set up WiFi, Blynk & Blynk timers
* Set up Blue LED on board
*/
void setup()
{
Serial.begin ( SERIAL_SPEED );
delay ( 500 );
Serial.println ( "\n\n=======================================" );
Serial.print ( PROGRAM_NAME );
#if USE_SSL
Serial.println ( " ** Using SSL ** \n" );
#endif
Serial.println();
connectToLANandBlynk();
// Initialize Onboard LED
pinMode ( LED_BUILTIN, OUTPUT );
digitalWrite ( LED_BUILTIN, LOW );
// Set Blynk Virtual LED OFF
heartbeatLED.off(); // Blynk Virtual LED
heartbeatLEDblink(); // first heartbeat
Serial.println ( "\nSetup complete \n" );
} //end setup
void loop()
{
Blynk.run();
myTimer.run();
}
void connectToLANandBlynk()
{
// Setup WLAN and Blynk
Serial.print ( "\nSetting up WLAN and Blynk " );
#if USE_WM
Serial.println ( "WITH WiFiManager" );
#else
Serial.println ( "WITHOUT WiFiManager" );
#endif
#if USE_WM
Serial.println ( "Starting Blynk.begin (with WM)" );
Blynk.setConfigPortal ( "TestPortal", "123" );
Serial.println ( "Blynk.setConfigPortal(TestPortal, 123);" );
Blynk.setConfigPortalIP ( IPAddress ( 192, 168, 220, 1 ) );
Blynk.config ( blynkAuth );
Blynk.begin ( "Blynk-Configurator" );
#else//NOT using WM
Serial.println ( "Starting WiFi.begin (no WM)" );
WiFi.begin ( WiFiSSID, WiFiPass );
Serial.println ( "... waiting a few seconds for WiFi ..." );
delay ( 7000 ); // For esp8266, it needs a delay to realize it has connected
// REBOOT if we do not have a good WiFi connection
if ( WiFi.status() != WL_CONNECTED )
{
Serial.println ( "Resetting in a few seconds..." );
delay ( 3000 );
ESP.restart();
}
// Configure and launch Blynk
Blynk.config ( blynkAuth );
Blynk.connect ( 2500 ); // Don't get stuck hanging for more than 2500 millis.
#endif // using WM
if ( Blynk.connected() ) Serial.println ( "Blynk connected just fine\n" );
else Serial.println ( "Blynk NOT CONNECTED \n\n" );
#if USE_WM
#if USE_SPIFFS
Serial.println("\nBlynk using SPIFFS connected. Board Name : " + Blynk.getBoardName());
#else
Serial.println("\nBlynk using EEPROM connected. Board Name : " + Blynk.getBoardName());
Serial.printf("EEPROM size = %d bytes, EEPROM start address = %d / 0x%X\n", EEPROM_SIZE, EEPROM_START, EEPROM_START);
#endif
#endif
Serial.println ( "Setting up Blynk timer" );
// Interval timer for heartbeatLED (Blynk LED and onboard LED
heartbeatLEDtimerID = myTimer.setInterval ( heartbeatLEDinterval, heartbeatLEDblink );
Serial.println ( "..Blynk config and timers setup complete\n" );
} //end connectToBlynk
void heartbeatLEDblink()
/* Blink the on-board LED AND the Virtual Blynk LED
* First time called, it turne the LEDs on, then sets a timer to turn LED off
* When the timer triggers, same routine turns the LEDs off
*/
{
if ( heartbeatLEDon ) // if LED is on, turn it off and vice cersa
{
heartbeatLED.off(); // Blynk Virtual LED
digitalWrite ( LED_BUILTIN, LOW ); // On-board LED
Serial.println ( " ..." );
} else
{
heartbeatLED.on(); // Blynk Virtual LED
digitalWrite ( LED_BUILTIN, HIGH ); // On-board LED
// Set the timer to turn off the LEDs in a bit
heartbeatLEDdurationTimerID = myTimer.setTimeout ( heartbeatLEDduration, heartbeatLEDblink );
Serial.print ( "... heartbeat of " ); Serial.print ( PROGRAM_NAME );
Serial.print ( " WiFi.status() = " ); Serial.print ( WiFi.status() );
}
heartbeatLEDon = ! heartbeatLEDon; // flip status
} //end heartbeatLEDblink
// CALLED WHEN CONNECTING TO BLYNK SERVERS
// GETS CALLED IMMEDIATELY ON FIRST CONNECT
// THIS SYNCS UP SLIDER AND PUSHBUTTON WHEN BLYNK CONNECTS - EVEN FOR THE FIRST TIME
BLYNK_CONNECTED()
{
Serial.println ( "\nBLYNK_CONNECTED..." );
}