Hi
I’ve having so many problems trying to use Blynk Bridge widget - I just can’t figure out why its not working for me.
My setup:
I have a Mega with a Ethernet Shield and a 4 x Relay Shield that I have verified works all fine. I can turn Relay 3 (on Digital Pin 5) on and off easily and see Relay light and hear relay click so I know that works.
I also have a WeMos D1 R2 ESP board with a simple program that I want to send a HIGH and LOW do Digitalpin 5 on to my Mega so my Relay 3 turns on and off. But it doesn’t work - I have no idea why.
NOTE: I did read on Blynk.cc that : “when communicating between different device types, as Ardiono Core may refer to wrong pins in such cases.” IF this is the case could this be why I can’t get this to work ? and if so can Blynk programmers pls publish the CORE pin mappings ?
I am running all this on my local Blynk server.
My code below…any help would be very much appreciated.
MEGA Board Code:
/*
* This is MEGA Arduino with Ethernet Shield and Relay Shield
*
*/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
// #include <ESP8266WiFi.h>
// #include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define RELAY1 7 // D7 [GPIO13 for ESP]
#define RELAY2 6 // D6 [GPIO12 for ESP]
#define RELAY3 5 // D5 [GPIO14 for ESP] // We are trying to set this digitalPin HIGH and LOW from the WeMos D1 R2 ESP board using BLYNK Bridge widget
#define RELAY4 4 // D4 [GPIO4 for ESP]
long BaudRate = 9600, sysTick = 0;
char GotChar;
char auth[] = "xxxx"; // Blynk token for Mega Project on LOCAL SERVER
void setup()
{
// Initialise the Arduino data pins for OUTPUT
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, IPAddress(xxx,xxx,xxx,xxx), 8442);
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V7)
{
// BLYNK_LOG("Got a value: %s", param.asStr());
// You can also use:
int i = param.asInt();
int state;
if (i==0) { digitalWrite(RELAY3,LOW);
Serial.println("Relay 3 LOW = OFF"); } // turn ON Relay 2
if (i==1) { digitalWrite(RELAY3,HIGH); // turn OFF Relay 2
Serial.println("Relay 3 HIGH = ON");
delay (500); } //
}
bool isFirstConnect = true;
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
Serial.println ("Blynk First connected EXECUTED");
}
}
The WeMos D1 R2 ESP code is:
#include <SPI.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "yyyyyy";
char rollerdoor_auth[] = "xxxx"; // Blynk token for ARDUINO Mega Project on LOCAL SERVER
// Bridge widget on virtual pin 1
WidgetBridge bridge1(V20);
// Timer for blynking
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "xxx", "xxx", IPAddress(xxx,xxx,xxx,xxx));
while (Blynk.connect() == false) {
// Wait until connected
}
// Call blynkAnotherDevice every second
timer.setInterval(8000L, blynkAnotherDevice);
}
BLYNK_CONNECTED() {
bridge1.setAuthToken(rollerdoor_auth);
Serial.println ("Linked to RollerDoor");
}
static bool value = true;
void blynkAnotherDevice()
{
// Send value to another device
if (value) {
bridge1.digitalWrite (5, HIGH);
Serial.println("Set D5 to high");
} else {
bridge1.virtualWrite(5, LOW);
Serial.println("Set D5 to low");
}
// Toggle value
value = !value;
}
void loop()
{
Blynk.run();
timer.run();
}