Hello. I am trying to add one more thing to the Costas great example of “noBlynkBlock”
Basically exactly what he did for us, with the ability to enter AP mode on request (pin)
So… i took Costas sketch and also wifi.manager (by tzapu). At this point, the sketch is doing what Costas did, and when you put pin 0 to ground you have wifiManager AP page (192.168.4.1) so you can enter new wifi/pass credentials. Everything works just perfect.
Then i was trying to move forward with Tzapu example of adding custom parameters to wifi.manager so i can also enter the token on that config page. While this works just fine in his examples of the library, i cannot make it work with the Costas code.
Can someone please help me integrate the SPIFFS part of the tzapu wifi.manager into this code?
No matter how much i’ve tried i end up with 2 possibilities:
- Costas code gets messed up
- The token field appears on the page, i can enter my token, hit save, but my sketch will never connect to blynk server anymore although wifi stays connected.
This is the current sketch which works perfect, except that it has the token “hard coded”.
THANK YOU!
/* NoBlynkBlock.ino by Costas for https://community.blynk.cc/t/blynk-is-blocking-if-internet-is-down/16809
will recover from server or router going down
*/
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <BlynkSimpleEsp8266.h>
#define TRIGGER_PIN 0
char server[] = "server";
char auth[] = "token";
BlynkTimer timer;
unsigned int myServerTimeout = 3500; // 3.5s server connection timeout (SCT)
unsigned int myWiFiTimeout = 3200; // 3.2s WiFi connection timeout (WCT)
unsigned int functionInterval = 2000; // 2s function call frequency (FCF)
unsigned int blynkInterval = 25000; // 25.0s check server frequency (CSF)
void setup(){
Serial.begin(115200);
Serial.println();
pinMode(BUILTIN_LED, OUTPUT);
if(WiFi.status() == 6){
Serial.println("\tWiFi not connected yet.");
}
timer.setInterval(functionInterval, myfunction);// run some function at intervals per functionInterval
timer.setInterval(blynkInterval, checkBlynk); // check connection to server per blynkInterval
timer.setInterval(500, configAP ); // check pin to enter config mode
unsigned long startWiFi = millis();
WiFiManager wifiManager;
//wifiManager.resetSettings(); //reset settings - for testing
wifiManager.setTimeout(600); // 10 minutes to enter data and then Wemos resets to try again.
while (WiFi.status() != WL_CONNECTED){
delay(500);
if(millis() > startWiFi + myWiFiTimeout){
Serial.println("\tCheck the WiFi router. ");
break;
}
}
Blynk.config(auth, server);
checkBlynk();
}
void myfunction(){
Serial.println("\tLook, no Blynk block.");
if(WiFi.status()== 3){
Serial.println("\tWiFi still connected.");
//toggle led state
int state = digitalRead(BUILTIN_LED); // get the current state of GPIO2 pin
digitalWrite(BUILTIN_LED, !state); // set pin to the opposite state
}
if(Blynk.connected()){
Blynk.virtualWrite(V3, millis() / 1000);
}
}
void checkBlynk() {
if (WiFi.status() == WL_CONNECTED)
{
unsigned long startConnecting = millis();
while(!Blynk.connected()){
Blynk.connect();
if(millis() > startConnecting + myServerTimeout){
Serial.print("Unable to connect to server. ");
break;
}
}
}
if (WiFi.status() != 3) {
Serial.print("\tNo WiFi. ");
}
Serial.printf("\tChecking again in %is.\n", blynkInterval / 1000);
Serial.println();
}
void configAP() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW ) {
WiFiManager wifiManager;
if (!wifiManager.startConfigPortal("AP")) {
Serial.println("failed to connect and hit timeout");
delay(5000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}
}
}
void loop(){
timer.run();
if (Blynk.connected()) {
Blynk.run();
}
}