#include "WiFi.h"
const char* ssid = "Wokwi-GUEST";
const char* pass = "";
const char* host = "api.thingspeak.com";
const char* writeApiKey = "588FYHVWWF1YBU0L";
int temp;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
WiFi.begin(ssid,pass);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.print("CONNECTED!!!");
pinMode(2, OUTPUT);
pinMode(A0, INPUT);
}
void loop()
{
temp = analogRead(A0);
WiFiClient client;
const int http = 80;
if (!client.connect(host,http))
{
return;
}
if (temp >= 10)
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
Serial.println("Temp: ");
Serial.print(temp);
Serial.print("\n");
client.println(sendThing());
delay(15000);
}
String sendThing()
{
String command = String("GET ") +
"/update?key="+
writeApiKey+
"&field1="+
String(temp)+ "\r\n"+
"HTTP/1.1 200 OK\r\n"+
"Host: "+host+"\r\n"+
"Connection: close\r\n\r\n";
Serial.print(command);
return command;
}