What am I doing wrong? esp8266 ch340 dht22 Blynk 2.0"

Hello everyone, I’m new to the forum and also to Blynk, I’m trying to make a project work that was perfect in the old Blynk, but in 2.0 I can’t do it. First I show you the code to see what I’m doing wrong.

#define BLYNK_TEMPLATE_ID "MYTEMPLATEID"
#define BLYNK_DEVICE_NAME "MYNAME"
#define BLYNK_AUTH_TOKEN "MYTOOOOOOOOOKENNNNN"

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>


char auth[] = "OkwT0fIbqtje8_6yLY1NYvyDgahGzG-A";    //I don't know what's going on 
char ssid[] = "MEDINA-WIFI";
char pass[] = "dinofeli";

#define DHTPIN 4       

//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT22     

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;


void sendSensor()
{
 float nem = dht.readHumidity();
 float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

 if (isnan(nem) || isnan(sicaklik)) {
   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(V1, nem);
 Blynk.virtualWrite(V0, sicaklik);

}
void sendAlert()
{
 float nem = dht.readHumidity();
 float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if(sicaklik > 26)
 {
   Blynk.notify(String("Sıcaklık Yüksek ")+sicaklik + String("°C"));
 }
 
 // You can send any value at any time.
 // Please don't send more that 10 values per second.
   Blynk.virtualWrite(V0, sicaklik);
}

void setup()
{
 // Debug console
 Serial.begin(115200);

 Blynk.begin(auth, ssid, pass);
 // You can also specify server:
 //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
 //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

 dht.begin();

 // Setup a function to be called every second
 timer.setInterval(5000L, sendSensor);
 timer.setInterval(60000L, sendAlert);
}

void loop()
{
 Blynk.run();
 timer.run();
}

I have the D4 connected to the signal of the DHT22, the 3V to the power supply and the G to the ground. It used to work fine like this before.

and finally, another of my doubts, after creating the template, when I create the device, I don’t know what or which Datastreams to choose. I hope you can help me, thanks.

@KazaDoor please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Edited, I hope you can help me Pete. Thanks

This is the auth token from the new Blynk IoT dashboard, and the code that you copy paste from there assigns it a variable name of BLYNK_AUTH_TOKEN.

Your old sketch used the char variable of auth for this, so the simplest solution is to replace the following line…

With this:

char auth[] = BLYNK_AUTH_TOKEN;

As far as datastreams are concerned, your old project used two Virtual Pins, V0 and V1…

So you need to create two virtual pin datastreams - V0 and V1 with a data type of Double and you need to take care to set sensible money and max values - don’t leave the defaults of 0 and 1 otherwise you won’t see any data.

Pete.

I found another code, I think it’s newer, with my data it would look like this. but it appears offline.

/*
 * This program is property of SME Dehradun. for any query related to this program, contact us at www.smedehradn.com
 * if your want any soluiton related for any IoT Customized Boards and Sensor to www.nuttyengineer.com 
 */
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLRTutYRis"
#define BLYNK_DEVICE_NAME "CLIMAX"
#define BLYNK_AUTH_TOKEN "4lzjmi35kalX0PIz2caHeWMDNbdtpbAn"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"
#include "DHT.h"


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MEDINA-FTTH";  //ingrese nombre de red wifi
char pass[] = "dinofeli";  //ingrese contaseña de la red wifi

#define DHTPIN D4 
#define DHTTYPE DHT22

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
}

climax

As you told me, the code looked like this…

#define BLYNK_TEMPLATE_ID "TMPLRTutYRis"
#define BLYNK_DEVICE_NAME "CLIMAXTEMP"
#define BLYNK_AUTH_TOKEN "64evVt9Ez0ZnP5HLIRyClzTszCgqqEMx"

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>


char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "MEDINA-FTTH";
char pass[] = "dinofeli";

#define DHTPIN 4       

//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT22     

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;


