wifiMananger

Sou leigo em programação, eu copiei o código no arduino e colei na postagem.

Well if you download the wifiManager library in arduino (as shown on the wifiManager GitHub), you can find examples that would be a good starting point.

Sim,já fiz isto, só que la não ensina como incluir meu código.

If clear instructions didn’t teach you how to properly format your posted code… what more can anyone do?

You need to learn enough basic programming to make proper use of examples… due to the variety of devices, they are rarely plug and play

1 Like

a formatação que vocês tanto falam é o tradutor da pagina do blynk que está bugada

How about the motion gif in the welcome topic?

Como já disseram sem formatar o seu código é bem difícil de alguém te ajudar.

Qual erro você recebe quando tenta compilar?

@luciano0609 Close… You where just using wrong key. It is the backtick, not the comma or apostrophe.

Blynk - FTFC

I fixed it for you this time :wink:

@luciano0609 esta faltando UM MONTE de codigo do wifi manager, sugiro voce usar esse exemplo e mesclar seu codigo AutoConnectWithFSParameters


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>  
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char blynk_token[] = "";

// 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.connect()

  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);

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

void checkPhysicalButton1()
{
  if (digitalRead(16) == 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(12) == LOW)
  {
    if(estadobotao3 != LOW)
    {
      estadorele3 = !estadorele3;
      digitalWrite(2,estadorele3);
      Blynk.virtualWrite(V3, estadorele3);
    }
    estadobotao3 = LOW;
  }
  else
  {
    estadobotao3 = HIGH;
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);
// wifi
  WiFiManager wifiManager;
  wifiManager.autoConnect("AutoConnectAP", "ronin");
  Serial.println("baglanti tamam :)");
   WiFiManagerParameter custom_blynk_token("Blynk", "blynk token", blynk_token, 34);
   wifiManager.addParameter(&custom_blynk_token);
   wifiManager.autoConnect("Blynk");
   Blynk.config(custom_blynk_token.getValue());
  pinMode(16, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(115200);
Blynk.config(blynk_token);
bool result = Blynk.connect(180);

if (result != true)
{
  Serial.println("BLYNK Connection Fail");
  wifiManager.resetSettings();
  ESP.reset();
  delay (5000);
}
else
{
  Serial.println("BLYNK Connected");

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

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

Tentei mandar formatado de novo, o exemplo que você me indicou é com MQTT como altero para funcionar com a plataforma do blynk?

Tentei compilar o código que você me indicou e está da este erro

na imagem abaixo.

Aqui funciona normal, veja se você inclui todas as bibliotecas necessárias.

1 Like

porque está dando este erro?

Como eu disse anteriormente, cheque se você adicionou todas as biblioteca requeridas por esse código que esta tentando usar.

Se você procurar aqui vai encontrar vários exemplos de códigos usando o WiFi Manager, porem eh uma funcao mais avancada.

Se voce apenas quer colocar para ajudar na hora de mudar sua senha do Wifi acho que nao vale a pena visto que voce nao muda sua senha tao frequentemente.

1 Like

problem comes from the version of ArduinoJson used. (v6 beta)
you can not use this version with wifimanager
you need to install version 5.13
:wink:

Olá Alexis, tudo bem!
Obrigado esta parte consegui resolver, agora e o meu código que estou tentando incluir neste código, não estou conseguindo.
Poderia me ajudar?

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.