BlynkEdgent

Please help if you can.
I have seen others have had similar issues and have tried the solutions provided, none have worked for me.

I am trying to create a simple sketch to link a DHT11 sensor to Blynk
I am using a ESP8266 on a PC
I have managed to write a sketch to simply blink an on-board LED, compile and upload to the ESP8266. This worked - no problem
The problem comes up when trying to validate the sketch below.
I even tried to simply copy this below code into the sketch simple LED sketch and teh same error occurred.

I get the following error, no matter what I have tried.

I have also Update my library - Deleted library and re-installed - Tried other board selections – Nothing seems to do the trick

ERROR REPORT:
Arduino: 1.8.19 (Windows 10), Board: “Generic ESP8266 Module, 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

C:\Program Files (x86)\Arduino\libraries\DHT_sensor_library-1.4.3\DHT_U.h:36:10: fatal error: Adafruit_Sensor.h: No such file or directory

36 | #include <Adafruit_Sensor.h>
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Generic ESP8266 Module.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLANdHxXFH"
#define BLYNK_DEVICE_NAME "BLYNK app project"

#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial

//#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"
#include "DHT.h"
#define DHTPIN D2 
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);
float t, h;

void sendSensor()
{
  h = dht.readHumidity();
  t = dht.readTemperature();  
  Blynk.virtualWrite(V0, h);
  Blynk.virtualWrite(V1, t);
}

void setup()
{
  Serial.begin(9600);
  dht.begin();
  BlynkEdgent.begin();
  delay(2000); 
  timer.setInterval(1000L, sendSensor); 
}

void loop() 
{
  BlynkEdgent.run();
  timer.run(); // Initiates SimpleTimer
}```

This might be that you are choosing Generic ESP8266 as your board type in the IDE, rather than NodeMCU (which I assume is what you’re using).

Generic ESP8266 doesn’t support the digital pin aliases like “D2”, which may be causing the issue.

Otherwise you may be missing one of the Adafruit helper libraries that are needed to enable the Adafruit DHT library.

I also notice that you don’t have a board type un-commented in your Edgent sketch.
You should read this to understand how board types work, and which pins the Edgent sketch uses in the Settings.h file, so need to be avoided for sensors etc in your sketch…

Pete.

also, you should add a timer object to your sketch

BlynkTimer timer;

Pete,
Thank you very much for your speedy and extremely helpful reply.
As a complete novice and beginner in this field, assistance like this is highly appreciated.

Allow me to tell you where I am up to in my “baby steps” methodology.

I have been using the NodeMCU 1.0 (ESP-12E Module) Board in my setup
I have followed your instruction to the letter, uncommented the appropriate board and am at the point where I want to upload the sketch (pasted below) to the board.

This is where I get the following error:

Arduino: 1.8.19 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”

Blynk_with_NodeMCU_ESP8266_001:10:10: fatal error: BlynkSimpleEsp8266.h: No such file or directory
10 | #include <BlynkSimpleEsp8266.h>
compilation terminated.
exit status 1
BlynkSimpleEsp8266.h: No such file or directory

I searched for but could not find BlynkSimpleEsp8266.h which made me think that this is possibly more than just a missing library.

Just as a side note.
Does it make a difference as to which folder the libraries are downloaded to because somehow my downloads are going to 3 different folders.
I have no doubt that I selected a setting for this at some point in time, but simply don’t know.
Also - Must all the downloaded libraries be unzipped after download?

// https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLQwq5uoqJ"
#define BLYNK_DEVICE_NAME "NodeMCU Temp Humidity"

//===============================================
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
//===============================================


#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

#include "BlynkEdgent.h"

//=============================================
#define DHTPIN D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer; // Announcing the timer
//=============================================

int temp;
int humidity;







BLYNK_WRITE(V0)
{
 if(param.asInt()==1){
   digitalWrite(2, HIGH);
 }
 else{
   digitalWrite(2, LOW);
 }
}

BLYNK_CONNECTED()
{
 Blynk.syncVirtual(V0);
 Blynk.virtualWrite(V1, temp);  
 //Blynk.virtualWrite(V2, humidity);  
}




void setup()
{
 pinMode(2, OUTPUT); // Initialise digital pin 2 as an output pin
 Serial.begin(115200);
 timer.setInterval(1000L, sensorDataSend); //timer will run every sec 
 delay(100);

 BlynkEdgent.begin();

//==================================================
 pinMode(D4, OUTPUT);
 digital Write(D4, HIGH);
 Serial.begin(9600);
 Blynk.begin(auth, ssid, pass);
 dht.begin();
 //=========================================
 
}




//=============================================
void Sendsensor{}

{
 if(WiFi.status() != WL_CONNECTED)
 digitalWrite(D4,HIGH);
 else
 digitalWrite(D4, LOW);
 float h =dht.readHumidity();
 float t =dht.readTemperature();

if(isnan(h) || isnan(t){
Serial.println(Failed to read sensor");
return;
}

Blynk.virtalWrite(V1,h);
Blynk.virtalWrite(V0,t);
}

//===================================================


void loop() {
//  temp= analogRead(A0)/0.32;
//  //humidity= analogRead(A2);
//  BlynkEdgent.run();

 //=============================
 Blynk.run();
 timer.run();        // run timer every second
 //=========================
}

Please edit your post and add triple backticks ( ``` ) before and after your whole sketch.

