Created
January 29, 2023 13:56
-
-
Save ajangrahmat/5f7e178ad1a15cfd028b756cd2c56a95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<WiFi.h> | |
#include <HTTPClient.h> | |
const char* ssid = "Wokwi-GUEST"; | |
const char* pass = ""; | |
unsigned const long interval = 2000; | |
unsigned long zero = 0; | |
void setup(){ | |
Serial.begin(115200); | |
WiFi.begin(ssid, pass); | |
while(WiFi.status() != WL_CONNECTED){ | |
delay(100); | |
Serial.println("."); | |
} | |
Serial.println("WiFi Connected!"); | |
Serial.println(WiFi.localIP()); | |
} | |
void loop(){ | |
if(millis()-zero > interval){ | |
HTTPClient http; | |
http.begin("http://jsonplaceholder.typicode.com/todos/1"); | |
int httpResponCode = http.GET(); | |
Serial.println(httpResponCode); | |
if(httpResponCode > 0){ | |
String payload = http.getString(); | |
Serial.print(payload); | |
}else{ | |
Serial.print("error "); | |
Serial.println(httpResponCode); | |
} | |
zero = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment