Sending value from one esp8266 to the other trough Blynk, should be easy?

Hi Blynkers :wave:

For my project I want to send value’s between my Esp8266 HUZZAH to my Nodemcu.
I was thinking to do this by sending the value to a Virtual Pin and than reading the one with the other module. Can I do this with bridge?
But is it even possible to share a Virtual pin between two modules?
Am I thinking in the right direction, am I missing something?

Thank you for reading!

Bridge is the way to do it, search the forum for Bridge examples.

Pete.

Thank you very much for your reply!
I am now trying the example to blink an LED over bridge.
There is probably something wrong on the receiving code.

Any clues?

Sending code:


#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
//NODEMCU
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "KbNZdDoRZ2jFcc0Mm2o4GQSRbN_tUYe9";

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

// Timer for blynking
BlynkTimer timer;

static bool value = true;
void blynkAnotherDevice() // Here we will send HIGH or LOW once per second
{
  // Send value to another device
  if (value) {
    bridge1.digitalWrite(12, HIGH);  // Digital Pin 12 on the second board will be set HIGH
    bridge1.virtualWrite(V1, 1); // Sends 1 value to BLYNK_WRITE(V1) handler on receiving side.

    /////////////////////////////////////////////////////////////////////////////////////////
    // Keep in mind that when performing virtualWrite with Bridge,
    // second board will need to process the incoming command.
    // It can be done by using this handler on the second board:
    //
    //    BLYNK_WRITE(V5){
    //    int pinData = param.asInt(); // pinData variable will store value that came via Bridge
    //    }
    //
    /////////////////////////////////////////////////////////////////////////////////////////
  } else {
    bridge1.digitalWrite(12, LOW); // Digital Pin 9 on the second board will be set LOW
    bridge1.virtualWrite(V1, 0); // Sends 0 value to BLYNK_WRITE(V5) handler on receiving side.
  }
  // Toggle value
  value = !value;
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("eB_UgC2p8R3I6NYH3QknkVMwr4Aawty4"); // Place the AuthToken of the second hardware here
}

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

  Blynk.begin(auth);

  // Call blynkAnotherDevice every second
  timer.setInterval(1000L, blynkAnotherDevice);
}

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

Recieving code

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//ESP8266 HUZZAH
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "eB_UgC2p8R3I6NYH3QknkVMwr4Aawty4";


BLYNK_WRITE(V1){
int pinData = param.asInt(); // pinData variable will store value that came via Bridge
}

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

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
 
}

It doesn’t look like you are doing anything with the data in the ‘receiving’ code?

You receive the HIGH or LOW on V1 and D12, But there’s nothing in your code to do anything with this data?

For D12 you will need to define the pin as an output.

For V1 (param.asInt()), what are you proposing to do with that info? You receive it, but then nothing happens.

I’d suggest get your receiving device working as a standalone first, then incorporate control via bridge.

billd

Thank you @Bill_Donnelly!

I wrote this now:
But I’m still not very sure about it. I’m quite new to using bridge.
I wonder if I am placing everything in the right place (Outside of the void loop).
Also is the serial.print part right to read it on my computer?

Thank you for reading!

The new code:
But I still don’t receive anything.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetBridge bridge1(V1);
//ESP8266 HUZZAH
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "**********************************************";

BLYNK_WRITE(V1){
int pinData = param.asInt(); // pinData variable will store value that came via Bridge
Serial.println (param.asInt());
pinMode (12, OUTPUT);

}

void setup()
{
  // Debug console
  Serial.begin(11500);
  pinMode (12, OUTPUT);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}
pinMode (12, OUTPUT);

should only be in your setup()

You also don’t have any of the BLYNK connection commands in your setup(), of the stuff for the wifi credentials. You need to add Blynk.begin(auth); to the second device as well. They both need to be connected to BLYNK in order to talk to each other.

Also, make sure both devices are running, and connected. You can confirm they are connected by checking the device online status.

Additionally, confirm auth token in the bridg1.setAuthToken() is correct.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetBridge bridge1(V1);
//ESP8266 HUZZAH
// 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[] = "YourNetworkName";
char pass[] = "YourPassword";

BLYNK_WRITE(V1){
int pinData = param.asInt(); // pinData variable will store value that came via Bridge
Serial.println (param.asInt());

}

void setup()
{
  // Debug console
  Serial.begin(11500);
  pinMode (12, OUTPUT);
  
   Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

Thank you very much for the reply.

I have removed pinMode (12, OUTPUT);
So now it is only in my setup.

I shall add the Blynk.begin(auth);
I guess this should also be added to my first device?

The set Auth should be correct .

Should I also put the bridge widget in the app?

Both devices need to be connected. It looks like you are using different connection methods for your two boards. Make sure you are using the proper commands for the connection method you are using.

It sounds like you should be using wifi connection for both. Therefore you need to make sure both sketches include the proper commands for a wifi connection.

Thank you so much! That did it :smiley: !

This is the working code for anyone who wants to have a basic code to try out bridge:

Sending code and the second one is the receiving code.


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

//NODEMCU
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

char auth[] = "****";
char ssid[] = "****";
char pass[] = "****";

// Your WiFi credentials.
// Set password to "" for open networks.



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

void setup() {
  Blynk.begin(auth, ssid, pass);
  pinMode (12, OUTPUT);
  while (Blynk.connect() == false) {
    // Wait until Blynk is connected
  }
  digitalWrite (12, HIGH);// write own led high
  bridge1.digitalWrite(12, HIGH); // will trigger D12 HIGH on Device B. No code on Device B required
  bridge1.virtualWrite(V1, "hello"); // you need to write code on Device B in order to receive this value.

}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("****"); // Token of the hardware B
}

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


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetBridge bridge1(V1);
//ESP8266 HUZZAH

