Skip to content

Instantly share code, notes, and snippets.

@ajangrahmat
Created January 29, 2023 13:56
Show Gist options
  • Save ajangrahmat/5f7e178ad1a15cfd028b756cd2c56a95 to your computer and use it in GitHub Desktop.
Save ajangrahmat/5f7e178ad1a15cfd028b756cd2c56a95 to your computer and use it in GitHub Desktop.
#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