Louie NRT Story

[Node MCU ESP8266] Monitoring DHT11 via thingspeak 본문

에너지

[Node MCU ESP8266] Monitoring DHT11 via thingspeak

hyeok0724.kim@gmail.com 2019. 12. 24. 14:53
반응형

Writed 24 DEC 2019

Why I am posting blog at work on Christmas Adam.

 

1. System DiagramESP8266 and DHT11 Schematic Diagram

출처: https://randomnerdtutorials.com/esp8266-dht11dht22-temperature-and-humidity-web-server-with-arduino-ide/

2. Login 

https://thingspeak.com/

 

IoT Analytics - ThingSpeak Internet of Things

Weather Station This project shows how to build an Arduino-based weather station that sends data to ThingSpeak. Once the data is collected, MATLAB is used to view trends of the data, plot histograms of the data, calculate dew point from the raw temperature

thingspeak.com

3. Make My Channel

4. Input Text

 - There are many options with help next to them

5. Change charing setting from private to public

6. Install Library

 

7. Save as Open Example Code

 - To avoid library issues

 

8. Input your infomation

 - You can find Channel ID and Write_APIkey on API Keys tap

9. Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "DHT.h"
#include "ThingSpeak.h"
#include "secrets.h"
#include <ESP8266WiFi.h>
 
#define DHTPIN 5     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11   // DHT 11
 
DHT dht(DHTPIN, DHTTYPE);
 
char ssid[] = SECRET_SSID;   // your network SSID (name) 
char pass[] = SECRET_PASS;   // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)
WiFiClient  client;
 
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
 
int number = 0;
 
void setup() {
  Serial.begin(115200);  // Initialize serial
 
  ThingSpeak.begin(client);  // Initialize ThingSpeak
  
  dht.begin();
}
 
void loop() {
 
  // Connect or reconnect to WiFi
  if(WiFi.status() != WL_CONNECTED){
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(SECRET_SSID);
    while(WiFi.status() != WL_CONNECTED){
      WiFi.begin(ssid, pass);  // Connect to WPA/WPA2 network. Change this line if using open or WEP network
      Serial.print(".");
      delay(5000);     
    } 
    Serial.println("\nConnected.");
  }
 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
 
  ThingSpeak.setField(1, t);
  ThingSpeak.setField(2, h);
  
  // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
  // pieces of information in a channel.  Here, we write to field 1.
  int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  if(x == 200){
    Serial.println("Channel update successful.");
  }
  else{
    Serial.println("Problem updating channel. HTTP error code " + String(x));
  }
 
  Serial.print(F("Humidity: "));
  Serial.print(F("%  Temperature: "));
  Serial.println(F("°C "));
 
  delay(20000); // Wait 20 seconds to update the channel again
}
 
 

 

10. Result

 

Reference

- https://randomnerdtutorials.com/esp8266-dht11dht22-temperature-and-humidity-web-server-with-arduino-ide/

반응형

'에너지' 카테고리의 다른 글

[나인와트] 2019 Incheon Civic Hack-Fair  (0) 2020.01.05
[기본상식] App 만드는 방법  (0) 2019.12.26
[Node MCU ESP8266] LED On/Off via thinger.io  (0) 2019.12.20
[Arduino UNO] DHT11  (0) 2019.12.17
[NodeMCU ESP 8266] DHT11  (0) 2019.12.16
Comments