1#include <ThingSpeak.h>
2
3
8#include <DHT.h>
9#define DHTPIN 2
10#define DHTTYPE DHT22
11DHT dht(DHTPIN, DHTTYPE);
12#include <ESP8266WiFi.h>
13
14unsigned long myChannelNumber = 167319;
15const char * myWriteAPIKey = "XXXP9V86RWR7R9Y";
16
17const char* ssid = "XXXX ";
18const char* password = "XXXX";
19
20 WiFiClient client;
21
22
23WiFiServer server(80);
24
25void setup() {
26 Serial.begin(115200);
27 delay(10);
28 dht.begin();
29
30
31
32
33
34
35
36 Serial.println();
37 Serial.println();
38 Serial.print("Connecting to ");
39 Serial.println(ssid);
40
41 WiFi.begin(ssid, password);
42
43 while (WiFi.status() != WL_CONNECTED) {
44 delay(500);
45 Serial.print(".");
46 }
47 Serial.println("");
48 Serial.println("WiFi connected");
49
50
51
52
53
54
55
56
57 Serial.println(WiFi.localIP());
58
59ThingSpeak.begin(client);
60
61}
62
63void loop() {
64
65float h = dht.readHumidity();
66 float t = dht.readTemperature();
67
68 Serial.println("Humedad: ");
69 Serial.println(h);
70 Serial.println("Temperatura: ");
71 Serial.println(t);
72 delay(2000);
73
74
75ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey);
76 delay(20000);
77
78
79ThingSpeak.writeField(myChannelNumber, 2, t, myWriteAPIKey);
80 delay(20000);
81
82
83
84
85
86 }
87
88
89
90
91
92