also, you should read this

There’s no need to use Blynk.run, you should only use BlynkEdgent.run

Thanks John,
I have edited the initial sketch as you instructed and thank you for the Timer information.
I will edit my sketch and hope to see a positive result if my rudimentary ability succeeds.
Learning from the scratch of a standing start can be challenging and “silly questions” are sometime unavoidable.
Rob

Why are you adding these libraries to the Edgent example sketch?
Edgent is a fully working example that requires no changes other than inserting the template and device IDs and un-commenting a board type.

Which libraries are you talking about?

Generally, libraries go in documents/arduino/libraries on a windows system.

Are you using the Arduino IDE library manager to install the libraries?

Pete.

Pete,

Let me start by telling you what I am trying to do at this stage and bear in mind that I have just been using YouTube and reading as many help/information sites that I could find the time for.

I am reasonably comfortable with C++ and Arduino IDE sketches, so that is my mindset I am coming from.

To start, I just want to create a linked “application” of a temp/humidity sensor linked to a desktop and Mobile app. Hence me trying to link the DHT11 to the ESP8266.

This will be my first incremental step toward linking my Arduino weather station of multiple sensors to my phone - But 1 small step at a time

“Why are you adding these libraries to the Edgent example sketch?”
I suspect this is what happens when one simply cuts and pastes from YouTube examples and gets a load of superfluous lines of unnecessary code

“Edgent is a fully working example that requires no changes other than inserting the template and device IDs and un-commenting a board type.”
Possibly I have the completely wrong end of the stick here because I am under the impression that one writes an Arduino IDE sketch that links the 2 devices just mentioned and thereafter one creates a template on Blynk which is then interfaced with the Arduino IDE sketch.

This question of yours makes me think I am going about this whole malarkey in the wrong way.

Which libraries are you talking about?
Every time I compile a sketch in Arduino IDE and get an error regarding a library, I simply download said library using the Arduino IODE and this seems to either go into the folder you have just mentioned or sometimes into the folder where the Arduino IDE sketch files are located.

Like now:
I have just tried to complied and upload Edgent and I get the error that the BlynkSimpleEsp8266.h does not exist.
Consequently I tried to find and download this library and these are what I am referring to.

Arduino: 1.8.19 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”
In file included from C:\Data\Dropbox\Arduino\Projects\Edgent_ESP8266\Edgent_ESP8266\Edgent_ESP8266.ino:19:

BlynkEdgent.h:10:10: fatal error: BlynkSimpleEsp8266_SSL.h: No such file or directory
10 | #include <BlynkSimpleEsp8266_SSL.h>
exit status 1
BlynkSimpleEsp8266_SSL.h: No such file or directory

So that’s now a different library that you’re missing.

It looks like you don’t have the Blynk C++ library installed on YouTube system, of if you do it’s in a place where the compiler can’t find it.

When you open the Arduino IDE library manager and search for “Blynk” what does it show?

Pete.

Pete,

When opening the IDE library, you where 100% correct, I did not have the Blynk library installed.
I must add that I have deleted and added libraries on my PC so many times that I have lost count.

I have reinstalled the Blynk library and have found it installed into a folder
C:\Data\Dropbox\Arduino\Paul McWhorter\libraries
This is a folder that I created some time ago when I started learning about the Arduino and there where libraries to install to be able to do some of the projects.
Somehow this has become the default Library folder because I moved all the previously installed libraries from
C:\Users\ABCD\AppData\Local\Arduino15\staging\libraries
Where they where previously installed, to this folder and the IDE seems to work fine

