#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
#include <WiFi.h>
#include <DHT.h>
#include <ThingSpeak.h>
char* ssid = "Wokwi-GUEST";
char* password = "";
WifiServer server(80);
WifiClient client;
unsigned long myChannelNumber = 3;
const char * myWriteAPIKey = "EJ4W92QK7TTA3DF1";
unsigned long lastTime = 0;
unsigned long timerDelay = 1000;
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(ssid);
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() {
((millis() - lastTime) > timerDelay)
{
delay(2500);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
isnan(h) || isnan(t) || isnan(f)
{
Serial.println(F("Failed to read from DHT sensor! "));
return;
}
Serial.print("Temperature (C): ");
Serial.print(t);
Serial.println("C");
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();
}
// put your main code here, to run repeatedly:
// this speeds up the simulation
}