#include <WiFi.h>
#include <HTTPClient.h>
//Puertos GPIO
int boton=33;
int led=32;
//Variables status
int status_boton=0;
//PHP sever
String url="https://ca5a5cb3-9ad8-44c8-aa7e-5ad18fc8baf1-00-1xjqy1et84q7y.kirk.replit.dev/sensor1/?"; //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 mensaje: https://ca5a5cb3-9ad8-44c8-aa7e-5ad18fc8baf1-00-1xjqy1et84q7y.kirk.replit.dev/sensor1/?DATO=1
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(1000);
}