I’m using 2 NodeMcu esp8266 to collect data from DHT22 and SCD30 sensors.
I’m trying to send the data from SCD30 connected to one ESP8266 module to the one that is connectes to the DHT22 and display it in the app.
In the app (Blynk IoT) I have added a datastream V9 to show the sent data, but it always shows 0.
SCD30 - sending data:
#define BLYNK_TEMPLATE_ID "TEMP_SND"
#define BLYNK_DEVICE_NAME "NAME_SND"
#define BLYNK_AUTH_TOKEN "XXXXXXXXXXXXXXXXXXXXXX"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;
WidgetBridge bridge1(V1);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "GGGGGG";
char pass[] = "*****";
BlynkTimer timer;
void sendSensor()
{
if (airSensor.dataAvailable())
{
Blynk.virtualWrite(V9, airSensor.getHumidity());
int sendHumid = airSensor.getHumidity();
bridge1.virtualWrite(V10,100);
}
}
BLYNK_CONNECTED() {
bridge1.setAuthToken("YYYYYYYYYYYYYYYYYY"); // Place the AuthToken of the second hardware here
Serial.println("Connected to bridge"); // Showing that this code was executed.
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
Wire.begin();
timer.setInterval(3000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
Receiving data:
#define BLYNK_TEMPLATE_ID "TEMP_RCV"
#define BLYNK_DEVICE_NAME "NAME_RCV"
#define BLYNK_AUTH_TOKEN "YYYYYYYYYYYYYYYYYY"
#define BLYNK_PRINT Serial
#define DHTPIN 5 // What digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "GGGGGG"; ;
char pass[] = "*****";
int pinData;
WidgetBridge bridge1(V1);
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V7, h);
Blynk.virtualWrite(V8, t);
Blynk.virtualWrite(V9, pinData);
}
BLYNK_WRITE(V10){
pinData = param.asInt(); // pinData variable will store value that came via Bridge
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(3000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
Is there anything i’m missing that i need to update in the dashboard/app? any data streams to create? update?
Thanks all, i’ll check the solutions you’ve suggested. Getting data from all devices to a single controller will definitely improve my project. I’ll also consider using the legacy version since the bridge widget gives another solution.
I’ll use this post for further question about automation. I cant seem to understand how should I update a device when action occurs.
For example, I have a humidity device with a relay and ESP8266 that I want to turn on when another device send low humidity %.
So I understand how to set up the data streams on both device and set up an action, I don’t understand how this action will change the state of the relay.
Should I read the virtual pin connected to the data stream?
I have, and I am setting everything as described, just the part where I want to change the relay state, this I don’t understand how it is done.
Where is the connection between the data stream that is defined to change switch when action occurs to the relay.
If you cant choose the device/datastream that you want to control with the automation then you probably haven’t configured that target datastream correctly in the Advanced settings
In the Expose to Automations part, you’ll need the target device configured as a Switch, and Available in Actions checked.
@PeteKnight I can see the device and data stream and configured it as you suggested.
@John93 Yes, I’m configuring something like this, just not sure how exactly the data is updated in the sending and receiving side. I’m missing something…