alanswx / ESPAsyncWiFiManager

Port WiFiManager to ESP Async Server
MIT License
222 stars 85 forks source link

not compatible with Alexa? #74

Open PauloFDO opened 3 years ago

PauloFDO commented 3 years ago

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!");
 }
}