Quick question about Bridge widget

I need more information. Whats your setup in this? What is the master and what the slave, apparently im looking at the code from the ‘master’? Then this:

makes little sense. Reading it it says: when master receives input from slave? app? on V66 then send that value to slave?

and then later one you again send an new value TURN_ON or OFF on the same pin V66, to the same slave depending on some variables.

‘BLYNK_WITE(V66)’ literally means: in the event that this device (where this code is running) receives a value on V66 THEN execute the code in this routine. In this case: pass that value on to the slave. And indeed you cannot ‘hide’ that code inside a class or other routine. It has to be outside any routine.

1 Like

The terms “Master and Slave” for Bridge are a bit of a misnomer… more correctly would be sender and receiver, since either/both/all (not limited to two here) can send or receive to and from any others that you set up.

As I stated before, in its simplest form, Bridge is really just the sender emulating you clicking on a widget that then processes a Blynk function on the receiver side.

Simply do what ever you would normally do on the device with the sensor… read the data and when a trigger point happens, do something…

Blynk.virtualWrite(localPin, "abc");

Only use the bridge to do that something on another device instead.

bridgeName.virtualWrite(remotePin, "abc");

If the remotePin happens to be a virtual pin, then simply have a BLYNK_WRITE() function on that devices sketch to take the value “abc” and do something with it…

1 Like

correct, which is the reason I asked the OP. Its unclear where I’m looking at and what it supposed to do in respect to the other device(s?)

next to that I have a feeling that the OP doesn’t understand the workings of blync_write() and bridge.virtualwrite().

I realize all devices I’m using (ESP8266) can be configured as bi directional, but I figured it would be best for my learning curve to learn a uni-directional configuration first, then expand out once I have that down. I am perplexed though as I successfully managed to pass values from app, to Master to cloud to slave in the ROcheck() function, and those values are floats. Those float values were then received by slave, multiplied against and the desired outcome achieved. Yet when I try to send digital values (0 or 1) via the virtual pins, I wasn’t (always) getting the desired outcome.

All of that said, I must pause this topic for some days/weeks as I also discovered that maybe my ESP8266 isn’t up to the task of driving optocouplers used on the relays module. The ESP pins are rated for 12mA, yet the optos require 15-20mA. With the first module I tried, 3/8 relays triggered and power cycled the connected AC~ device, yet when I tried the 2nd relay module, none of the relays toggled. The onBoard LEDs lit up, but the relays themselves were not rocking. Also, I believe I can find my way back to the syntax that I tried that produced a result that lit up the relay LEDs. Because I need to address my hardware concerns, I want to table this topic for now and revisit it when I have hardware that will jive better.

Master Sketch RO function

uint32_t msPerGallon = 33000; //ms per gallon
uint32_t ROstart = 0;
uint32_t countGallons;
boolean runningRO = false;
int ROpumpOn = 0;     //Blynk Triggered RO Pump button widget
float totalGallons;   //Number of RO Gallons Selected in Step V Widget

BLYNK_WRITE(V32) {    //V33 Reserved to illuminate button
  ROpumpOn = param.asInt();  // button widget that activates the process
}
BLYNK_WRITE(V34) {
  totalGallons = param.asFloat();  // the value that is sent once button is ticked
}

void ROcheck()  //RO Pump = 33 seconds on time per gallon
{
  if (ROpumpOn == 1 && runningRO == false)            // Activates when Blynk button is toggled
  {
    Bridge1.virtualWrite(V64, totalGallons);
    terminal.print("Pumping:");
    terminal.print(totalGallons);
    terminal.println(" Gallons of RO");
    Blynk.virtualWrite(V33, 1);                     // Illuminates Blynk button widget
    runningRO = true;
    ROstart = millis();
    countGallons = msPerGallon * totalGallons;        // Calculates length of runtime for
    Blynk.virtualWrite(V34, 0);
  }
  if (millis() - ROstart > countGallons)              // Determines when runtime ends
  {
    ROpumpOn = 0;
    runningRO = false;
    Blynk.virtualWrite(V32, 0);                 // Turn off lit button widget
    Blynk.virtualWrite(V33, 0);                 // Turn off lit button widget
    Blynk.virtualWrite(V64, totalGallons);
  }
  terminal.flush();
}

Slave Sketch RO function

uint32_t msPerGallon = 33000; //ms per gallon
uint32_t ROstart = 0;
uint32_t countGallons;
boolean runningRO = false;
float totalGallons;   //Number of RO Gallons Selected in Widget

