Blynk Bridge not working (across seperate accounts)

Hello,

I am trying to have a bridge between two different devices but the bridge does not seem to be working for some reason. Below is my code, any help would be appreciated, thanks.

Code on the main board, this board has the blynk bridge

/*************************************************************
  This program uses a ds18b20 sensor to detect temperature and send a notification if the temperature is below a certian value
 *************************************************************/

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

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <OneWire.h>
#include <DallasTemperature.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[] = "wifi";
char pass[] = "password";

float temp;


#define ONE_WIRE_BUS D2          // What digital pin we're connected to
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

BlynkTimer timer;

//Bridge definement
WidgetBridge bridge1(V0);

//bridge token

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


void sendSensor() {
  sensors.requestTemperatures();
  temp = sensors.getTempFByIndex(0)+multi;
  
  //Serial.println(temp);

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, temp);
  bridge1.virtualWrite(V3, 150);
}


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

  //Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  Blynk.begin(auth, ssid, pass, IPAddress(local server ip), 8442);


  // Setup a function to be called every second
  timer.setInterval(5000L, sendSensor);
}


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

And here is the code for my second nodemcu board that is supposed to receive the data sent from the first


/*************************************************************

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


  WARNING :
  For this example you'll need Adafruit DHT sensor libraries:
    https://github.com/adafruit/Adafruit_Sensor
    https://github.com/adafruit/DHT-sensor-library

  App project setup:
    Value Display widget attached to V5
    Value Display widget attached to V6
 *************************************************************/

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

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

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

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

float t;
float h;

//int pinData;

#define DHTPIN D2          // What digital pin we're connected to

// 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;

float pinData;
//bridge communication

BLYNK_WRITE(V3){
    pinData = param.asFloat(); //pinData variable will store value that came via Bridge
    Blynk.virtualWrite(V3, pinData);
    Serial.println(pinData);
}



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

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

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V11, t);
  Blynk.virtualWrite(V12, h);
  //Blynk.virtualWrite(V3, pinData);
}



void setup()
{
  // Debug console
  Serial.begin(9600);
  //Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  Blynk.begin(auth, ssid, pass, IPAddress(local server ip), 8442);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(5000L, sendSensor);
}

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


So basically this project is doing 2 things. the first set of code is on a nodemcu board that measures water temperature from a water boiler, this board is using an auth token under user1, on the user1 app the data is being sent fine and i can can see the temp from this board.This board is meant for my family and anyone who wants the temp for the boiler.
On the second board from the second set of code it is also a second nodemcu it has a dht11 sensor that is in my room, this is my board under user2, i would like the first board to also send its data to the second board so my user account can also see the temp of the boiler. The only problem is that anything i try to get the bridge to sent the water temp has failed, it seems as though the bridge is not working, any help would be greatly appreciated and if anyone needs further clarification i will be happy to do that.

Thanks guys,

I can see nothing wrong with it to be honest. Looks like a text book example.

For now I would strip all the DHT stuff and try to do a basic sending of a reading of analog port 0 or something, just to generate some data and to exclude something in the DHT part.

Yea, i even tried to have it turn on the onboard led to see if the bridge was working and i could not even get that to work, i will try latter to strip all code down and just do a basic bridge, or even copy and paste the example code to see if that works.

That would be a good start.

The second option would be integrating all the devices into 1 dashboard. That is a very nice feature which will probably eliminate the use of the Bridge in most cases. Anything you want to do than can be handled from the App side using the Eventor widget (sort of an IFTTT thingie).

Alright, so ive spent the past few hours reading the documentation and looking at other peoples posts and i cannot figure out whats going wrong. I have gone to the most basic sketch i could, right from the bridge example and nothing seems to be working. I even tried swapping one of my nodeMCU out for a wemosD1 mini, still nothing. Here is my code if anyone can please tell me what im doing wrong, OR if someone can write some code for testing bridge that i can copy and see if I can get that to work.