More imposrant though is that after installing the newest Blynk.h the Edgent example sketch compile works fine and I am now at " Initial Provisioning" on the troubleshooting page you sent earlier on.
Just about to restart that process.

Please be so kind as to comment on my statement:
Possibly I have the completely wrong end of the stick here because I am under the impression that one writes an Arduino IDE sketch that links the 2 devices just mentioned and thereafter one creates a template on Blynk which is then interfaced with the Arduino IDE sketch.

I am starting to think that possible the more correct procedure is to start with the Edgent example sketch, rename, save and the populate this sketch with new code to accommodate the sensors that I want to add to this project.

Rob

Agreed.

Agreed.

Pete.

Thanks to you and your generous time, I am finally getting somewhere.
Now lets hope I manage to get through the troubleshoot relative unscathed :slight_smile:

Arduino IDE
Library is in C:\Data\Dropbox\Arduino\Libraries
ESP8266 NodeMCU
ESP8266
DHT11
LED
I have started with the Edgent_ESP8266 example sketch

1: Please tell me where Blynk.h library is installed or included

2: Am I correct that BlynkTimer.h does not have to be included as a separate library?

3: #define USE_NODE_MCU_BOARD is uncommented. Please help me understand why when this line of code is uncommented, the switching of the LED in the attached sketch does not work but when this line of code is commented, the LED switching works BUT the connection to the DHT11 is lost

4: When I #include <BlynkSimpleEsp8266.h> I get the following error:

Arduino: 1.8.19 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”
In file included from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\ESP8266_NodeMCU_DHT11_LM35DZ_LED_001.ino:32:
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266.h:29:7: error: template argument required for ‘class BlynkWifi’
29 | class BlynkWifi
| ^~~~~~~~~
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266.h:100:21: error: conflicting declaration ‘WiFiClient _blynkWifiClient’
100 | static WiFiClient _blynkWifiClient;
| ^~~~~~~~~~~~~~~~
In file included from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\BlynkEdgent.h:10,
from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\ESP8266_NodeMCU_DHT11_LM35DZ_LED_001.ino:28:
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266_SSL.h:192:27: note: previous declaration as ‘BearSSL::WiFiClientSecure _blynkWifiClient’
192 | static WiFiClientSecure _blynkWifiClient;
| ^~~~~~~~~~~~~~~~
In file included from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\ESP8266_NodeMCU_DHT11_LM35DZ_LED_001.ino:32:
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266.h:101:29: error: conflicting declaration ‘BlynkArduinoClient _blynkTransport’
101 | static BlynkArduinoClient _blynkTransport(_blynkWifiClient);
| ^~~~~~~~~~~~~~~
In file included from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\BlynkEdgent.h:10,
from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\ESP8266_NodeMCU_DHT11_LM35DZ_LED_001.ino:28:
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266_SSL.h:193:53: note: previous declaration as ‘BlynkArduinoClientSecureBearSSL::WiFiClientSecure _blynkTransport’
193 | static BlynkArduinoClientSecure _blynkTransport(_blynkWifiClient);
| ^~~~~~~~~~~~~~~
In file included from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\ESP8266_NodeMCU_DHT11_LM35DZ_LED_001.ino:32:
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266.h:102:13: error: conflicting declaration ‘BlynkWifi<…auto…> Blynk’
102 | BlynkWifi Blynk(_blynkTransport);
| ^~~~~
In file included from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\BlynkEdgent.h:10,
from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_754775\ESP8266_NodeMCU_DHT11_LM35DZ_LED_001.ino:28:
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266_SSL.h:194:58: note: previous declaration as ‘BlynkWifi<BlynkArduinoClientSecureBearSSL::WiFiClientSecure > Blynk’
194 | BlynkWifi<BlynkArduinoClientSecure > Blynk(_blynkTransport);
| ^~~~~
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

// Fill-in information from your Blynk Template here
char auth[] = "_omyDSXtrWE_7UTL3gZsurAkCaklB2zf";

char ssid[] = "Rob's Networks";  //Enter your WIFI Name
char pass[] = "4121@Flag";  //Enter your WIFI Password

#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#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 BLYNK_TEMPLATE_ID "TMPLwRpGCxLt"
#define BLYNK_DEVICE_NAME "NodeMCU"

#include "BlynkEdgent.h"

