Alexa won't find more than 5 switches...
Ynot1 opened this issue · 6 comments
If I define more than 5 switches, Alexa randomly fails to discover some of them. All the switches I have defined work fine idenpendanty, but discovery of all of them is a problem. The code says "max 10" - what limit is this, and have I hit it early?
I came across the same problem.
From the sixth switch Alexa will not find a new device. Also, Alexa does not find a previously known switch when asked to "switch one on".
Has anyone defined more than 5 switches successfully? If so, how?
I am also struggling for same, If any one have solution please help us. I am giving less preference to Sinric as i dont want to control power from internet(security reason)
I have seen after adding 5+ switches script start crashing(reboot nodemcu) and in VS 2017 i seen error stating some code trying to access cpu private info(in nodemcu). If you want i can share error.
Here is my sketch, which works at least up to 5 switches.
At the 6th switch (Vf) nothing works.
Maybe someone finds an error in the sketch?
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include
#include "switch.h"
#include "UpnpBroadcastResponder.h"
#include "CallbackFunction.h"
// prototypes
boolean connectWifi();
//on/off callbacks
bool VaOn();
bool VaOff();
bool VbOn();
bool VbOff();
bool VcOn();
bool VcOff();
bool VdOn();
bool VdOff();
bool VeOn();
bool VeOff();
bool VfOn();
bool VfOff();
// Change this before you flash
const char* ssid = "xxxxxxxx";
const char* password = "yyyyyyyyy";
const int relayPin1 = 5; // D1 Pin
const int relayPin2 = 4; // D2 Pin
const int relayPin3 = 0; // D3 Pin
const int relayPin4 = 2; // D4 Pin
const int relayPin5 = 14; // D5 Pin
const int relayPin6 = 12; // D6 Pin
boolean wifiConnected = false;
UpnpBroadcastResponder upnpBroadcastResponder;
Switch *Va = NULL;
Switch *Vb = NULL;
Switch *Vc = NULL;
Switch *Vd = NULL;
Switch *Ve = NULL;
Switch *Vf = NULL;
bool isVaOn = false;
bool isVbOn = false;
bool isVcOn = false;
bool isVdOn = false;
bool isVeOn = false;
bool isVfOn = false;
void setup()
{
Serial.begin(9600);
// Setup Relay
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT);
pinMode(relayPin5, OUTPUT);
pinMode(relayPin6, OUTPUT);
// Initialise wifi connection
wifiConnected = connectWifi();
if (wifiConnected) {
upnpBroadcastResponder.beginUdpMulticast();
// Define your switches here. Max 10
Va = new Switch("eins", 80, VaOn, VaOff);
Vb = new Switch("zwei", 81, VbOn, VbOff);
Vc = new Switch("drei", 82, VcOn, VcOff);
Vd = new Switch("vier", 83, VdOn, VdOff);
Ve = new Switch("fünf", 84, VeOn, VeOff);
Vf = new Switch("sechs", 85, VfOn, VfOff);
Serial.println("Adding switches upnp broadcast responder");
upnpBroadcastResponder.addDevice(*Va);
upnpBroadcastResponder.addDevice(*Vb);
upnpBroadcastResponder.addDevice(*Vc);
upnpBroadcastResponder.addDevice(*Vd);
upnpBroadcastResponder.addDevice(*Ve);
upnpBroadcastResponder.addDevice(*Vf);
}
// 18.07.2018 Erweiterung durch Egon - Urzustand herstellen.
digitalWrite(relayPin1, LOW); // turn off relay with voltage LOW
digitalWrite(relayPin2, LOW); // turn off relay with voltage LOW
digitalWrite(relayPin3, LOW); // turn off relay with voltage LOW
digitalWrite(relayPin4, LOW); // turn off relay with voltage LOW
digitalWrite(relayPin5, LOW); // turn off relay with voltage LOW
digitalWrite(relayPin6, LOW); // turn off relay with voltage LOW
}
void loop()
{
if (wifiConnected) {
upnpBroadcastResponder.serverLoop();
Va->serverLoop();
Vb->serverLoop();
Vc->serverLoop();
Vd->serverLoop();
Ve->serverLoop();
Vf->serverLoop();
}
}
bool VaOn() {
Serial.println("Switch 1 turn on ...");
digitalWrite(relayPin1, HIGH); // turn on relay with voltage HIGH
isVaOn = true;
return isVaOn;
}
bool VaOff() {
Serial.println("Switch 1 turn off ...");
digitalWrite(relayPin1, LOW); // turn off relay with voltage LOW
isVaOn = false;
return isVaOn;
}
bool VbOn() {
Serial.println("Switch 2 turn on ...");
digitalWrite(relayPin2, HIGH); // turn on relay with voltage HIGH
isVbOn = true;
return isVbOn;
}
bool VbOff() {
Serial.println("Switch 2 turn off ...");
digitalWrite(relayPin2, LOW); // turn off relay with voltage LOW
isVbOn = false;
return isVbOn;
}
bool VcOn() {
Serial.println("Switch 3 turn on ...");
digitalWrite(relayPin3, HIGH); // turn on relay with voltage HIGH
isVcOn = true;
return isVcOn;
}
bool VcOff() {
Serial.println("Switch 3 turn off ...");
digitalWrite(relayPin3, LOW); // turn off relay with voltage LOW
isVcOn = false;
return isVcOn;
}
bool VdOn() {
Serial.println("Switch 4 turn on ...");
digitalWrite(relayPin4, HIGH); // turn on relay with voltage HIGH
isVdOn = true;
return isVdOn;
}
bool VdOff() {
Serial.println("Switch 4 turn off ...");
digitalWrite(relayPin4, LOW); // turn off relay with voltage LOW
isVdOn = false;
return isVdOn;
}
bool VeOn() {
Serial.println("Switch 5 turn on ...");
digitalWrite(relayPin5, HIGH); // turn on relay with voltage HIGH
isVeOn = true;
return isVeOn;
}
bool VeOff() {
Serial.println("Switch 5 turn off ...");
digitalWrite(relayPin5, LOW); // turn off relay with voltage LOW
isVeOn = false;
return isVeOn;
}
bool VfOn() {
Serial.println("Switch 6 turn on ...");
digitalWrite(relayPin6, HIGH); // turn on relay with voltage HIGH
isVfOn = true;
return isVfOn;
}
bool VfOff() {
Serial.println("Switch 6 turn off ...");
digitalWrite(relayPin6, LOW); // turn off relay with voltage LOW
isVfOn = false;
return isVfOn;
}
// connect to wifi – returns true if successful or false if not
boolean connectWifi() {
boolean state = true;
int i = 0;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting ...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 10) {
state = false;
break;
}
i++;
}
if (state) {
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
The basis of this sketch is the code of kakopappa "https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch".
I only expanded it by defining the outputs. In the above sketch, if all lines addressing the sixth output "Vf" are cleared, the 5-output sketch runs very reliably.
It may be that Alexa does not recognize all 5 outputs at the first scan. However, a second search leads to the desired result and all 5 switches have been found.
I suspect the bug that no more than 5 switches work flawlessly, somewhere in kakopappa's programs. I think we have to wait until the programmer has time to take care of the matter. He indicated this on 18 July 2018 at "#54".
santosh09142: I understand you so much that you did not get more than 5 switches to run. Why do you suppose that from the sixth switch, the modemcu would always reboot after a while?