0% found this document useful (0 votes)
4 views1 page

LAB3 ThingSpeak

Uploaded by

bautroidem100702
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

LAB3 ThingSpeak

Uploaded by

bautroidem100702
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <WiFi.

h>
#include "ThingSpeak.h"
#include "DHTesp.h"
#define DHT_PIN 15
const char* WIFI_SSID = "Wokwi-GUEST";
const char* WIFI_PASSWORD = "";
WiFiClient client;
#define SECRET_CH_ID 2111762
#define SECRET_WRITE_APIKEY "OKZBIJQP99A7CL9Z"
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
int Temperature;
int Humidity;
DHTesp dhtSensor;
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
dhtSensor.getPin();
delay(10);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop() {
Temperature = dhtSensor.getTemperature();
Humidity = dhtSensor.getHumidity();
Serial.print("Nhiet do: ");
Serial.print(Temperature);
Serial.print("*C ");
Serial.print("Do am: ");
Serial.print(Humidity);
Serial.println("% ");
ThingSpeak.setField(1, Temperature);
ThingSpeak.setField(2, Humidity);
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));
}
delay(1000);
}
https://wokwi.com/projects/366076593053778945

You might also like