//DHT11===============================================
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <DHT.h>
//#include <BlynkTimer.h>

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

//const int LM35DZPin =  A0;       // the number of the LM35DZ pin
float LM35DZPin =  A0;       // the number of the LM35DZ pin
#define DHTPIN 4          // Digital pin 2
#define LEDPin 2  // Digital pin 4

float Temp_DHT11;
float Humid_DHT11;
float TempLM35DZ;

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// 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.

//The BLYNK_WRITE() function is used to check for incoming data at V0 and V1 Virtual pins.
BLYNK_WRITE(V0)
{
  if (param.asInt() == 1) {
    digitalWrite(LEDPin, HIGH);
  }
  else {
    digitalWrite(LEDPin, LOW);
  }
}

//BLYNK_WRITE(V0){
// //time_blynk = param.asInt();
//}
//
//BLYNK_WRITE(V2){
// //time_blynk = param.asInt();
//}
//
//BLYNK_WRITE(V3){
// //time_blynk = param.asInt();
//}


BLYNK_CONNECTED()
{
  // You can send any value at any time. but don't send more that 10 values per second.
  Blynk.syncVirtual(V0);
  //Write from NodeMCU to blync Server
  Blynk.virtualWrite(V1, TempLM35DZ);
  Blynk.virtualWrite(V2, Temp_DHT11);
  Blynk.virtualWrite(V3, Humid_DHT11);
}

