Multiple Bridge from one token

Before creating the topic
Hardware: 1 NODEMCU & 2 ESP32
Smartphone OS: IOS
Blynk Server

I’m attempting to use the bridge function to to trigger updates on other ESPs simultaneously from the blynk app. I’ve added bridge1.setauthtoken("") and bridge2.setauthoken("") which are two of the tokens that I would like to trigger the updates on. When I attempt to trigger the updates, I notice that only one of the tokens get triggered at a time.
is it possible to bridge to two different tokens from one device? I read the other topics but they seem to be different from what I am trying to do.
this is the code running in the NODEMCU where I trigger the update from

#include <FS.h>
#include <SPI.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiManager.h>
#define BLYNK_PRINT Serial

bool shouldSaveConfig = false;
int Lw_pin = 15;
int LedOk = 12;
int WifiReset_Pin = 13;

BlynkTimer timer;
char FWU_token[34] = "YOUR_TOKEN";
void saveConfigCallback()
{

  shouldSaveConfig = true;
}

WidgetBridge bridge1(V26);
WidgetBridge bridge2(V26);

BLYNK_CONNECTED()
{

  bridge1.setAuthToken("blynktoken");
  bridge2.setAuthToken("blynktoken");
}

BLYNK_WRITE(V26)
{
  int pinValue = param.asInt();

  if (pinValue == 1)
  {
    bridge1.virtualWrite(V26, 1);
    bridge2.virtualWrite(V26, 1);
  }
  else
  {
  }
}

void setup()
{

  WiFiManager wifiManager;
  pinMode(Lw_pin, OUTPUT);
  pinMode(WifiReset_Pin, INPUT_PULLUP);
  pinMode(LedOk, OUTPUT);
  LEDFlash();
  digitalWrite(LedOk, LOW);
  delay(100);
  int clearwifi = digitalRead(WifiReset_Pin);
  delay(100); //debounce input

  if (clearwifi == 0)
  {
    digitalWrite(LedOk, LOW);

    wifiManager.resetSettings();

    if (SPIFFS.begin())
    {

      if (SPIFFS.exists("/config.json"))
      {

        SPIFFS.remove("/config.json");
      }
    }
    else
    {
    }
    ESP.restart();

    digitalWrite(Lw_pin, HIGH);
    delay(5000);
  }

  if (clearwifi == 1)
  {

    if (SPIFFS.begin())
    {

      if (SPIFFS.exists("/config.json"))
      {

        File configFile = SPIFFS.open("/config.json", "r");
        if (configFile)
        {

          size_t size = configFile.size();
          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())
          {

            strcpy(FWU_token, json["FWU_token"]);
          }
          else
          {
          }
        }
      }
    }
    else
    {
    }
    WiFiManagerParameter custom_FWU_token("FWU", "FWU_token", FWU_token, 33);

    wifiManager.setSaveConfigCallback(saveConfigCallback);

    wifiManager.addParameter(&custom_FWU_token);

    wifiManager.setTimeout(360);
    if (!wifiManager.autoConnect("FWU-AP"))
    {
      delay(1000);

      delay(1000);

      ESP.restart();
    }

    strcpy(FWU_token, custom_FWU_token.getValue());

    if (shouldSaveConfig)
    {

      DynamicJsonBuffer jsonBuffer;
      JsonObject &json = jsonBuffer.createObject();

      json["FWU_token"] = FWU_token;

      File configFile = SPIFFS.open("/config.json", "w");
      if (!configFile)
      {
      }

      json.printTo(Serial);
      json.printTo(configFile);
      configFile.close();
    }

    Blynk.config(FWU_token);
    bool result = Blynk.connect();
  }
}

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

I would try using different virtual pins, as you are using the same virtual pin for the app widget and both bridges.

WidgetBridge bridge1(V27);//V26 is being used by a widget, V28 is being used for the second bridge
WidgetBridge bridge2(V28);//V26  is being used by a widget, V27 is being used for the first bridge

the bridge1.virtualWrite(V26, 1); and bridge2.virtualWrite(V26, 1); should be ok as these are manipulating virtual pin 26 on the other devices.

Correct :slight_smile:

@yourideasvi When initiating the bridges to multiple MCUs, you can use any name and available (unused) vPin on the “transmitter” project’s side… but each defined bridge does need a different vPin.

These "holding’ vPins are NOT the same as whatever vPins you are trying to control on the receiving side… so there is NO need to make them the same unless you really like it that way…

For example…

WidgetBridge MyNodeMCU(V125); //  Initiating Bridge Widget on V125 (this is just as holding pin for the bridge, can be any unused vPin and each bridge needs its own)

WidgetBridge MyWemos(V126); //  Initiating Bridge Widget on V126 (this is just as holding pin for the bridge, can be any unused vPin and each bridge needs its own)

WidgetBridge MyUNO(V127); //  Initiating Bridge Widget on V127 (this is just as holding pin for the bridge, can be any unused vPin and each bridge needs its own)
BLYNK_CONNECTED() {
  MyNodeMCU.setAuthToken("AuthToken of NodeMCU"); // Token of the hardware A
  MyWemos.setAuthToken("AuthToken of Wemos"); // Token of the hardware B
  MyUNO.setAuthToken("AuthToken of UNO"); // Token of the hardware C
}
BLYNK_WRITE(V0) {
  MyNodeMCU.virtualWrite(V3, param.asInt()); // take the state of this transmitting MCU's virtual V0 button and send it to the receiving MCU's V3 vPin
}

BLYNK_WRITE(V1) { 
  MyWemos.virtualWrite(V8, param.asInt()); // take the state of this transmitting MCU's virtual button on V1 and send it to the receiving MCU's V8 vPin
}

BLYNK_WRITE(V2) { 
  MyUNO.digitalWrite(13, param.asInt()); // take the state of this transmitting MCU's virtual button on V2 and send it to the receiving MCU's GPIO13
}
1 Like

thanks guys. your suggestions worked.

1 Like