BLYNK_WRITE(V64) {
  totalGallons = param.asFloat();  // value that is received

void ROcheck()  //RO Pump = 33 seconds on time per gallon
{
  if (totalGallons > 0 && runningRO == false)            // Activates when Blynk button is toggled
  {
    Serial.print(totalGallons);
    Serial.println(" - Gallons");
    digitalWrite(ROpump, TURN_ON);
    runningRO = true;
    ROstart = millis();
    countGallons = msPerGallon * totalGallons;        // Calculates length of runtime for pump
  }
  if (millis() - ROstart > countGallons)              // Determines when runtime ends
  {
    Blynk.virtualWrite(V64, 0);
    totalGallons = 0;
    digitalWrite(ROpump, TURN_OFF);
    runningRO = false;
  }
}

The above function accounts for a single relay. The other 7 relays I had set to perform the sensor tests on the master device, and send a 1 to turn on a relay at a desired time, then later send a 0 to turn it off once the desired time has elapsed. My new train of thought is to merely send the sensor value, and have the slave process it accordingly, but I do first need to address my hardware concerns first. Thanks for all the help.

I think you’ll find that the ESP8266 has a maximum Drain current of 20ma per GPIO pin, so you should be fine.
However, if you’re using a single ESP device you’ll struggle to find 8 GPIO pins that are suitable for driving relays. Two ESPs working side by side might be better, or even a couple of Sonoff 4ch devices?

Your problems with getting your current setup to operate your relays may be caused by a number of issues:

  • Faulty relays (the bigger relay boards seem prone to this), but it’s easy enough to check each relay circuit in turn, even without an ESP

  • Insufficient power supply to either the ESP or the relay board, or poor wiring (lack of shared Ground maybe)

  • Poor choice of pins

  • Faulty ESP board

  • Poor coding

Pete.

1 Like

I currently have two of these 8 Channel Modules configured for true opto-isolation in that there are no shared grounds between the MCU and the relays. I pulled the jumper from JD-VCC-VCC and supply 5V4A to the JD-VCC and GND respectively. That takes care of the relay circuit. The control circuit is from the MCU’s power pin, in this case 3V on the ESP, and each of the GPIO connected sinks current supplied by the power pin to complete the logic side of the circuit. Previously, I was using an Ethermega (Arduino Mega/Ethernet combined) and this setup worked flawlessly for more than a year, but the Arduino’s limits in memory and other terms I don’t fully comprehend prevented me from expanding my project much further and I DO intend on doubling it’s size and needs in the future, so a friend talked me into considering splitting my project into several ESPs which I am now doing. It’s pretty tough going from a 5V system to a 3V3 system with only hobbiest level knowledge of circuitry and coding.

I’m glad you stated that I can get upwards of 20mA per pin as that gives me more confidence in buying 4 channel relays. I also have read that some of the pins I’m now using (2-4-5-12-13-14-15-16) may have other functions attached to them at bootup which may work against my overall desires. If my burden is halved, I think I’ll be better off finding 4 completely unused pins than 8. I’ve been wanting to slim down my project’s foot print anyways by designing and 3D printing some custom cases to hold 4 outlets, a 4chan relay and an ESP. I’ve already done this with my dosing pumps and driver circuits and it looks great. Here’s what my current hack looks like for the outlets, not pretty by any standard.

64[quote=“Skybound, post:36, topic:23360”]
I think I’ll be better off finding 4 completely unused pins
[/quote]
You should read this thread:

Having seen your setup I really would suggest that you take a look at the Sonoff 4ch or 4ch Pro devices. They’re probably cheaper than the cost of the components you’re using and are DIN rail mounting, so lend themselves to neat modular installations and kale swapping-out modules very easy. They should be easy to re-programme to work with Blynk.

Pete.

Thanks for the link. Can you also get me a link for the relays you suggested? My search I think is returning incorrect results. Also, when you have a 3D printer, mounting things is no longer a concern at all b/c I can custom design cases, standoffs and print it out in a few hours, so do I need DIN rail mounting? Is DIN rail applications for inside of a mains power panel? My application will be mounted/deployed about 100’ downstream of the mains power panel/sub panel.

This is the Sonoff 4ch Pro:
https://www.itead.cc/sonoff-4ch-pro.html

And here’s what @scargill has to say about them:

DIN rail is the thing that’s used in the back of a main ‘fusebox’ that the circuit breakers clip on to, but you can buy lengths of rail, or an empty ‘fusebox’ to give yourself an easy way of mounting hardware. Quite handy when you want to use the clip-on functionality that makes it easy to swap components out.

Pete.

1 Like

Is that a vga port?? Tell me what it is and how you’re tying that to your ESP!

1 Like

Not VGA, but DB9 which is same/similar. Prior to getting into ESP, I was developing my project around the Arduino Mega and housed the Mega in a small case. From the case, I used DB9 ports to connect with my hardware which at the time were the 8 channel relay module (pictured above), two DHT temp/humidity sensors and 8 peristaltic dosing pumps that were driven by TIP120 transistors. I’m currently in the process of migrating everything to an ESP atmosphere. The small module in the above pic is my master ESP and it will interface all of my widgets as well as run the 2 DHT22 sensors. I soldered all the GNDs and 3V leads together and also solder on right angle male header pins, Once I completely iron out the circuit configurations, I will likely remove the pin headers from the ESP and solder the wires directly.

Looks like he is using a 9-pin D-Sub plug for power and data cable connection… probably to the relay box, althogh I cannot see the matching socket on it.

@Skybound It appears you are inputting AC converted power to the battery socket… which I hope you understand is not rated for 5v (meant to charge and feed from the LiPo, thus 3-4.2v would be my guess)… and if like any battery capable ESP I have used, will not pass or boost 5v onto the 5v pin that you have on your D-Sub, so not understanding what you are doing there.

The module next to the ESP is a 5V1A phone charger I hacked apart, put a short length of 110VAC cable on one end, and the battery JST connector on the other. I read as deeply as I could into the Adafruit datasheet for the Huzzah Feather and was lead to believe that everything more or less ties together inside, so I chose to go this route to power the ESP. Assuming I didn’t already smoke the board from powering it the wrong way or over driving the pins, how would you suggest I inlet the 5V supply? If I did smoke it, I have others.

Feather Huzzah ESP - datasheet in Tech Details

Through the USB pin just like if it was from a USB plug.

image

image
image

But not through the battery connector (VBAT)… the SCHOTTKY BARRIER RECTIFIER is probably limiting the voltage.


https://learn.adafruit.com/assets/31354

1 Like

Ok, I replaced the liPoly JST connects with micro USB on both boards as pictured below.

Also, please look at the side by side of the sketches. The left is the slave with relays connected to each pin. I’ve commented out 5 of the 8 relays, so only 3 can operate. 1 of those 3 channels already performs great. So I’m now just trying to verify if my code looks good/functional for the other 2 channels. The code snippet is only for one of those channels, but the other is identical.

left side is the slave and right side is the master. Also, is pasted the handlers that are in both sketches. What I want is to press a button in my app (pumpAon on V30) “or” if the time makes the function true, send the value of 1 (TURN_ON) over the bridge on V62. The slave should see the value on V62 and execute digitalWrite commands based upon what value V62 holds.

BLYNK_WRITE(V62) {
  CC = param.asInt();  // pumpA remote
}

Does the above look correct? Below is my USB power feed from the respective hacked phone chargers.

So if I understand you want to send data to a selected bridge.

Here is what I did.

I created 3 devices with the same code each having a seperate id.

I then create three bridges in each device so that they can talk.

like this

#define bridgedata      V9

WidgetBridge bridge1(51);
WidgetBridge bridge2(52);
WidgetBridge bridge3(53);

BLYNK_CONNECTED() {
  bridge1.setAuthToken(a_token); 
  bridge2.setAuthToken(b_token); 
  bridge3.setAuthToken(c_token); 
}

to select the device to talk to I send a message to the master device. and set a flag that tells the device that it is waiting for a message.

Like this

BLYNK_WRITE(vpin##)
{
  talktome = 1;
  bridge1.virtualWrite(Same Vpin##, 1);     //bridge 1 is the master
}

when the master get this it sends the data to the other devices like this

BLYNK_WRITE(VPIN??)
{
  bridge2.virtualWrite(bridgedata, cardHolder[0], cardId[0], accessFlags[0]);      //bridge 2 slave
  bridge3.virtualWrite(bridgedata, cardHolder[0], cardId[0], accessFlags[0]);      //Bridge 3 slave

}

you look for the data on the device like this

BLYNK_WRITE(VPin$$) // copy card to lock hardware
{
  if (talktome) {
    talktome = 0;
    cardHolder[0] = param[0].asStr();
    cardId[0] = param[1].asStr();
    accessFlags[0] = param[2].asInt();
  }
}

The talktome flag is defined as a global int.

@Gyromike Please take note of the time date stamps before revising old topics… children are conceived and bore in the time since this post… The OP probably figured out the answer in that timeframe as well :stuck_out_tongue:

I understand however it may help others that have a similar question

Thanks. but as I mentioned to you before, concerning old topics… please consider putting together another “Projects Made with Blynk” tutorial or something, like you did for NFC. That way we keep topics fresh without dragging on old ones for years… They can often get confusing after a few months due to constant development changes.

Thank you.