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

ESP8266 to ESP8266 Communication with Blynk Bridge

esp8266
#1

I am trying to use 2 esp8266 in bridge mode the first code is in esp8266 which requests the data of the other the second code is in the other esp8266 where it has the relay and the dht22 sensor

the relay part is working perfectly, however I can not read the dht22

Can someone help me?

see what is wrong in my code 1 and 2


#include <Arduino.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>

// Você deve obter o Auth Token no Blynk App.
// Vá para as configurações do projeto (ícone da engrenagem).
char auth[] = "xx";

// Suas credenciais de WiFi.
// Definir senha para "" para redes abertas.
char ssid[] = "Leo";
char pass[] = "12345678";

const int relePin = 13; //PINO EM QUE O RELÉ ESTÁ CONECTADO (D7)
const int pulsadorPin = 12; //PINO EM QUE O PULSADOR ESTÁ CONECTADO (D6)

WidgetBridge bridge1(V1);

#define DHTPIN 2 // Qual pino digital estamos conectados

// Descomente qualquer tipo que você esteja usando
//define DHTTYPE DHT11     // DHT 11
#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);

BlynkTimer timer; //OBJETO DO TIPO BlynkTimer

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // ou dht.readTemperature (true) para Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Falha ao ler o sensor DHT!");
    return;
  }
  // Você pode enviar qualquer valor a qualquer momento.
  // Por favor não envie mais que 10 valores por segundo.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  bridge1.virtualWrite(V6, t);
  bridge1.virtualWrite(V5, h);
  
}

void checkPhysicalButton(); //FUNÇÃO checkPhysicalButton

int releState = LOW; //ESTADO INICIAL DO RELÉ (13)
int pulsadorState = LOW; //ESTADO INICIAL DO PULSADOR (12)

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // Você também pode especificar o servidor:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  dht.begin();

  pinMode(relePin, OUTPUT); //DECLARA O PINO COMO SAÍDA (13)
  pinMode(pulsadorPin, INPUT_PULLUP); //DECLARA O PINO COMO SAÍDA (12)
  bridge1.digitalWrite(relePin, releState); //RELÉ RECEBE (13) O ESTADO INICIAL

  // Chame blynk checkPhysicalButton a cada segundo
  timer.setInterval(100L, checkPhysicalButton);
  timer.setInterval(2000L, sendSensor); //DEFINE O INTERVALO DE 2000 MILISSEGUNDOS(2000L = 2000 MILISSEGUNDOS) PARA EXECUÇÃO DA FUNÇÃO DHT dht
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("xx"); // SE CONECTA A OUTROS DISPOSITIVO POR MQTT
  Blynk.syncVirtual(V1); //REQUISITA O ÚLTIMO ESTADO DO PINO VIRTUAL 1
}
BLYNK_WRITE(V1) { //FUNÇÃO QUE MUDA O ESTADO DO RELÉ QUANDO O BOTÃO NO APP É PRESISONADO
  releState = param.asInt(); //VARIÁVEL RESPONSÁVEL POR RECEBER E ARMAZENAR O DADO VINDO DO APP
  bridge1.digitalWrite(relePin, releState); //ALTERNA O ESTADO ATUAL DO RELÉ
}

void checkPhysicalButton() { //FUNÇÃO QUE VERIFICA O PRESSIONAMENTO DO PULSADOR

  if (digitalRead(pulsadorPin) == LOW) { //SE LEITURA DO PULSADOR FOR IGUAL A LOW, FAZ
    if (pulsadorState != LOW) { //SE O ESTADO DO PULSADOR FOR DIFERENTE DE LOW (OU SEJA, HIGH), FAZ
      releState = !releState; //ESTADO DO RELÉ, RECEBE O ESTADO ATUAL INVERTIDO
      bridge1.digitalWrite(relePin, releState); //ALTERNA O ESTADO ATUAL DO RELÉ
      Blynk.virtualWrite(V1, releState); //ATUALIZA NO WIDGET O ESTADO ATUAL (INDEPENDENTE SE FOI ACIONADO VIA APP OU PULSADOR)
    }
    pulsadorState = LOW; //ESTADO DO PULSADOR RECEBE LOW
  } else { //SENÃO, FAZ
    pulsadorState = HIGH; //ESTADO DO PULSADOR RECEBE HIGH
  }

}// fim if relé1 (13)

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




*************



#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

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

// This code will update the virtual port 1
BLYNK_WRITE(V1) {
  int pinData = param.asInt();
}

void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);

}

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

thank you

0 Likes

#2

You have no receiving functions in your code 2 to match these.

http://docs.blynk.cc/#widgets-other-bridge

image

0 Likes

#3

Please correct the code where the error is, please.


////////////////////  code 1 (esp8266 + dht22) ////////////////////////////////q

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “4971a1340d634b4a8740048f95805626”;
//char ssid[] = “Leo”;
//char pass[] = “12345678”;

char ssid[] = “BLACKOPS 2.4 Ghz”;
char pass[] = “wellcome”;

