Alexa y fauxmo.h

Buenos dias.
Estoy utilizando esta libreria para acceder a un esp-01 con rele desde alexa.
Se conecta y se ven pero el problema viene cuando le doy instrucciones de apagarse y de encenderse lo hace al reves:
"Alexa, enciende fuente" dice ok y no hace nada
"Alexa, apaga fuente" dice ok y activa el rele.
No sé si es un problema del programa o es un problema de hardware.

Adjunto el programa por si hay que hacer alguna modificacion:

#include <Arduino.h>
#ifdef ESP32
    #include <WiFi.h>
#else
    #include <ESP8266WiFi.h>
#endif
#include "fauxmoESP.h"

/
#define WIFI_SSID "*****"
#define WIFI_PASS "*****"    

fauxmoESP fauxmo;
#define SERIAL_BAUDRATE     115200
#define LED_YELLOW         0 //16 // 4
#define LED_GREEN           5
// #define LED_BLUE            0
#define LED_PINK            2
#define LED_WHITE           15

#define ID_YELLOW           "Fuente"
/*
#define ID_GREEN            "P2"
#define ID_BLUE             "R3"
#define ID_PINK             "R4"
#define ID_WHITE            "R5"
*/

void wifiSetup() {

    // Set WIFI module to STA mode
    WiFi.mode(WIFI_STA);

    // Connect
    Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
    WiFi.begin(WIFI_SSID, WIFI_PASS);

    // Wait
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(100);
    }
    Serial.println();

    // Connected!
    Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());

}

void setup() {

    // Init serial port and clean garbage
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println();
    Serial.println();

    // LEDs
    pinMode(LED_YELLOW, OUTPUT); 
    digitalWrite(LED_YELLOW, HIGH);    
    // Wifi
    wifiSetup();    
    fauxmo.createServer(true); // not needed, this is the default value
    fauxmo.setPort(80); // This is required for gen3 devices
    fauxmo.enable(true);
      
    fauxmo.addDevice(ID_YELLOW);
    
    fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {      
      
        Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);

        if (strcmp(device_name, ID_YELLOW)==0) {
            digitalWrite(LED_YELLOW, state ? HIGH : LOW);
        };
    });
  fauxmo.setState(ID_YELLOW, true, 255);
}

void loop() {

    fauxmo.handle();
    static unsigned long last = millis();
    if (millis() - last > 5000) {
        last = millis();
        Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
    }
}

Gracias y un saludo.
Javier

No me queda claro dónde está conectado el relé, si es en LED_YELLOW prueba cambiando

        if (strcmp(device_name, ID_YELLOW)==0) {
            digitalWrite(LED_YELLOW, state ? HIGH : LOW);
        };

por

        if (strcmp(device_name, ID_YELLOW)==0) {
            digitalWrite(LED_YELLOW, state ? LOW : HIGH);
        };

a ver si resulta.

Saludos

Estupendo, muchas gracias por tu ayuda. Funciona.

Un saludo,
Javier

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.