Aircoookie/Espalexa

Espalexa and elegantOTA while running a ESP8266webserver? ESP is crashing.

Closed this issue · 2 comments

Is it possible to run a webserver, espalexa and elegantOTA all at the same time? I am attempting to do so, but the esp crashes and restarts when I try to access the OTA update page. The standard webserver works fine. So does alexa control. To complicate matters, I also am running a softAP so the user can set up the initial wifi credentials. Here are snipets of my code.

in globals

#include <Espalexa.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <DNSServer.h>
#include <ElegantOTA.h> //https://github.com/ayushsharma82/ElegantOTA

//callback functions for alexa
void deviceOneChanged(uint8_t brightness);
void deviceTwoChanged(uint8_t brightness);
Espalexa espalexa;

//pointers for alexa devices
EspalexaDevice* d1;
EspalexaDevice* d2;

ESP8266WiFiMulti wifiMulti;
ESP8266WebServer server(80);
DNSServer dnsServer;

in void setup()

//lots of other stuff going on, but here is the relevant pieces.

//setup softAP
  WiFi.softAP(ap_SSID, ap_Password);
  dnsServer.start(53, "Settings.com", WiFi.softAPIP());

//setup wifi
  WiFi.disconnect(true);
  wifiMulti.addAP(SSID1, PW1);
  wifiMulti.addAP(SSID2, PW2);

//Setup Alexa
  d1 = new EspalexaDevice(A_Click_Device, deviceOneChanged);
  d2 = new EspalexaDevice(B_Click_Device, deviceTwoChanged);
  espalexa.addDevice(d1);
  espalexa.addDevice(d2);


  server.on("/", handleRoot);
  server.onNotFound([]() {
    if (!espalexa.handleAlexaApiCall(server.uri(), server.arg(0))) {
      server.send(404, "text/plain", "Not found");
    }
  });


//start servers
    ElegantOTA.begin(&server);
    espalexa.begin(&server);

in void loop()

//again.  lots of other code, but here are the relevant snipets.

    dnsServer.processNextRequest();
    server.handleClient();
    espalexa.loop(); 

I believe the problem is that I am trying to start the espalexa.begin and ElegantOTA.begin with (&server). But I am really not sure. The OTA is supposed to have a server.begin() after the elegantOTA.begin(&server), but espalexa says to eliminate that and replace it with espalexa.begin(&server). Is there a way to combine the espalexa and elegantOTA begin commands with the webserver begin? Thank you.

Hi!

ElegantOTA.begin(&server);
espalexa.begin(&server);

should be correct. I'm sorry, I don't know why it doesn't work... You can try removing server.handleClient(); from your code as that is already called by espalexa.loop(), but it technically shouldn't make a difference.

It just seems to be an incompatibility with ElegantOTA. I'm using a different OTA method and all works well.