#include <WiFi.h>
#include <ThingSpeak.h>
#define SECRET_SSID "Wokwi-GUEST"
#define SECRET_PASS""
#define SECRET_CH_ID 2483007
#define SECRET_WRITE_APIKEY"ICR6GFIPFCSUCJMV"
char ssid[]= SECRET_SSID;
char pass[]=SECRET_PASS;
int keyIndex=0;
WiFiClient client;
unsigned long myChannelNumber=SECRET_CH_ID;
const char * myWriteAPIKey= SECRET_WRITE_APIKEY;
int temppin=32;
float pinval;
float temp=0.00;
void setup()
{
pinMode(temppin,INPUT);
Serial.begin(115200);
if(WiFi.status()!=WL_CONNECTED)
Serial.print("attempting to connect to SSID: ");
Serial.println("SECRET_SSID);
while(WiFi.status()!=WL_CONNECTED)
{
WiFi.begin(ssid,pass);
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
while(!Serial){
}
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop()
{
pinval=analogRead(temppin);
temp=pinval*(0.122);
Serial.println(temp);
int x=ThingSpeak.writeField(myChannelNumber,1,temp,myWriteAPIKey);
if(x==20)
{
Serial.println("channel update succesful.");
}
else
{
Serial.println("problem updating channel.HTTP error code+ String(x)");
}
delay(1000);
}