// This code will update the virtual port
BLYNK_WRITE(V10) {
float h = param.asInt();
}

BLYNK_WRITE(V11) {
float t = param.asInt();
}

void setup(){
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}

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

//////////////////////////code 2 (esp8266 which receives data from code 1)/////////////////////

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>
#include <DHT.h>

char auth[] = “5d1bc82a6998488bbb1dec5b3bf704b2”;
//char ssid[] = “Leo”;
//char pass[] = “12345678”;

char ssid[] = “BLACKOPS 2.4 Ghz”;
char pass[] = “wellcome”;

// Bridge widget on virtual pin 1
WidgetBridge bridge1(V1);

#define DHTPIN 2

// Uncomment whatever type you’re using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}

Blynk.virtualWrite(V10, h);
Blynk.virtualWrite(V11, t);
bridge1.virtualWrite(V10, h);
bridge1.virtualWrite(V11, t);
}

BLYNK_CONNECTED() {
bridge1.setAuthToken(“4971a1340d634b4a8740048f95805626”); // Place the AuthToken of the second hardware here
}

void setup()
{
// Debug console
Serial.begin(115200);

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, “blynk-cloud.com”, 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();
timer.setInterval(1000L, sendSensor);
}

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


I can not receive sensor data, neither humidity nor temperature.

0 Likes

#4

Please properly format all posted code…

We are not code monkeys fixing code on demand, at least I am not :stuck_out_tongue_winking_eye: I have my own projects to slave over and inspect for bugs :face_with_monocle:

Just add in the needed BLYNK_WRITE() functions in your receiving code.

I have an example of code that works as both sending and receiving… so you can hopefully get an understanding of Bridge operation from it…

0 Likes

#5

dear, I’m using 2 tokens of the same account.:sonolento:

0 Likes

#6

So? I don’t understand the question.

0 Likes

#7

sorry, but it does not work for me.

0 Likes

#8

What does not work for you?

0 Likes

#9

bridge mode ESP 2266 + DHT22 I can not recover the data.

maybe I have not understood the bridge logic, a doubt I have is:

the esp8266 + dht22 is receiving the following code:


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

char ssid[] = "BLACKOPS 2.4 Ghz";
char pass[] = "wellcome";

BLYNK_WRITE(V1) {
  int pinData = param.asInt();
}

