#ifdef __cplusplus
extern "C" {
#endif
uint8_t temperature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temperature_sens_read();
#include <WiFi.h>
#include "DHT.h"
#include "ThingSpeak.h"
const char* ssid = "Wokwi-GUEST";
const char* password = "";
WiFiServer server(80);
WiFiClient client;
unsigned long myChannelNumber = 1 ;
const char * myWriteAPIKey = "HVRDE6ZZUPMOWHWX";
unsigned long lastTime = 0;
unsigned long timerDelay = 1000;
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup(){
Serial.begin(115200);
WiFi.begin(ssid,password);
while(WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
dht.begin();
ThingSpeak.begin(client);
}
void loop() {
if((millis()-lastTime) > timerDelay)
{
delay(2500);
float h= dht.readHumidity();
float t= dht.readTemperature();
float f= dht.readTemperature(true);
if(isnan(h) || isnan(t) || isnan(f)){
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print("Temperature(ºC):");
Serial.print(t);
Serial.print("Humidity(%):");
Serial.println(h);
ThingSpeak.setField(1,h);
ThingSpeak.setField(2,t);
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));
}
lastTime = millis();
}
}