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.