void sendSensor()
{
  //TempLM35DZ = analogRead(LM35DZPin) * (3.3 / 1023) * 1000; //original formula
  TempLM35DZ = analogRead(LM35DZPin) * (3.0 / 1023) * 1000; // Adjusted formula to match DHT11 temp
  Serial.print("Temp Variable at LM35DZ: ");
  Serial.println(analogRead(LM35DZPin));

  Serial.print("Temp at LM35DZ: ");
  Serial.println(TempLM35DZ);

  Temp_DHT11 = dht.readTemperature();
  Serial.print("Temp at DHT11: ");
  Serial.println(Temp_DHT11);

  Humid_DHT11 = dht.readHumidity();
  Serial.print("Humidity at DHT11: ");
  Serial.println(Humid_DHT11);

  if (isnan(Humid_DHT11) || isnan(Temp_DHT11)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
}


void setup()
//Defaults =======================================================================================
{
  Serial.begin(115200);
  pinMode(LEDPin, OUTPUT); // Initialise digital pin 2 as an output pin
  Blynk.begin(auth, ssid, pass);
  delay(100);
  BlynkEdgent.begin();
  delay(100);
  dht.begin();
  // Setup a function to be called every second
  timer.setInterval(2000L, sendSensor);
}


void loop() {
  //Defaults =======================================================================================
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates BlynkTimer
  BlynkEdgent.run();
}

It’s part of the Blynk library, and is installed wherever you installed that to.

Yes, correct.

Please read the “Troubleshooting Edgent….” link that I provided 8n post #2

Then stop including it! Like I told you before…

These two lines need to be a the very top of your sketch, otherwise the library will compile as a legacy sketch.…

These two lines of code (one from void setup, and the other from void loop) have no place in the Edgent sketch. Please delete them…

And these three lines of code don’t belong in an Edgent sketch either. Please remove them too…

You don’t seem to have grasped the concepts that the Blynk Edgent example is a fully working Blynk sketch which provides dynamic provisioning of WiFi credentials and Blynk Auth token without the need for any changes, other than you copying and pasting the template ID and device name from the web console into the top of your sketch and un, commenting the correct board type.

I strongly suggest that you take the Edgent ESP8266 example and simply add your template ID and device name and un-comment the NodeMCU board type, compile it, upload it to your board and provision the device via the app.

Once you have this working, add-in the non-Blynk code from your original sketch, taking care not to create any pin conflicts from the pins used by Edgent.

Pete.

Thanks Pete,
I have certainly waste my time by overcomplicating this sketch.
I apologize for possibly wasting your time as well.

I have just done what you have instructed me to do. I think I have done it all.
But now get this error.

Arduino: 1.8.19 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”
In file included from C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/Blynk/BlynkApi.h:36,
from C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkApiArduino.h:14,
from C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/BlynkSimpleEsp8266_SSL.h:27,
from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_744288\BlynkEdgent.h:10,
from C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_744288\Edgent_ESP8266.ino:20:
C:\Users\ABCD\AppData\Local\Temp\arduino_modified_sketch_744288\ConfigStore.h: In function ‘bool config_load_blnkopt()’:
ConfigStore.h:75:29: error: expected ‘,’ or ‘;’ before ‘BLYNK_WIFI_SSID’
75 | BLYNK_PARAM_KV(“ssid” , BLYNK_WIFI_SSID)
| ^~~~~~~~~~~~~~~
C:\Data\Dropbox\Arduino\libraries\Blynk-1.1.0\src/Blynk/BlynkParam.h:19:37: note: in definition of macro ‘BLYNK_PARAM_KV’
19 | #define BLYNK_PARAM_KV(k, v) k “\0” v “\0”
| ^
exit status 1
expected ‘,’ or ‘;’ before ‘BLYNK_WIFI_SSID’

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLwRpGCxLt"
#define BLYNK_DEVICE_NAME "NodeMCU"
#define BLYNK_AUTH_TOKEN "_omyDSXtrWE_7UTL3gZsurAkCaklB2zf"

#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

#include "BlynkEdgent.h"


//======================================================================================
//DHT11===============================================
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <DHT.h>


// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

//const int LM35DZPin =  A0;       // the number of the LM35DZ pin
float LM35DZPin =  A0;       // the number of the LM35DZ pin
#define DHTPIN 4          // Digital pin 2
#define LEDPin 2  // Digital pin 4

float Temp_DHT11;
float Humid_DHT11;
float TempLM35DZ;

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// 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.

//The BLYNK_WRITE() function is used to check for incoming data at V0 and V1 Virtual pins.
BLYNK_WRITE(V0)
{
  if (param.asInt() == 1) {
    digitalWrite(LEDPin, HIGH);
  }
  else {
    digitalWrite(LEDPin, LOW);
  }
}

//BLYNK_WRITE(V0){
// //time_blynk = param.asInt();
//}
//
//BLYNK_WRITE(V2){
// //time_blynk = param.asInt();
//}
//
//BLYNK_WRITE(V3){
// //time_blynk = param.asInt();
//}


BLYNK_CONNECTED()
{
  // You can send any value at any time. but don't send more that 10 values per second.
  Blynk.syncVirtual(V0);
  //Write from NodeMCU to blync Server
  Blynk.virtualWrite(V1, TempLM35DZ);
  Blynk.virtualWrite(V2, Temp_DHT11);
  Blynk.virtualWrite(V3, Humid_DHT11);
}

void sendSensor()
{
  //TempLM35DZ = analogRead(LM35DZPin) * (3.3 / 1023) * 1000; //original formula
  TempLM35DZ = analogRead(LM35DZPin) * (3.0 / 1023) * 1000; // Adjusted formula to match DHT11 temp
  Serial.print("Temp Variable at LM35DZ: ");
  Serial.println(analogRead(LM35DZPin));

  Serial.print("Temp at LM35DZ: ");
  Serial.println(TempLM35DZ);

  Temp_DHT11 = dht.readTemperature();
  Serial.print("Temp at DHT11: ");
  Serial.println(Temp_DHT11);

  Humid_DHT11 = dht.readHumidity();
  Serial.print("Humidity at DHT11: ");
  Serial.println(Humid_DHT11);

  if (isnan(Humid_DHT11) || isnan(Temp_DHT11)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
}


//==============================================================================================================





void setup()
{
  Serial.begin(115200);
  delay(100);

  BlynkEdgent.begin();

  //===================================================================================================
  pinMode(LEDPin, OUTPUT); // Initialise digital pin 2 as an output pin

  dht.begin();
  // Setup a function to be called every second
  timer.setInterval(2000L, sendSensor);
  //===============================================================================


}

void loop() {
  timer.run(); // Initiates BlynkTimer
  BlynkEdgent.run();
}

Edgent will dynamically provision your Auth token, so this shouldn’t be here.

Also, if you’ve created a device from your template then you should delete it. The device will be created when you hit “+ Add Device” in the app then go through the provisioning process.

You will notice that the Edgent sketch doesn’t include a blank line for the Auth token, and this is why, and also why I’ve repeatedly said that you need to add the template ID and device name to the top of the sketch, and not said to also add the Auth token.

You seem to have jumped this suggestion…

And gone straight to…

without reaching the…

stage.

Pete.

Thanks Pete,
It has taken a lot of “head scratching” but thanks to you I have just managed to get this part of my project working.
Really appreciate the assistance
Rob

1 Like