On one NodeMCU i have the code:

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest
  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.
    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app
  Blynk library is licensed under MIT license
  This example code is in public domain.
 *************************************************************
  Control another device using Bridge widget!
  Bridge is initialized with the token of any (Blynk-enabled) device.
  After that, use the familiar functions to control it:
    bridge.digitalWrite(8, HIGH)
    bridge.digitalWrite("A0", LOW) // <- target needs to support "Named pins"
    bridge.analogWrite(3, 123)
    bridge.virtualWrite(V1, "hello")
 *************************************************************/

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


#include <SPI.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[] = "DEVICE ONE AUTH TOKEN";

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

// 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(D6, HIGH);  // Digital Pin 9 on the second board will be set HIGH
    bridge1.virtualWrite(V5, 1); // Sends 1 value to BLYNK_WRITE(V5) 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(D6, LOW); // Digital Pin 9 on the second board will be set LOW
    bridge1.virtualWrite(V5, 0); // Sends 0 value to BLYNK_WRITE(V5) handler on receiving side.
  }
  // Toggle value
  value = !value;
}

/*BLYNK_CONNECTED() {
  bridge1.setAuthToken("DEVICE B AUTH TOKEN"); // Place the AuthToken of the second hardware here
}*/

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

  Blynk.begin(auth, ssid, pass, IPAddress(LOCAL SERVER IP), 8442);

  while (Blynk.connect() == false) {
    // Wait until connected
  }
  bridge1.setAuthToken("DEVICE B AUTH TOKEN"); // I put this here again to test and see fi this was the problem, as i saw someone on the forms say it should work
  // Call blynkAnotherDevice every 2 seconds
  timer.setInterval(2000L, blynkAnotherDevice);
}

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

Thats all the code i have on my first nodemcu. I should also mention that these 2 devices are using separate user accounts and projects and connect to the same local blynk server. Does bridge work with separate users?

Here is the code on my second device:

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

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

  This sketch shows how to read values from Virtual Pins

  App project setup:
    Slider widget (0...100) on Virtual Pin V1
 *************************************************************/

/* Comment this out to disable prints and save space */
#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[] = "SECOND DEVICE AUTH TOKEN";

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

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Blynk.virtualWrite(V6, pinValue);
  Serial.println(pinValue);
  // process received value
  
}

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

  Blynk.begin(auth, ssid, pass, IPAddress(LOCAL SERVER IP), 8442);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}

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

That is all i have on the second device. I have tried using serial and virtualwrite to see if any data is coming through, i even had an led hooked up to pin D6 and tried pulsing that directly from the first device to see if something in the digital pins were broken, but it seems not. I am completely lost here as what to do, as i would like to keep these 2 devices on 2 separate user accounts, one for me and one for my family. Thanks for any help.

That might be your issue? As each Account is a separate entity within the encompassing Server (and each server independently on it’s own), Bridging Across separate projects within the same account, yes, but possibly not across separate accounts.

Thinking about that, it makes sense, as there is no parameter to include account login info for a Bridge… it will only work within it’s own account.

That keeps people, without your login, from using your authcode (say if it is accidently posted in a forum) to control your stuff indirectly and without your control.

Yea that’s what i was thinking, but an auth code is like a unique identifier for each device. I was under the assumption that it would work like that, im gonna have to try it on a different project now instead of 2 accounts. Although I would like this feature to be implemented as it can be very useful for my exact senario. Thanks for the input.

EDIT: So as it turns out it does work with separate projects, so it does not work with separate user accounts. Thanks for the advice. Also if the devs would please somehow make this work from separate user accounts it would really work well for me. Thanks

Take a look at blynks http restful api
It does not seem to require account information, I have not gone through it myself though.

1 Like

I may just have to look into that for future use, Thanks.

This is not supported. Bridge works only within same account.

Do you think there will be a feature in the future in do cross account bridging?

This is actually a security measure. So we have no plans to change that. Maybe some day we will have some special kind of API for that.

Isnt that the same thing as the RESTful API though? Because all you need for that is a token and you can transmit and receive data with it. Or maybe enable this as a feature for local servers and make it only work with accounts on the same local server.