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,