void sendSensor()
{
 float nem = dht.readHumidity();
 float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

 if (isnan(nem) || isnan(sicaklik)) {
   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(V1, nem);
 Blynk.virtualWrite(V0, sicaklik);

}
void sendAlert()
{
 float nem = dht.readHumidity();
 float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if(sicaklik > 26)
 {
   Blynk.notify(String("Sıcaklık Yüksek ")+sicaklik + String("°C"));
 }
 
 // You can send any value at any time.
 // Please don't send more that 10 values per second.
   Blynk.virtualWrite(V0, sicaklik);
}

void setup()
{
 // Debug console
 Serial.begin(115200);

 Blynk.begin(auth, ssid, pass);
 // You can also specify server:
 //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
 //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

 dht.begin();

 // Setup a function to be called every second
 timer.setInterval(5000L, sendSensor);
 timer.setInterval(60000L, sendAlert);
}

void loop()
{
 Blynk.run();
 timer.run();
}

but the device does not send me data, it shows me erroneous data, although it appears online.

the datastreams place it like this…

That’s because you’re looking at the template view, not the device view.

Pete.

Very well, I understand, but now I log into the account on the cell phone, in the app and entering I don’t have the gadgets that I created on the web. I have the device but when I enter it it tells me "setup your mobile dashboard.
and when entering there is nothing, I enter the developer mode but I do not have any widget, and if I create one it does not give me data.

There is no duplication of widgets between the web dashboard and the mobile dashboard.

Tap the device, then the spanner (wrench) icon, then the + icon and add the widgets you need.

Pete.

Perfect, I have already made the tento gadgets work on the web and in the mobile app. I ask you these last 2 questions…
1 - Notifications can only be created in the PLUS or PRO versions, and they don’t work in the free version? (if they work I would like you to explain how to enable them).
2 - The user roles (to be able to market an app and that the client cannot modify anything) can only be modified in the PRO version or in the PLUS version I can already make users use the app and not be able to touch anything. Thank you for all of your help.

Incorrect.

Read the documentation and search the forum, it’s been discussed many times recently.

Role permissions can only be edited in PRO and White Label.
Change your users to the “Staff” role.

Pete.

Perfect, I found it. how to create events and generate a notification of them, I still don’t know how to use it from the source code but I trust that I will find it in the forum, otherwise I will be bothering you again.
One last question (this time it’s going to be true :slight_smile: ) is it crazy to think that I can handle by modifying the source code that I wrote before several DHT22 sensors with a single ESP8266 board? Could it be done and take the data from different virtual pin? Because if it works I want to test it, to be able to place a single NODEMCU with several sensors. Thanks in advance for the predisposition and answering the messages so quickly.

1 Like

It’s possible to use multiple DHT sensors with one ESP8266 board. You would need to declare additional DHT objects. In your existing code you have this…

And you could add something like this…

DHT dht_2(DHT_2PIN, DHT_2TYPE);

You can then take readings from your dht_2 Sensor in the same way that you do from your dht sensor.

Pete.

hello pete, I just resumed the project today and I’m looking at the topic of notifications and events, I already configured an event in the template with notification… but none is activated. Can you guide me to see what I’m doing wrong?

Here the code…


#define BLYNK_TEMPLATE_ID "TMPLdnAA_caL"
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "U1z4xPEw1FgiedaDoDo9U5h2VqxC93_K"

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>


char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "MEDINA-FTTH";
char pass[] = "dinofeli";

#define DHTPIN 4       

//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define DHTTYPE DHT22     

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;


void sendSensor()
{
 float nem = dht.readHumidity();
 float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

 if (isnan(nem) || isnan(sicaklik)) {
   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(V1, nem);
 Blynk.virtualWrite(V0, sicaklik);

 
if (V0 > 26){
    Blynk.logEvent("hotpush", "ESTO SE ESTA CALENTANDO,") ;
}

}
void sendAlert()
{
 float nem = dht.readHumidity();
 float sicaklik = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if(sicaklik > 26)
 {
   Blynk.notify(String("Sıcaklık Yüksek ")+sicaklik + String("°C"));
 }
 
 // You can send any value at any time.
 // Please don't send more that 10 values per second.
   Blynk.virtualWrite(V0, sicaklik);
}

void setup()
{
 // Debug console
 Serial.begin(115200);

 Blynk.begin(auth, ssid, pass);
 // You can also specify server:
 //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
 //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

 dht.begin();

 // Setup a function to be called every second
 timer.setInterval(5000L, sendSensor);
 timer.setInterval(60000L, sendAlert);
 

 
}

void loop()
{
 Blynk.run();
 timer.run();
}

Try this

Blynk.logEvent("HOTPUSH", "ESTO SE ESTA CALENTANDO,") ;

Blynk.notify, blynk.email, and blynk.sms had been replaced with blynk.logEvent

As @John93 has pointed-out, your event code (which is what should be used in the logEvent command I’d “HOTPUSH” not “hotpush” as you have used.

Also, you don’t have any code to prevent multiple events from being logged for the same over temperature event.
This will result in you quickly exceeding the limit of 100 events in a 24 hour period.
You should add a flag variable, and only log the event if the flag is false. You then set the flag to true, and only clear it back to false if your temperature drops below the threshold.

Pete.

Thanks @John93 and Pete… Pete, sorry but wouldn’t reception be limited by setting the Notifications Limit to the Limit Period? I want to configure this if a cold room that normally works at -40 or -20 reaches 0 degrees. In other words, it would only send notifications if something relatively bad happens. For the other I can use the Automations.

That will limit how frequently you receive notifications.
There is a limit of 100 events per 24 hour period for each device, so if you have the notification limit period set to 2 hours and send one event per minute you will receive the first notification, then after 100 minutes you will have reached your daily event limit.
Any future events will be rejected, so you’ll have to wait a further 24 hours before the next notification can be sent.

Hence my advice to only send one event per over temperature situation.

Feel free to ignore my advice if you wish.

Pete.

I just configured the code with capital letters and I still don’t receive notifications. I’ll see if I can find an example to see what I’m doing wrong. I have it online but I do not receive any notification.