#include <WiFi.h>
#include <HTTPClient.h>
char ssid[] = "Wokwi-GUEST";//Enter your WIFI name
char pass[] = "";
const char* host="webpercobaan.my.id";
const int adc = 34;
int pwm;
#define x 2 // d1
/*#define pinn 4 //d2*/
float volt;
void setup()
{
Serial.begin(9600);
WiFi.begin(ssid,pass);
while(WiFi.status()!=WL_CONNECTED)
{Serial.print('.');delay(500);}
Serial.print("Berhasil Konek");
pinMode(x, OUTPUT);
/*pinMode(pinn, OUTPUT);
digitalWrite(x, LOW);*/
}
void loop()
{
volt=analogRead(34);
pwm=(volt*5/4095)*51;
WiFiClient client;
const int httpPort=80;
if(!client.connect(host, httpPort))
{
Serial.println("Gagal Koneksi Ke Server");
return;
}
Serial.println("Berhasil Koneksi Ke Server");
//baca status relay1
HTTPClient httpRelay1;
httpRelay1.begin("http://webpercobaan.my.id/bacarelay1.php");
int responkode=httpRelay1.GET();
//Serial.println(responkode);
String responseRelay1=httpRelay1.getString();
Serial.println(responseRelay1);
httpRelay1.end();
digitalWrite(x, responseRelay1.toInt());
HTTPClient http;
http.begin("http://webpercobaan.my.id/kirim.php?volt=" + String(volt));
http.GET();
Serial.println(pwm);
http.end();
}