// 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[] = "****";

BLYNK_WRITE(V1){
int pinData = param.asInt(); // pinData variable will store value that came via Bridge
Serial.println (param.asInt());

}

void setup()
{
  // Debug console
  Serial.begin(11500);
  pinMode (12, OUTPUT);
  
   Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

I would probably move that code out of the setup(). Otherwise you will have to reset the board for it to run again.

Maybe something like you had originally:

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

//NODEMCU
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

char auth[] = "****";
char ssid[] = "****";
char pass[] = "****";

// Your WiFi credentials.
// Set password to "" for open networks.



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

 bool value = true;

void blynkAnotherDevice() // Here we will send HIGH or LOW once per second
{
  // Send value to another device
  if (value) {
    digitalWrite (12, HIGH); // Digital Pin 12 on the this board will be set HIGH
    bridge1.digitalWrite(12, HIGH);  // Digital Pin 12 on the second board will be set HIGH
    bridge1.virtualWrite(V1, "Hello"); // Sends "Hello" value to BLYNK_WRITE(V1) handler on receiving side.
  } 
else {
    digitalWrite (12, LOW); // Digital Pin 12 on the this board will be set LOW
    bridge1.digitalWrite(12, LOW); // Digital Pin 9 on the second board will be set LOW
    bridge1.virtualWrite(V1, "Hello Again"); // Sends "Hello Again" value to BLYNK_WRITE(V1) handler on receiving side.
  }
  // Toggle value
  value = !value;
}


void setup() {
  Serial.begin(11500);
  pinMode (12, OUTPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, blynkAnotherDevice);
 
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("****"); // Token of the hardware B
}

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

Hey,

Thanks for the reply. At the moment I am a bit further with the code and made some improvements.

My setup is like this now:
Teensy sends a value of 1023 to the HUZZAH over serial.
Then the HUZZAH sends it to the NODEMCU over bridge.

Everything works fine apart from that the value I receive on the NODEMCU and HUZZAH is 225 instead of 1013.
My guess would be that the value is to big for serial write.

My goal is to eventually be able to send ldr sensor information from the Teensy to the NODEMCU. Thats why I chose the value 1023.

Any hints on how to get past that problem?

Teensy code:


void setup() {

    // Setup computer to Arduino serial
    Serial.begin(115200);

    // Setup Arduino to ESP8266 serial
    // Use baud rate 115200 during firmware update
    Serial1.begin(115200);
    pinMode(20, INPUT);//LDR pin

}

void loop() {

 int LDR = analogRead(A6);
 //Serial1.write (LDR);
 Serial1.write (1023);
 //Serial.println (LDR);
 delay (1000);

 Serial1.write (0); // "50\r\n"

 delay (1000);

}

HUZZAH code


//#define uint8 unsigned char 
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//HUZZAH
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

char auth[] = "";
char ssid[] = "";
char pass[] = "";


// Your WiFi credentials.
// Set password to "" for open networks.



// Bridge widget on virtual pin 1 
WidgetBridge bridge1(V1);
BlynkTimer timer;
bool value = true;

void blynkAnotherDevice() // Here we will send HIGH or LOW once per second
{
  int val = 0; //or uint8_t
  // Send value to another device
  if (value) {
    //digitalWrite (12, HIGH); // Digital Pin 12 on the this board will be set HIGH
    val = Serial.read();
    Serial.println(val);
    bridge1.digitalWrite(12, HIGH);  // Digital Pin 12 on the second board will be set HIGH
    bridge1.virtualWrite(V1, val); // Sends recieved sensor value to BLYNK_WRITE(V1) handler on receiving side.
  } 
else {
    //digitalWrite (12, LOW); // Digital Pin 12 on the this board will be set LOW
    bridge1.digitalWrite(12, LOW); // Digital Pin 12 on the second board will be set LOW
    bridge1.virtualWrite(V1, val); // Sends recieved sensor value to BLYNK_WRITE(V1) handler on receiving side.
  }
  // Toggle value
  value = !value;
}


void setup() {
  Serial.begin(115200);
  pinMode (12, OUTPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, blynkAnotherDevice);
 
}
BLYNK_CONNECTED() {
  bridge1.setAuthToken(""); // Token of the hardware B
}

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

NODEMCU CODE


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetBridge bridge1(V1);
//NODEMCU

// 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[] = "";

BLYNK_WRITE(V1){
int pinData = param.asInt(); // pinData variable will store value that came via Bridge
Serial.println (pinData);

}

void setup()
{
  // Debug console
  Serial.begin(115200);
  pinMode (12, OUTPUT);
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

At the receiving side you also need a blynk.virtualwrite at V1 for when V1 receives the data from the master. See blynk bridge example