#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
int relay1 = 2;
String serverName = "https://monkey-content-fawn.ngrok-free.app";
String device_id = "75c597dd-70c1-11ef-8380-30894ab97e9a";
int pos_air = 0;
String sensorReadings;
void setup() {
pinMode(relay1, OUTPUT);
Serial.begin(115200);
WiFi.begin("Wokwi-GUEST", "", 6);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(WiFi.localIP());
Serial.println(" Connected!");
}
void loop() {
Serial.println(WiFi.status() == WL_CONNECTED);
Serial.println(WiFi.status(), WL_CONNECTED);
if(WiFi.status()== WL_CONNECTED){
//sensorReadings = httpGETRequest(serverName + "/device/get_status?device_id=" + device_id);
//JSONVar myObject = JSON.parse(sensorReadings);
//if (JSON.typeof(myObject) == "undefined") {
//Serial.println("Parsing input failed!");
//return;
//}
//Serial.print("JSON object = ");
//Serial.println(myObject);
getData();
}
delay(10); // this speeds up the simulation
}
void getData(){
WiFiClient client;
HTTPClient http;
http.begin(client, serverName + "/device/get_status?device_id=" + device_id);
http.GET();
Serial.print(http.getString());
http.end();
}
String httpGETRequest(String serverName) {
WiFiClient client;
HTTPClient http;
http.begin(client, serverName);
int httpResponseCode = http.GET();
String payload = "{}";
Serial.println(httpResponseCode);
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
return payload;
}