BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

wifiMananger

Olá Luciano,

Yes I can try to help you,
please send us the code to insert , don’t forget backtips ```

#include <FS.h>                   //this needs to be first, or it all crashes and burns...
//#define BLYNK_DEBUG           // Comment this out to disable debug and save space
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager

//for LED status
#include <Ticker.h>
Ticker ticker;

#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson

char blynk_token[34] = "BLYNK_TOKEN";

bool shouldSaveConfig = false; //flag for saving data

#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;
void checkPhysicalButton1();
void checkPhysicalButton2();
void checkPhysicalButton3();
void tick()
{
  //toggle state
int estadorele1 = LOW;
int estadorele2 = LOW;
int estadorele3 = LOW;
int estadobotao1 = HIGH;
int estadobotao2 = HIGH;
int estadobotao3 = HIGH;
//int state = digitalRead(BUILTIN_LED);  // get the current state of GPIO1 pin
 // digitalWrite(BUILTIN_LED, !state);     // set pin to the opposite state
}
BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
 }

BLYNK_WRITE(V1)
{
  estadorele1 = param.asInt();
  digitalWrite(5, estadorele1); 

}
void checkPhysicalButton1()
{
  if (digitalRead(12) == LOW)
  {
    if(estadobotao1 != LOW)
    {
      estadorele1 = !estadorele1;
      digitalWrite(5,estadorele1);
      Blynk.virtualWrite(V1, estadorele1);
    }
    estadobotao1 = LOW;
  }
  else
  {
    estadobotao1 = HIGH;
  }
}


BLYNK_WRITE(V2)
{
  estadorele2 = param.asInt();
  digitalWrite(4, estadorele2); 
}

void checkPhysicalButton2()
{
  if (digitalRead(14) == LOW)
  {
    if(estadobotao2 != LOW)
    {
      estadorele2 = !estadorele2;
      digitalWrite(4,estadorele2);
      Blynk.virtualWrite(V2, estadorele2);
    }
    estadobotao2 = LOW;
  }
  else
  {
    estadobotao2 = HIGH;
  }
}

BLYNK_WRITE(V3)
{
  estadorele3 = param.asInt();
  digitalWrite(2, estadorele3); 
}

void checkPhysicalButton3()
{
  if (digitalRead(16) == LOW)
  {
    if(estadobotao3 != LOW)
    {
      estadorele3 = !estadorele3;
      digitalWrite(2,estadorele3);
      Blynk.virtualWrite(V3, estadorele3);
    }
    estadobotao3 = LOW;
  }
  else
  {
    estadobotao3 = HIGH;
  }
}


void saveConfigCallback ()   //callback notifying us of the need to save config
{
  Serial.println("Should save config");
  shouldSaveConfig = true;
  ticker.attach(0.2, tick);  // led toggle faster
}

void setup()
{

  Serial.begin(115200);
  Serial.println();

  //set led pin as output
  //pinMode(BUILTIN_LED, OUTPUT);
  pinMode(12, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(115200);
  timer.setInterval(100L, checkPhysicalButton1);
  timer.setInterval(100L, checkPhysicalButton2);
  timer.setInterval(100L, checkPhysicalButton3);
  
  // start ticker with 0.5 because we start in AP mode and try to connect
  ticker.attach(0.6, tick);

  //SPIFFS.format();    //clean FS, for testing
  Serial.println("Mounting FS...");    //read configuration from FS json

  if (SPIFFS.begin()) {
    Serial.println("Mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("Reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("Opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          strcpy(blynk_token, json["blynk_token"]);

        } else {
          Serial.println("Failed to load json config");
        }
      }
    }
  } else {
    Serial.println("Failed to mount FS");
  }
  //end read

  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);   // was 32 length
  
  Serial.println(blynk_token);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  wifiManager.setSaveConfigCallback(saveConfigCallback);   //set config save notify callback

  //set static ip
  // this is for connecting to Office router not GargoyleTest but it can be changed in AP mode at 192.168.4.1
  //wifiManager.setSTAStaticIPConfig(IPAddress(192,168,10,111), IPAddress(192,168,10,90), IPAddress(255,255,255,0));
  
  wifiManager.addParameter(&custom_blynk_token);   //add all your parameters here

  //wifiManager.resetSettings();  //reset settings - for testing

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  
  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep, in seconds
  wifiManager.setTimeout(600);   // 10 minutes to enter data and then Wemos resets to try again.

  //fetches ssid and pass and tries to connect, if it does not connect it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("CentralHeatingAP", "MY123PWD")) {
    Serial.println("Failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }
  Serial.println("Connected Central Heating System :)");   //if you get here you have connected to the WiFi
  ticker.detach();
  //turn LED off
  digitalWrite(BUILTIN_LED, HIGH);

  strcpy(blynk_token, custom_blynk_token.getValue());    //read updated parameters

  if (shouldSaveConfig) {      //save the custom parameters to FS
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("Failed to open config file for writing");
    }

    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

  Serial.println("local ip");
  Serial.println(WiFi.localIP());
  
  Blynk.config(blynk_token);
  //Blynk.connect();

}

  void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer  
}

Me confirma se foi formatado, por favor.

sim está bem formatado !

but where is your problem ?
did you resolved wifimanager issue ?

Se eu fecho a chave que está na linha 36 da este erro:

Se eu retiro a chave da linha 36 da este erro:

I thing there is a missing bracket in your code
I will edit your code to see where it’s missing

ok.

Alexis, este é o código antes de incluir o meu código.

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager

//for LED status
#include <Ticker.h>
Ticker ticker;

void tick()
{
  //toggle state
  int state = digitalRead(BUILTIN_LED);  // get the current state of GPIO1 pin
  digitalWrite(BUILTIN_LED, !state);     // set pin to the opposite state
}

//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
  Serial.println(WiFi.softAPIP());
  //if you used auto generated SSID, print it
  Serial.println(myWiFiManager->getConfigPortalSSID());
  //entered config mode, make led toggle faster
  ticker.attach(0.2, tick);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  
  //set led pin as output
  pinMode(BUILTIN_LED, OUTPUT);
  // start ticker with 0.5 because we start in AP mode and try to connect
  ticker.attach(0.6, tick);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;
  //reset settings - for testing
  //wifiManager.resetSettings();

  //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
  wifiManager.setAPCallback(configModeCallback);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect()) {
    Serial.println("failed to connect and hit timeout");
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(1000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
  ticker.detach();
  //keep LED on
  digitalWrite(BUILTIN_LED, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Desculpa, o exemplo errado.
O certo é este aqui.

#include <FS.h>                   //this needs to be first, or it all crashes and burns...
//#define BLYNK_DEBUG           // Comment this out to disable debug and save space
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h>
//for LED status
#include <Ticker.h>
Ticker ticker;

//#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson

char blynk_token[34] = "BLYNK_TOKEN";

bool shouldSaveConfig = false; //flag for saving data

#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;

void tick()
{
  //toggle state
  int state = digitalRead(BUILTIN_LED);  // get the current state of GPIO1 pin
  digitalWrite(BUILTIN_LED, !state);     // set pin to the opposite state
}

void saveConfigCallback () {  //callback notifying us of the need to save config
  Serial.println("Should save config");
  shouldSaveConfig = true;
  ticker.attach(0.2, tick);  // led toggle faster
}

void setup()
{

  Serial.begin(115200);
  Serial.println();

  //set led pin as output
  pinMode(BUILTIN_LED, OUTPUT);
  // start ticker with 0.5 because we start in AP mode and try to connect
  ticker.attach(0.6, tick);

  //SPIFFS.format();    //clean FS, for testing
  Serial.println("Mounting FS...");    //read configuration from FS json

  if (SPIFFS.begin()) {
    Serial.println("Mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("Reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("Opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          strcpy(blynk_token, json["blynk_token"]);

        } else {
          Serial.println("Failed to load json config");
        }
      }
    }
  } else {
    Serial.println("Failed to mount FS");
  }
  //end read

  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);   // was 32 length
  
  Serial.println(blynk_token);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  wifiManager.setSaveConfigCallback(saveConfigCallback);   //set config save notify callback

  //set static ip
  // this is for connecting to Office router not GargoyleTest but it can be changed in AP mode at 192.168.4.1
  //wifiManager.setSTAStaticIPConfig(IPAddress(192,168,10,111), IPAddress(192,168,10,90), IPAddress(255,255,255,0));
  
  wifiManager.addParameter(&custom_blynk_token);   //add all your parameters here

  //wifiManager.resetSettings();  //reset settings - for testing

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  
  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep, in seconds
  wifiManager.setTimeout(600);   // 10 minutes to enter data and then Wemos resets to try again.

  //fetches ssid and pass and tries to connect, if it does not connect it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("CentralHeatingAP", "MY123PWD")) {
    Serial.println("Failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }
  Serial.println("Connected Central Heating System :)");   //if you get here you have connected to the WiFi
  ticker.detach();
  //turn LED off
  digitalWrite(BUILTIN_LED, HIGH);

  strcpy(blynk_token, custom_blynk_token.getValue());    //read updated parameters

  if (shouldSaveConfig) {      //save the custom parameters to FS
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("Failed to open config file for writing");
    }

    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

  Serial.println("local ip");
  Serial.println(WiFi.localIP());
  
  Blynk.config(blynk_token);
  Blynk.connect();

}

  void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer  
}

Não sei se vai ajudar, e este é meu código sem o wifiManager que está funcionando perfeitamente.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>




// You should get  Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";


SimpleTimer timer;
void checkPhysicalButton1();
void checkPhysicalButton2();
void checkPhysicalButton3();


int estadorele1 = LOW;
int estadorele2 = LOW;
int estadorele3 = LOW;
int estadobotao1 = HIGH;
int estadobotao2 = HIGH;
int estadobotao3 = HIGH;
BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0);
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
 }

BLYNK_WRITE(V0)
{
  estadorele1 = param.asInt();
  digitalWrite(5, estadorele1); 
}

void checkPhysicalButton1()
{
  if (digitalRead(13) == LOW)
  {
    if(estadobotao1 != LOW)
    {
      estadorele1 = !estadorele1;
      digitalWrite(5,estadorele1);
      Blynk.virtualWrite(V0, estadorele1);
    }
    estadobotao1 = LOW;
  }
  else
  {
    estadobotao1 = HIGH;
  }
}

BLYNK_WRITE(V1)
{
  estadorele2 = param.asInt();
  digitalWrite(4, estadorele2); 
}

void checkPhysicalButton2()
{
  if (digitalRead(14) == LOW)
  {
    if(estadobotao2 != LOW)
    {
      estadorele2 = !estadorele2;
      digitalWrite(4,estadorele2);
      Blynk.virtualWrite(V1, estadorele2);
    }
    estadobotao2 = LOW;
  }
  else
  {
    estadobotao2 = HIGH;
  }
}

BLYNK_WRITE(V2)
{
  estadorele3 = param.asInt();
  digitalWrite(2, estadorele3); 
}

void checkPhysicalButton3()
{
  if (digitalRead(12) == LOW)
  {
    if(estadobotao3 != LOW)
    {
      estadorele3 = !estadorele3;
      digitalWrite(2,estadorele3);
      Blynk.virtualWrite(V2, estadorele3);
    }
    estadobotao3 = LOW;
  }
  else
  {
    estadobotao3 = HIGH;
  }
}

void setup()
{
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(100L, checkPhysicalButton1);
  timer.setInterval(100L, checkPhysicalButton2);
  timer.setInterval(100L, checkPhysicalButton3);
}

void loop()
{
  Blynk.run();
  timer.run();
} 

this is the problem, you must delete void tick(), else the int are not declared :wink:

void tick()
{
  //toggle state
int estadorele1 = LOW;
int estadorele2 = LOW;
int estadorele3 = LOW;
int estadobotao1 = HIGH;
int estadobotao2 = HIGH;
int estadobotao3 = HIGH;
//int state = digitalRead(BUILTIN_LED);  // get the current state of GPIO1 pin
 // digitalWrite(BUILTIN_LED, !state);     // set pin to the opposite state
}

replace by :

int estadorele1 = LOW;
int estadorele2 = LOW;
int estadorele3 = LOW;
int estadobotao1 = HIGH;
int estadobotao2 = HIGH;
int estadobotao3 = HIGH;

Alexis, tudo bem!
Desculpa demorar responder, estava no trabalho aquela hora, testei aqui o código e compilou.
O problema agora e que não esta me dando a opção da configuração da rede wifi e do token.

Também tentei acessar pelo endereço IP que aparece na porta serial e não abriu nenhuma página para configuração da rede wifi, o código ficou assim agora.

#include <FS.h>                   //this needs to be first, or it all crashes and burns...
//#define BLYNK_DEBUG           // Comment this out to disable debug and save space
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager

//for LED status
#include <Ticker.h>
Ticker ticker;

#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson

char blynk_token[34] = "BLYNK_TOKEN";

bool shouldSaveConfig = false; //flag for saving data

#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;
void checkPhysicalButton1();
void checkPhysicalButton2();
void checkPhysicalButton3();

  //toggle state
int estadorele1 = LOW;
int estadorele2 = LOW;
int estadorele3 = LOW;
int estadobotao1 = HIGH;
int estadobotao2 = HIGH;
int estadobotao3 = HIGH;
//int state = digitalRead(BUILTIN_LED);  // get the current state of GPIO1 pin
 // digitalWrite(BUILTIN_LED, !state);     // set pin to the opposite state

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
 }

BLYNK_WRITE(V1)
{
  estadorele1 = param.asInt();
  digitalWrite(5, estadorele1); 

}
void checkPhysicalButton1()
{
  if (digitalRead(12) == LOW)
  {
    if(estadobotao1 != LOW)
    {
      estadorele1 = !estadorele1;
      digitalWrite(5,estadorele1);
      Blynk.virtualWrite(V1, estadorele1);
    }
    estadobotao1 = LOW;
  }
  else
  {
    estadobotao1 = HIGH;
  }
}


BLYNK_WRITE(V2)
{
  estadorele2 = param.asInt();
  digitalWrite(4, estadorele2); 
}

void checkPhysicalButton2()
{
  if (digitalRead(14) == LOW)
  {
    if(estadobotao2 != LOW)
    {
      estadorele2 = !estadorele2;
      digitalWrite(4,estadorele2);
      Blynk.virtualWrite(V2, estadorele2);
    }
    estadobotao2 = LOW;
  }
  else
  {
    estadobotao2 = HIGH;
  }
}

BLYNK_WRITE(V3)
{
  estadorele3 = param.asInt();
  digitalWrite(2, estadorele3); 
}

void checkPhysicalButton3()
{
  if (digitalRead(16) == LOW)
  {
    if(estadobotao3 != LOW)
    {
      estadorele3 = !estadorele3;
      digitalWrite(2,estadorele3);
      Blynk.virtualWrite(V3, estadorele3);
    }
    estadobotao3 = LOW;
  }
  else
  {
    estadobotao3 = HIGH;
  }
}


void saveConfigCallback ()   //callback notifying us of the need to save config
{
  Serial.println("Should save config");
  shouldSaveConfig = true;
//  ticker.attach(0.2, tick);  // led toggle faster
}

void setup()
{

  Serial.begin(115200);
  Serial.println();

  //set led pin as output
  //pinMode(BUILTIN_LED, OUTPUT);
  pinMode(12, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(115200);
  timer.setInterval(100L, checkPhysicalButton1);
  timer.setInterval(100L, checkPhysicalButton2);
  timer.setInterval(100L, checkPhysicalButton3);
  
  // start ticker with 0.5 because we start in AP mode and try to connect
  //ticker.attach(0.6, tick);

  //SPIFFS.format();    //clean FS, for testing
  Serial.println("Mounting FS...");    //read configuration from FS json

  if (SPIFFS.begin()) {
    Serial.println("Mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("Reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("Opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          strcpy(blynk_token, json["blynk_token"]);

        } else {
          Serial.println("Failed to load json config");
        }
      }
    }
  } else {
    Serial.println("Failed to mount FS");
  }
  //end read

  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);   // was 32 length
  
  Serial.println(blynk_token);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  wifiManager.setSaveConfigCallback(saveConfigCallback);   //set config save notify callback

  //set static ip
  // this is for connecting to Office router not GargoyleTest but it can be changed in AP mode at 192.168.4.1
  //wifiManager.setSTAStaticIPConfig(IPAddress(192,168,10,111), IPAddress(192,168,10,90), IPAddress(255,255,255,0));
  
  wifiManager.addParameter(&custom_blynk_token);   //add all your parameters here

  //wifiManager.resetSettings();  //reset settings - for testing

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  
  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep, in seconds
  wifiManager.setTimeout(600);   // 10 minutes to enter data and then Wemos resets to try again.

  //fetches ssid and pass and tries to connect, if it does not connect it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("CentralHeatingAP", "MY123PWD")) {
    Serial.println("Failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }
  Serial.println("Connected Central Heating System :)");   //if you get here you have connected to the WiFi
  //ticker.detach();
  //turn LED off
  //digitalWrite(BUILTIN_LED, HIGH);

  strcpy(blynk_token, custom_blynk_token.getValue());    //read updated parameters

  if (shouldSaveConfig) {      //save the custom parameters to FS
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("Failed to open config file for writing");
    }

    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

  Serial.println("local ip");
  Serial.println(WiFi.localIP());
  
  Blynk.config(blynk_token);
  Blynk.connect();

}

  void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer  
}

the problem has nothing to do with variable declarations,
you probably have a problem with using wifimanager.
but I’m not familiar with wifimanager,
Since I have only one wifi SSID, I prefer to use the blynk library to check connection.
I assume that you have more than one wifi SSID.
However, I’ll try your code.

@luciano0609

I looked closely at your code, and I have several questions to ask.

why do you use :
FS.h and Blynk.syncVirtual, it’s not the same result?

Ticker.h, just to check LED status ? (blynk can do that without ticker)

SimpleTimer.h, blynk as a powerful timer already include

and the last
timer.setInterval(100L, checkPhysicalButton1);
timer.setInterval(100L, checkPhysicalButton2);
timer.setInterval(100L, checkPhysicalButton3);

you will flood blynk …
why don’t use interrupts ?

could you explain what do you want to do with your blynk code?
I just see 3 physical buttons.

have a nice day

Bom dia, Alexis!
Te Mandei também o código que hoje uso sem o wifimanager, com ele controlo 03 botões fisicamente e 03 botões virtuais pelo blynk, funciona perfeitamente, só que eu tenho que incluir dentro d código o token do blynk, ssid e senha da minha rede para que ele funcione, o problema é que quando troco minha rede wifi tenho que ficar reconfigurando meu código pela porta serial do arduino, por isso estou tentando incluir o wifimanager.
Tem um exemplo na IDE do Arduino que faz isto, más é muito complexo para mim porque sou novo na programação com arduino e este código controla um led rgb e um sensor de temperatura, não sei como alterar para funcionar com meu código.
Resumindo, preciso controlar 03 ibotões que vão acionar 03 saídas relés pelo blynk e que eu tenha a opção de trocar o ssid, pass e o token do blynk pela minha rede wifi.

O caminho na IDE do arduino para o código exemplo que te comentei acima.
Exemplos, Blynk, Export_Demo e Templat_8266.

It shouldn’t be this difficult. If you start with the example that @ldb provided a link to, comment out the stuff that doesn’t apply (mqqt port, mqqt server), and add in your code to the appropriate places it will work.

While cut and paste programming is one of the easier ways to generate code, you still need a basic understanding of coding in order to be sure you are doing it correctly. Just blindly copying and pasting will get you nothing but errors. I suggest you watch some YouTube videos, and read some stuff on Google so that you have the basic concepts of programming down.

Since this topic seems to be going in circles, here is your code. If it doesn’t work report back the error, and I’ll see what I can do to fix it(provided I am not busy).

Since I am not sure if you understand where this information is in the code; the name of the wifi network it will generate is Wifi_Manager, and the password is password.

#include <FS.h>                   //this needs to be first, or it all crashes and burns...

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <SimpleTimer.h>
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson


#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#define BLYNK_DEBUG

BlynkTimer timer;

//define your default values here, if there are different values in config.json, they are overwritten.
//char mqtt_server[40];
//char mqtt_port[6] = "8080";
char blynk_token[34] = "YOUR_BLYNK_TOKEN";

//flag for saving data
bool shouldSaveConfig = false;

int estadorele1 = LOW;
int estadorele2 = LOW;
int estadorele3 = LOW;
int estadobotao1 = HIGH;
int estadobotao2 = HIGH;
int estadobotao3 = HIGH;

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
 }

BLYNK_WRITE(V1)
{
  estadorele1 = param.asInt();
  digitalWrite(4, estadorele1); 

}
void checkPhysicalButton1()
{
  if (digitalRead(12) == LOW)
  {
    if(estadobotao1 != LOW)
    {
      estadorele1 = !estadorele1;
      digitalWrite(4, estadorele1);
      Blynk.virtualWrite(V1, estadorele1);
    }
    estadobotao1 = LOW;
  }
  else
  {
    estadobotao1 = HIGH;
  }
}


BLYNK_WRITE(V2)
{
  estadorele2 = param.asInt();
  digitalWrite(5, estadorele2); 
}

void checkPhysicalButton2()
{
  if (digitalRead(13) == LOW)
  {
    if(estadobotao2 != LOW)
    {
      estadorele2 = !estadorele2;
      digitalWrite(5, estadorele2);
      Blynk.virtualWrite(V2, estadorele2);
    }
    estadobotao2 = LOW;
  }
  else
  {
    estadobotao2 = HIGH;
  }
}

BLYNK_WRITE(V3)
{
  estadorele3 = param.asInt();
  digitalWrite(16, estadorele3); 
}

void checkPhysicalButton3()
{
  if (digitalRead(14) == LOW)
  {
    if(estadobotao3 != LOW)
    {
      estadorele3 = !estadorele3;
      digitalWrite(16, estadorele3);
      Blynk.virtualWrite(V3, estadorele3);
    }
    estadobotao3 = LOW;
  }
  else
  {
    estadobotao3 = HIGH;
  }
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();

   pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(16, OUTPUT);

  //clean FS, for testing
  //SPIFFS.format();

  //read configuration from FS json
  Serial.println("mounting FS...");

  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          //strcpy(mqtt_server, json["mqtt_server"]);
          //strcpy(mqtt_port, json["mqtt_port"]);
          strcpy(blynk_token, json["blynk_token"]);

        } else {
          Serial.println("failed to load json config");
        }
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  //end read



  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  //WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
  //WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //set static ip
  //wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  
  //add all your parameters here
  //wifiManager.addParameter(&custom_mqtt_server);
  //wifiManager.addParameter(&custom_mqtt_port);
  wifiManager.addParameter(&custom_blynk_token);

  //reset settings - for testing
  //wifiManager.resetSettings();

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  
  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  //wifiManager.setTimeout(120);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("Wifi_Manager", "password")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  //read updated parameters
  //strcpy(mqtt_server, custom_mqtt_server.getValue());
  //strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(blynk_token, custom_blynk_token.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    //json["mqtt_server"] = mqtt_server;
    //json["mqtt_port"] = mqtt_port;
    json["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

  //Serial.println("local ip");
  //Serial.println(WiFi.localIP());

  Blynk.config(blynk_token);
  bool result = Blynk.connect();

if (result != true)
{
  Serial.println("BLYNK Connection Fail");
  Serial.println(blynk_token);
  wifiManager.resetSettings();
  ESP.reset();
  delay (5000);
}
else
{
  Serial.println("BLYNK Connected");
}
  timer.setInterval(100L, checkPhysicalButton1);
  timer.setInterval(113L, checkPhysicalButton2);
  timer.setInterval(122L, checkPhysicalButton3);
}

void loop() {
 
Blynk.run();
timer.run();
}

Additionally, un-comment out this section of code for testing. It will erase your stored wifi, password and BLYNK token so you can confirm it works correctly. Once you are satisfied with its function, re-comment them out so that you don’t have to reload the credentials until you need to connect to a different wifi network, or different BLYNK token.

 //clean FS, for testing
  //SPIFFS.format();

EDIT - As of writing, use ArduinoJson Version 5.13.2

1 Like

Also on the ESP, pin 2 is kind of a “special” pin, you may want to reconsider using it.

And Pin 16 does not have a PULL_UP resistor built in.

https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html

1 Like

Olá, tudo bem toro!
Cheguei agora do trabalho e vi aqui seu comentário, vou testar aqui e te falo se funcionou, por enquanto muito obrigado.
Há só uma observação, eu estou usando o Modulo genérico ESP 8266-12.