Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit d755ba0

Browse files
authored
Add files via upload
1 parent c2c4486 commit d755ba0

File tree

5 files changed

+337
-14
lines changed

5 files changed

+337
-14
lines changed

examples/DHT11ESP32/DHT11ESP32.ino

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#define BLYNK_PRINT Serial
2+
3+
#include <BlynkSimpleEsp32_WM.h>
4+
#include <Ticker.h>
5+
#include <DHT.h>
6+
7+
#define PIN_D22 22 // Pin D22 mapped to pin GPIO22/SCL of ESP32
8+
9+
#define DHT_PIN PIN_D22 // pin DATA @ D22 / GPIO22
10+
#define DHT_TYPE DHT11
11+
12+
#define DHT_DEBUG 1
13+
14+
DHT dht(DHT_PIN, DHT_TYPE);
15+
BlynkTimer timer;
16+
Ticker led_ticker;
17+
18+
void readAndSendData()
19+
{
20+
float temperature = dht.readTemperature();
21+
float humidity = dht.readHumidity();
22+
23+
24+
if (!isnan(temperature) && !isnan(humidity))
25+
{
26+
Blynk.virtualWrite(V17, temperature);
27+
Blynk.virtualWrite(V18, humidity);
28+
}
29+
else
30+
{
31+
Blynk.virtualWrite(V17, -100);
32+
Blynk.virtualWrite(V18, -100);
33+
}
34+
}
35+
36+
void set_led(byte status)
37+
{
38+
digitalWrite(LED_BUILTIN, status);
39+
}
40+
41+
void check_status()
42+
{
43+
static unsigned long checkstatus_timeout = 0;
44+
45+
#define STATUS_CHECK_INTERVAL 15000L
46+
47+
// Send status report every STATUS_REPORT_INTERVAL (10) seconds: we don't need to send updates frequently if there is no status change.
48+
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
49+
{
50+
// report status to Blynk
51+
if (Blynk.connected())
52+
{
53+
set_led(LOW);
54+
led_ticker.once_ms(111, set_led, (byte) HIGH);
55+
56+
Serial.println("B");
57+
}
58+
else
59+
{
60+
Serial.println("F");
61+
}
62+
63+
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
64+
}
65+
}
66+
67+
void setup()
68+
{
69+
// Debug console
70+
Serial.begin(115200);
71+
pinMode(LED_BUILTIN, OUTPUT);
72+
73+
Serial.println("\nStarting ...");
74+
75+
dht.begin();
76+
Blynk.begin();
77+
timer.setInterval(60 * 1000, readAndSendData);
78+
79+
if (Blynk.connected())
80+
{
81+
Serial.println("\nBlynk ESP32 connected. Board Name : " + Blynk.getBoardName());
82+
}
83+
}
84+
85+
void loop()
86+
{
87+
Blynk.run();
88+
timer.run();
89+
check_status();
90+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#define BLYNK_PRINT Serial
2+
3+
#include <BlynkSimpleEsp32_SSL_WM.h>
4+
#include <Ticker.h>
5+
#include <DHT.h>
6+
7+
#define PIN_D22 22 // Pin D22 mapped to pin GPIO22/SCL of ESP32
8+
9+
#define DHT_PIN PIN_D22 // pin DATA @ D22 / GPIO22
10+
#define DHT_TYPE DHT11
11+
12+
#define DHT_DEBUG 1
13+
14+
DHT dht(DHT_PIN, DHT_TYPE);
15+
BlynkTimer timer;
16+
Ticker led_ticker;
17+
18+
void readAndSendData()
19+
{
20+
float temperature = dht.readTemperature();
21+
float humidity = dht.readHumidity();
22+
23+
24+
if (!isnan(temperature) && !isnan(humidity))
25+
{
26+
Blynk.virtualWrite(V17, temperature);
27+
Blynk.virtualWrite(V18, humidity);
28+
}
29+
else
30+
{
31+
Blynk.virtualWrite(V17, -100);
32+
Blynk.virtualWrite(V18, -100);
33+
}
34+
}
35+
36+
void set_led(byte status)
37+
{
38+
digitalWrite(LED_BUILTIN, status);
39+
}
40+
41+
void check_status()
42+
{
43+
static unsigned long checkstatus_timeout = 0;
44+
45+
#define STATUS_CHECK_INTERVAL 15000L
46+
47+
// Send status report every STATUS_REPORT_INTERVAL (10) seconds: we don't need to send updates frequently if there is no status change.
48+
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
49+
{
50+
// report status to Blynk
51+
if (Blynk.connected())
52+
{
53+
set_led(HIGH);
54+
led_ticker.once_ms(111, set_led, (byte) LOW);
55+
56+
Serial.println("B");
57+
}
58+
else
59+
{
60+
Serial.println("F");
61+
}
62+
63+
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
64+
}
65+
}
66+
67+
void setup()
68+
{
69+
// Debug console
70+
Serial.begin(115200);
71+
pinMode(LED_BUILTIN, OUTPUT);
72+
73+
Serial.println("\nStarting ...");
74+
75+
dht.begin();
76+
Blynk.begin();
77+
timer.setInterval(60 * 1000, readAndSendData);
78+
79+
if (Blynk.connected())
80+
{
81+
Serial.println("\nBlynk ESP32 SSL connected. Board Name : " + Blynk.getBoardName());
82+
}
83+
}
84+
85+
void loop()
86+
{
87+
Blynk.run();
88+
timer.run();
89+
check_status();
90+
}
Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,88 @@
11
#include <BlynkSimpleEsp8266_WM.h>
2+
#include <Ticker.h>
23
#include <DHT.h>
34

4-
#define DHT_PIN 2
5+
#define PIN_LED 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
6+
#define PIN_D2 4 // Pin D2 mapped to pin GPIO4 of ESP8266
7+
8+
#define DHT_PIN PIN_D2
59
#define DHT_TYPE DHT11
610

711
#define DHT_DEBUG 1
812

913
DHT dht(DHT_PIN, DHT_TYPE);
1014
BlynkTimer timer;
15+
Ticker led_ticker;
1116

1217
void readAndSendData()
1318
{
1419
float temperature = dht.readTemperature();
1520
float humidity = dht.readHumidity();
1621

17-
1822
if (!isnan(temperature) && !isnan(humidity))
1923
{
20-
Blynk.virtualWrite(V0, temperature);
21-
Blynk.virtualWrite(V1, humidity);
24+
Blynk.virtualWrite(V17, temperature);
25+
Blynk.virtualWrite(V18, humidity);
2226
}
2327
else
2428
{
25-
Blynk.virtualWrite(V0, -100);
26-
Blynk.virtualWrite(V1, -100);
29+
Blynk.virtualWrite(V17, -100);
30+
Blynk.virtualWrite(V18, -100);
2731
}
2832
}
2933

34+
void set_led(byte status)
35+
{
36+
digitalWrite(PIN_LED, status);
37+
}
38+
39+
void check_status()
40+
{
41+
static unsigned long checkstatus_timeout = 0;
42+
43+
#define STATUS_CHECK_INTERVAL 15000L
44+
45+
// Send status report every STATUS_REPORT_INTERVAL (10) seconds: we don't need to send updates frequently if there is no status change.
46+
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
47+
{
48+
// report status to Blynk
49+
if (Blynk.connected())
50+
{
51+
set_led(LOW);
52+
led_ticker.once_ms(111, set_led, (byte) HIGH);
53+
54+
Serial.println("B");
55+
}
56+
else
57+
{
58+
Serial.println("F");
59+
}
60+
61+
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
62+
}
63+
}
64+
3065
void setup()
3166
{
67+
// Debug console
68+
Serial.begin(115200);
69+
pinMode(PIN_LED, OUTPUT);
70+
71+
Serial.println("\nStarting ...");
72+
3273
dht.begin();
3374
Blynk.begin();
3475
timer.setInterval(60 * 1000, readAndSendData);
76+
77+
if (Blynk.connected())
78+
{
79+
Serial.println("\nBlynk connected. Board Name : " + Blynk.getBoardName());
80+
}
3581
}
3682

3783
void loop()
3884
{
3985
Blynk.run();
4086
timer.run();
87+
check_status();
4188
}

examples/DHT11ESP8266_Debug/DHT11ESP8266_Debug.ino

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
#include <Ticker.h>
55
#include <DHT.h>
66

7-
#define DHT_PIN 2
7+
#define PIN_LED 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
8+
#define PIN_D2 4 // Pin D2 mapped to pin GPIO4 of ESP8266
9+
10+
#define DHT_PIN PIN_D2
811
#define DHT_TYPE DHT11
912

1013
#define DHT_DEBUG 1
1114

1215
DHT dht(DHT_PIN, DHT_TYPE);
1316
BlynkTimer timer;
14-
Ticker aux_ticker;
17+
Ticker led_ticker;
1518

1619
void readAndSendData()
1720
{
@@ -31,12 +34,10 @@ void readAndSendData()
3134
}
3235
}
3336

