#include <ArduinoJson.h>
const char* ssid = "fabito"; // SSID
const char* password = "68040329"; //contraseña de WiFi
int pinPhoto = 2;
int ledPhoto=5;
int garajePin = 4;
int status = 0;
int temp=0;
// void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
// switch(type) {
// case WStype_DISCONNECTED:
// Serial.printf("[WSc] Disconnected!\n");
// break;
// case WStype_CONNECTED:
// Serial.printf("[WSc] Connected to url: %s\n", payload);
// break;
// case WStype_TEXT:
// Serial.printf("[WSc] get text: %s\n", payload);
// // Aquí procesas el mensaje recibido para mover el servo
// DynamicJsonDocument doc(1024);
// deserializeJson(doc, payload);
// int pin = doc["pin"];
// int status = doc["status"];
// delay(1000);
// }
// }
void setup() {
pinMode(pinPhoto, INPUT);
pinMode(garajePin, INPUT);
// Espera conexión
// while (WiFi.status() != WL_CONNECTED) {
// delay(1000);
// Serial.println("Conectando a WiFi...");
// };
// Configuración de WebSocket
// webSocket.begin("192.168.20.9", 8000, "/ws/light/"); // Ajusta la IP y el endpoint
// webSocket.onEvent(webSocketEvent);
Serial.begin(9600);
}
void loop() {
int value = analogRead(pinPhoto);
temp = map(value, 180, 900, 0, 255);
temp = constrain(temp, 0, 255);
int currentGarageStatus = digitalRead(garajePin);
if (currentGarageStatus == HIGH && status == 0) {
status = 1;
}else if (currentGarageStatus == HIGH && status == 1){
status=0;
}
Serial.println(temp);
// StaticJsonDocument<200> doc;
// doc["type"] = "change_message";
// doc["light-value"] = temp;
// doc["garaje-status"] = status;
// String output;
// serializeJson(doc, output);
// webSocket.sendTXT(output);
// //Serial.println("Sent: " + output);
//webSocket.loop();
delay(100);
}