#include <WiFi.h>
#include <HTTPClient.h>
//Puertos GPIO
int boton=33;
int led=32;
//Variables status
int status_boton=0;
//PHP Server
String url="https://000f5e11-d259-494d-84dd-0234e0655492-00-3idcw9csekrsh.kirk.replit.dev/?"; //Server URL
String sensor="DATO";
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);// Configurar puerto 2 como salida
pinMode(boton, INPUT); //Configurar puerto 4 como entrada
delay(1000);
Serial.begin(115200);
//Conect to wifi network
WiFi.begin("Wokwi-GUEST", ""); //Wifi_Network, Wifi_Password ******CHANGE
//Wait until connection
while((WiFi.status() != WL_CONNECTED)) {
delay(500);
Serial.print(".");
}
Serial.println("Wifi conected");
}
void loop() {
// put your main code here, to run repeatedly:
status_boton=digitalRead(boton);
if(status_boton==1){
digitalWrite(led,HIGH);
}
else{
digitalWrite(led,LOW);
}
// wait for WiFi connection
if((WiFi.status() == WL_CONNECTED)) {
// start connection and send HTTP header, return error code
HTTPClient http;
//Ejemplo: https://000f5e11-d259-494d-84dd-0234e0655492-00-3idcw9csekrsh.kirk.replit.dev/?DATO=22
String message=url+sensor+"="+String(status_boton);
http.begin(message); //HTTP
int httpCode = http.GET();
Serial.println(message);
Serial.print("GET code:");
Serial.println(httpCode);
http.end();
}
delay(3000);
}