Hi, beginner here and I apologize in advance for my english as it’s not my first language. I’ve successfully implemented the dht11 code provided in https://examples.blynk.cc/, I even added bh1750 and it works perfectly fine on the esp8266 even the value pops up on the app and blynkconsole. But now I’m trying to use BlynkEdgent.h si I can connect it to a different wifi without having to change the coding. I tried using the BlynkEdgent.h example in arduino IDE and reused most of my already working code. I can connect it to my phone but it failed to read the sensor. Am I doing something wrong?
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLMEsYL1CB"
#define BLYNK_DEVICE_NAME "HP0nics"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI
#define DHTPIN D3
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
#include <DHT.h>
#include <BH1750.h>
#include <Wire.h>
#include "BlynkEdgent.h"
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer1;
BH1750 lightMeter;
float t,h,l;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
h = dht.readHumidity();
l = lightMeter.readLightLevel();
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT11 sensor!");
return;
}
if (isnan(l)){
Serial.println("Failed to read from BH1750 sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
Blynk.virtualWrite(V2, l);
}
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
dht.begin();
Wire.begin();
lightMeter.begin();
// Setup a function to be called every second
timer1.setInterval(2000L, sendSensor);
}
void loop() {
BlynkEdgent.run();
timer1.run();
t = dht.readTemperature();
h = dht.readHumidity();
l = lightMeter.readLightLevel();
delay(800);
}