The code below works on Wemos LoLin D32 board well ( before WiFi provisioing ) . But adding Edgent.h throws multiple errors … Probably I have too many unwanted includes ? Kinly suggest the mistake that I am making…
/* Fill-in information from Blynk Device Info here and there should be no code before this */
#define BLYNK_TEMPLATE_ID "XXX"
#define BLYNK_TEMPLATE_NAME "XXX"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <esp_wifi.h>
#include "BlynkEdgent.h"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define APP_DEBUG
#define LOLIN_D32 // Define your board here
BlynkTimer timer;
Adafruit_BME280 bme; // I2C define
float Pressure ;
float DegC ;
float Humidity ;
int status;
const byte blueLED = 5;
byte blynkStatus ;
byte connectionTimeOut = 10;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setup()
{
// Debug console
Serial.begin(9600);
status = bme.begin(0x76);
pinMode(blueLED, OUTPUT);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
}
BlynkEdgent.begin();
int timeout_counter = 0;
byte ledStatus = LOW ;
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
if (ledStatus ) {
ledStatus = HIGH ;
}
else {
ledStatus = LOW;
}
digitalWrite( blueLED, ledStatus) ;
timeout_counter++;
if (timeout_counter >= connectionTimeOut * 5) {
ESP.restart();
}
}
//Blynk.config(BLYNK_AUTH_TOKEN);
blynkStatus = Blynk.connect();
if (!blynkStatus) {
ESP.restart();
}
digitalWrite(blueLED, LOW ); // Connected to Blynk. Light up !!
// Specify the intervals for two timer calls
timer.setInterval(60000L, myTimerEvent);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void loop()
{
BlynkEdgent.run() ;
timer.run();
if ( Blynk.connected()) {
Blynk.run();
}
else {
digitalWrite( blueLED, HIGH ) ;
ESP.restart();
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// This function sends data to Blynk App. At the specified interval when it fires.
void myTimerEvent()
{
DegC = bme.readTemperature();
Humidity = bme.readHumidity();
Pressure = bme.readPressure();
Blynk.virtualWrite(V0, DegC);
Blynk.virtualWrite(V1, Humidity);
Blynk.virtualWrite(V2, Pressure / 100);
}
// This function tries to restore connection if there is any momentary router drop out
// After the Blynk.Connected() was chcekd inside loop(), this is not used.
void checkConnection()
{
blynkStatus = Blynk.connected();
if (blynkStatus ) {
digitalWrite( blueLED, HIGH ) ;
}
else {
digitalWrite( blueLED, LOW ) ;
ESP.restart();
}
}
Difficult to say without understanding what errors you are getting.
Are these compilation errors or runtime errors?
Did you start with the Edgent example then add-in your own code, or have you tried to add Edgent to an existing sketch?
Pete.
I am sorry to not include the Error messages earlier… it was pretty voluminous !! And I did not even know where to start … here we go.
In file included from D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Desktop\Blynk_3Ch_Weather_WiFiProv\BlynkEdgent.h:8,
from D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Desktop\Blynk_3Ch_Weather_WiFiProv\Blynk_3Ch_Weather_WiFiProv.ino:24:
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32_SSL.h:55:7: error: 'BlynkWifi' is not a template
55 | class BlynkWifi
| ^~~~~~~~~
In file included from D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Desktop\Blynk_3Ch_Weather_WiFiProv\Blynk_3Ch_Weather_WiFiProv.ino:19:
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h:27:7: note: previous declaration here
27 | class BlynkWifi
| ^~~~~~~~~
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32_SSL.h:130:27: error: conflicting declaration 'WiFiClientSecure _blynkWifiClient'
130 | static WiFiClientSecure _blynkWifiClient;
| ^~~~~~~~~~~~~~~~
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h:96:21: note: previous declaration as 'WiFiClient _blynkWifiClient'
96 | static WiFiClient _blynkWifiClient;
| ^~~~~~~~~~~~~~~~
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32_SSL.h:131:53: error: conflicting declaration 'BlynkArduinoClientSecure<NetworkClientSecure> _blynkTransport'
131 | static BlynkArduinoClientSecure<WiFiClientSecure> _blynkTransport(_blynkWifiClient);
| ^~~~~~~~~~~~~~~
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h:97:27: note: previous declaration as 'BlynkEsp32Client _blynkTransport'
97 | static BlynkEsp32Client _blynkTransport(_blynkWifiClient);
| ^~~~~~~~~~~~~~~
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32_SSL.h:132:3: error: 'BlynkWifi' is not a template
132 | BlynkWifi<BlynkArduinoClientSecure<WiFiClientSecure> > Blynk(_blynkTransport);
| ^~~~~~~~~
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32_SSL.h:132:58: error: redefinition of 'BlynkWifi Blynk'
132 | BlynkWifi<BlynkArduinoClientSecure<WiFiClientSecure> > Blynk(_blynkTransport);
| ^~~~~
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h:98:13: note: 'BlynkWifi Blynk' previously declared here
98 | BlynkWifi Blynk(_blynkTransport);
| ^~~~~
In file included from D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32_SSL.h:137:
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkWidgets.h:20:7: error: redefinition of 'class VPinWriteOnChange<T>'
20 | class VPinWriteOnChange {
| ^~~~~~~~~~~~~~~~~
In file included from D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h:103:
D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Blynk\src/BlynkWidgets.h:20:7: note: previous definition of 'class VPinWriteOnChange<T>'
20 | class VPinWriteOnChange {
| ^~~~~~~~~~~~~~~~~
Multiple libraries were found for "Adafruit_BME280.h"
Used: D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Adafruit_BME280_Library
Not used: D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Adafruit_BME280_Library-master
Multiple libraries were found for "Wire.h"
Used: C:\Users\RAGHUNATHAN\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.2.0\libraries\Wire
Not used: D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Wire
Not used: D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\Wire_Alternate
Multiple libraries were found for "SPI.h"
Used: C:\Users\RAGHUNATHAN\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.2.0\libraries\SPI
Not used: D:\18_OneDrive_HHPL\OneDrive - Hydroquip Hydraulics Pvt Ltd\Documents\Arduino\libraries\SPI
exit status 1
Compilation error: exit status 1
And the answers to the rest of my questions?
Pete.
It was code that was done in legacy Blynky and I introduced the Edgent and landed in a mess. I then realized it was due to too many #include defines. So one one by one removed and got the code to compile … that’ s done . But the code does not do what it should … of course reading more examples . Not sure about the mistake till now.
#define BLYNK_TEMPLATE_ID "xxxxx"
#define BLYNK_TEMPLATE_NAME "yyyyy"
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "BlynkEdgent.h"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define APP_DEBUG
#define LOLIN_D32 // Define your board here
BlynkTimer timer;
Adafruit_BME280 bme; // I2C define
float Pressure ;
float DegC ;
float Humidity ;
int status;
const byte blueLED = 5;
byte blynkStatus ;
byte connectionTimeOut = 10;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setup()
{
// Debug console
Serial.begin(9600);
status = bme.begin(0x76);
pinMode(blueLED, OUTPUT);
digitalWrite( blueLED, HIGH) ;
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
}
BlynkEdgent.begin();
timer.setInterval(60000L, myTimerEvent);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void loop()
{
BlynkEdgent.run() ;
timer.run();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// This function sends data to Blynk App. At the specified interval when it fires.
void myTimerEvent()
{
DegC = bme.readTemperature();
Humidity = bme.readHumidity();
Pressure = bme.readPressure();
Blynk.virtualWrite(V0, DegC);
Blynk.virtualWrite(V1, Humidity);
Blynk.virtualWrite(V2, Pressure / 100);
}
My advice - start a new sketch by opening the Edgent example. Test that it provisions correctly with your hardware, then add-in the additional functionality you need.
Before adding-in any #includes, search ALL of the Edgent tabs to ensure that the library isn’t already included.
Pete.
1 Like
OK great … its connected. But I just have one query on the check regarding active connection to Blynk server.
Now the code effectively is only this 
void setup()
{
BlynkEdgent.begin();
timer.setInterval(5000L, myTimerEvent);
}
//====================
void loop()
{
BlynkEdgent.run() ;
timer.run();
}
So once started how to check if I am still on line and if not , do an Auto restart ? Does Edgent handle all this ?
I don’t use Edgent, so can’t remember.
Why not take a look at the code and do some tests to see if it meets your needs?
Pete.
1 Like
Oh ok… I thought that Edgent was the latest and best way to IoT using the ESP32 boards !! Possibly you are on to much more advanced methods.
Sure will have a look to see. Thanks
I have no need for the complexity of Edgent.
I prefer to have the WiFi credentials hard-coded in my sketches along with the Blynk auth token, rather than dynamically provisioning them via the Blynk app.
As a result, I use a far simpler Blynk sketch which is very similar to those I used with Blynk Legacy.
Pete.
2 Likes