34-
#define PIN_LED 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
35-
3637
void set_led(byte status)
3738
{
38-
digitalWrite(PIN_LED /*LED_BUILTIN*/, status);
39-
}
39+
digitalWrite(PIN_LED, status);
40+
}
4041

4142
void check_status()
4243
{
@@ -51,7 +52,7 @@ void check_status()
5152
if (Blynk.connected())
5253
{
5354
set_led(LOW);
54-
aux_ticker.once_ms(111, set_led, (byte) HIGH);
55+
led_ticker.once_ms(111, set_led, (byte) HIGH);
5556

5657
Serial.println("B");
5758
}
@@ -68,13 +69,17 @@ void setup()
6869
{
6970
// Debug console
7071
Serial.begin(115200);
72+
pinMode(PIN_LED, OUTPUT);
73+
74+
Serial.println("\nStarting ...");
75+
7176
dht.begin();
7277
Blynk.begin();
7378
timer.setInterval(60 * 1000, readAndSendData);
7479

7580
if (Blynk.connected())
7681
{
77-
Serial.println("Blynk connected. Board Name : " + Blynk.getBoardName());
82+
Serial.println("\nBlynk ESP8288 connected. Board Name : " + Blynk.getBoardName());
7883
}
7984
}
8085

0 commit comments

Comments
 (0)