void setup(){
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

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

Is it alright?

0 Likes

#10

Your posted code is meaningless to me unless I know exactly what you are trying to do, have tried, are trying, etc… which I don’t.

If that code above is the RECEIVING code, then where are your BLYNK_WRITE() functions that need to receive and/or display the data in the App?

Basically you set up a Bridge on the SENDING device, that can point to any other device code in your account, based on the RECEIVING devices AUTH.

And, when using virtual pins, as long as there is a BLYNK_WRITE() function in the RECEIVING code. Then using your <bridgename>.virtualWrite(vPin, <data>) commands from the SENDING device will activate/call the matching Blynk Function (in the RECEIVING code) using whatever param. data you send via the bridge.

Please study the posts, links and examples I have already given… Also search for keywords like Bridge in posts with my user name for all the other posts I have written about this. Yes, it is a common word, so you will have to do some digging for the correct context :stuck_out_tongue:

https://community.blynk.cc/search?q=Bridge%20%40Gunner%20order%3Alatest

0 Likes

#11

I have 2 plates esp8266 one of these cards will stay in my living room (will receive the parameters) the other plate together with the dht22 sensor will be in another place (wanna send the data to the first plate in the living room) get a little messed up now .

would you have an example of the codes that I should add on each board?

example: living room
example: other place

please

0 Likes

#12

I cannot write new code for this particular example… but I already posted a link to an example above that contains everything to understand how the bridge works for both sending and receiving devices

Actually the simple single code I used contains BOTH sending and RECEIVING aspects and thus when installed on both devices, and you adjust the commented lines for each one to point to the others AUTH, then you will have two devices that can control and display on each other (two-way Bridge link)

From there you can see how it is done for your one-way Bridge link.

0 Likes

#13

By the way, creating a 2nd account and posting your same question is NOT the way to resolve your issue… I have removed that duplicate user account and topic.

All the information you need has been repeatedly supplied and no one is going to do all your coding for you.

0 Likes

#14

Good evening, please see the code below and tell me why I can not use the second bridge that is commented on.

both work perfectly on their own, but when I enable them, I have no response and disconnection all the time.


#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

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

//const int relePin = 14; //PINO EM QUE O RELÉ ESTÁ CONECTADO (D5)
//const int pulsadorPin = 12; //PINO EM QUE O PULSADOR ESTÁ CONECTADO (D6)

const int relePin2 = 14; //PINO EM QUE O RELÉ ESTÁ CONECTADO (D5)
const int pulsadorPin2 = 13; //PINO EM QUE O PULSADOR ESTÁ CONECTADO (D6)



//int releState, pulsadorState = LOW;
int releState2, pulsadorState2 = LOW;



// Bridge widget on virtual pin 1
//WidgetBridge bridge1(V1);
WidgetBridge bridge2(V10);


// Timer for blynking
BlynkTimer timer;




BLYNK_CONNECTED() {
  //bridge1.setAuthToken("1493c"); // Place the AuthToken of the second hardware here
  bridge2.setAuthToken("91c1b2");
  Blynk.syncVirtual(V7);
}

BLYNK_WRITE(V7) { //FUNÇÃO QUE MUDA O ESTADO DO RELÉ QUANDO O BOTÃO NO APP É PRESISONADO
  releState2 = param.asInt(); //VARIÁVEL RESPONSÁVEL POR RECEBER E ARMAZENAR O DADO VINDO DO APP
  bridge2.digitalWrite(relePin2, releState2); //ALTERNA O ESTADO ATUAL DO RELÉ
}

//BLYNK_WRITE(V8) { //FUNÇÃO QUE MUDA O ESTADO DO RELÉ QUANDO O BOTÃO NO APP É PRESISONADO
//  releState = param.asInt(); //VARIÁVEL RESPONSÁVEL POR RECEBER E ARMAZENAR O DADO VINDO DO APP
//  bridge1.digitalWrite(relePin, releState); //ALTERNA O ESTADO ATUAL DO RELÉ
//}

void checkPhysicalButton() { //FUNÇÃO QUE VERIFICA O PRESSIONAMENTO DO PULSADOR
  // if (digitalRead(pulsadorPin) == LOW) { //SE LEITURA DO PULSADOR FOR IGUAL A LOW, FAZ
  //   if (pulsadorState != LOW) { //SE O ESTADO DO PULSADOR FOR DIFERENTE DE LOW (OU SEJA, HIGH), FAZ
  //     releState = !releState; //ESTADO DO RELÉ, RECEBE O ESTADO ATUAL INVERTIDO
  //     bridge1.digitalWrite(relePin, releState); //ALTERNA O ESTADO ATUAL DO RELÉ
  //     //bridge1.virtualWrite(V8, releState); //ATUALIZA NO WIDGET O ESTADO ATUAL (INDEPENDENTE SE FOI ACIONADO VIA APP OU PULSADOR)
  //     Blynk.virtualWrite(V8, releState);
  //   }
  //   pulsadorState = LOW; //ESTADO DO PULSADOR RECEBE LOW
  // } else { //SENÃO, FAZ
  //   pulsadorState = HIGH; //ESTADO DO PULSADOR RECEBE HIGH
  // }

  if (digitalRead(pulsadorPin2) == LOW) { //SE LEITURA DO PULSADOR FOR IGUAL A LOW, FAZ
    if (pulsadorState2 != LOW) { //SE O ESTADO DO PULSADOR FOR DIFERENTE DE LOW (OU SEJA, HIGH), FAZ
      releState2 = !releState2; //ESTADO DO RELÉ, RECEBE O ESTADO ATUAL INVERTIDO
      bridge2.digitalWrite(relePin2, releState2); //ALTERNA O ESTADO ATUAL DO RELÉ
      //bridge1.virtualWrite(V8, releState); //ATUALIZA NO WIDGET O ESTADO ATUAL (INDEPENDENTE SE FOI ACIONADO VIA APP OU PULSADOR)
      Blynk.virtualWrite(V7, releState2);
    }
    pulsadorState2 = LOW; //ESTADO DO PULSADOR RECEBE LOW
  } else { //SENÃO, FAZ
    pulsadorState2 = HIGH; //ESTADO DO PULSADOR RECEBE HIGH
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // pinMode(relePin, OUTPUT); //DECLARA O PINO COMO SAÍDA (13)
  // pinMode(pulsadorPin, INPUT_PULLUP); //DECLARA O PINO COMO SAÍDA (12)

  pinMode(relePin2, OUTPUT); //DECLARA O PINO COMO SAÍDA (13)
  pinMode(pulsadorPin2, INPUT_PULLUP); //DECLARA O PINO COMO SAÍDA (12)
  timer.setInterval(100L, checkPhysicalButton);
}

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

#15

Sounds like whatever you are doing is too much too fast… thus causing the server flood/disconnect.

You don’t want to call a bridge command too frequently as it is pretty much twice the processing as a standard Blynk command (from sender to server from server to receiver).

PS, just like creating a 2nd account… please don’t create a 2nd topic for same issue :wink: I merged your question back here.

0 Likes

#16

sorry for the inconvenience caused !!!
Could you please give me a hint how to solve this situation?

0 Likes

#17

Except for what I have already extensively supplied, you just need to re-start with a smaller test script and figure out how it works before adding on more and more.

0 Likes

#18

sorry friend…

I did not see your information below with this link.:sweat_smile:

http://docs.blynk.cc/#widgets-other-bridge

0 Likes

#19

Not just that link… all the others as well as an example I had written.

0 Likes