Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not compatible with Alexa? #74

Open
PauloFDO opened this issue Jan 9, 2021 · 0 comments
Open

not compatible with Alexa? #74

PauloFDO opened this issue Jan 9, 2021 · 0 comments

Comments

@PauloFDO
Copy link

PauloFDO commented Jan 9, 2021

so far I have been using another wifi library, but I really don't want to hardcode my password, the problem is that as soon as I use this library to stablish connection Alexa cannot find the connected devices, I can clearly see my esp8266 connected to my router, how can I solve this problem? I tried with different examples and all has the same outcome, is there something in particular that I should be looking for?

this is the last one that I tried (just a copy and paste of one of the examples), all seems to be working as expected but for Alexa not finding the device at all

#include <Arduino.h>
#include <fauxmoESP.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#else
#include <WiFi.h>
#endif

//needed for library
#include <ESPAsyncWebServer.h>
#include <ESPAsyncWiFiManager.h>    


DNSServer dnsServer;
AsyncWebServer server(80);

fauxmoESP fauxmo;
bool MoveCommand = false;

void setup() {
  Serial.begin(115200);
  WifiSetup();
  AlexaSetup();
}

class CaptiveRequestHandler : public AsyncWebHandler {
public:
  CaptiveRequestHandler() {}
  virtual ~CaptiveRequestHandler() {}

  bool canHandle(AsyncWebServerRequest *request){
    //request->addInterestingHeader("ANY");
    return true;
  }

  void handleRequest(AsyncWebServerRequest *request) {
    AsyncResponseStream *response = request->beginResponseStream("text/html");
    response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
    response->print("<p>This is out captive portal front page.</p>");
    response->printf("<p>You were trying to reach: http://%s%s</p>", request->host().c_str(), request->url().c_str());
    response->printf("<p>Try opening <a href='http://%s'>this link</a> instead</p>", WiFi.softAPIP().toString().c_str());
    response->print("</body></html>");
    request->send(response);
  }
};

void AlexaSetup(){
  
  fauxmo.addDevice("motor on");
    fauxmo.setPort(80); // required for gen3 devices
    fauxmo.enable(true);
    

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
    Serial.println("alexa can hear you");
        MoveCommand = true;
    });
    
      Serial.println("alexa device setup complete");
}

void WifiSetup(){
   WiFi.softAP("esp-captive");
  dnsServer.start(53, "*", WiFi.softAPIP());
  server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);//only when requested from AP
  //more handlers...
  server.begin();
}

void loop() {
 fauxmo.handle();

 if(MoveCommand){
  Serial.println("completed!");
 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant