wifiMananger

Tenho este código abaixo para ligar três reles no meu modulo ESP8266 e estou tentando usar o código wi-fi Mananger para conectar meu modulo, assim toda vez que eu trocar o nome da minha rede e senha, não conectar meu ESP8266 pelo cabo serial para trocar internamente no código, só que esta dando erro ao carregar, alguém pode me ajudar.

#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();
} 

you are missing a lot of the wifiManager code and libraries. There are working example on this forum, try searching for them. Also Go to the wifiManager GitHub and make sure you have all of the correct libraries installed.

OH ,and format your code correctly when posting

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?