samedi 14 avril 2018

ESP8266 IF Else Statement and Fauxmo

I programmed an ESP8266 with the Example sketch from Fauxmo, which let's me control the ESP8266 from Alexa by using my voice (turns it into a WEMO).

The example works fine and I am able to turn off and on the onboard LED light by talking to Alexa.

The problem I am having is that I added the ESP8266 HTTPClient Library, and an If, Else Statement which is not working correctly.

If I tell Alexa "Power One On", Alexa will then tell the ESP8266 to turn on the onboard LED light. I made an If/Else statement based on if Power One is ON or OFF. If it is on, I want the ESP8266 to call a webpage (HTTP.GET) to activate another smart device in my house, and if "Power One Off" I want the ESP8266 to call another webpage.

Everything seems to work except for the IF / Else statement, since it is not calling the webpage I listed in the code, and thus nothing other then the onboard LED is getting activated or deactivated.

Wondering if anyone could look over my IF ELse statement and see if there is anything wrong.

fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state) {
    Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
    digitalWrite(LED, !state);

    if( (strcmp(device_name, "Power One") == 0)){
      if(state){ 
        HTTPClient http;        
        http.begin("http://192.168.1.230/?2-on");
        http.GET();            
        http.end(); 
       // mySwitch.switchOn("xxx", "xxx");
        } else{
        HTTPClient http;        
        http.begin("http://192.168.1.230/?2-off");
        http.GET();            
        http.end(); 
        //mySwitch.switchOff("xxx", "xxx");
          }
      }//end of if

});

Entire Code:

http://textuploader.com/du2rx

Aucun commentaire:

Enregistrer un commentaire