kakopappa / arduino-esp8266-alexa-multiple-wemo-switch

multiple belkin wemos switch emulator using ESP8266
https://sinric.pro
MIT License
308 stars 196 forks source link

Alexa won't find more than 5 switches... #52

Open Ynot1 opened 6 years ago

Ynot1 commented 6 years ago

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?

EWdG commented 5 years ago

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?

santosh09142 commented 5 years ago

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.

EWdG commented 5 years ago

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

include

include

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; }

santosh09142 commented 5 years ago

Hi,

I tried your given code but this code also searched for 4 device not more then that. Is it possible for you to check ping request for your nodemcu is breaking or not while in discovery mode.

And one more thing when you add more device 6th device your nodemcu will reboot every after some time.

From: Egon notifications@github.com Sent: Friday, August 10, 2018 8:52 AM To: kakopappa/arduino-esp8266-alexa-multiple-wemo-switch arduino-esp8266-alexa-multiple-wemo-switch@noreply.github.com Cc: santosh09142 santosh09@gmail.com; Comment comment@noreply.github.com Subject: Re: [kakopappa/arduino-esp8266-alexa-multiple-wemo-switch] Alexa won't find more than 5 switches... (#52)

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

include

include

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; }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch/issues/52#issuecomment-411964004 , or mute the thread https://github.com/notifications/unsubscribe-auth/Aj_2zzQLecDjHbvge-V-lBzIZlfqqAJQks5uPPxcgaJpZM4VGkaX . https://github.com/notifications/beacon/Aj_2z4yBp2OALO0BvV4MfwdJZxfsaeikks5uPPxcgaJpZM4VGkaX.gif

EWdG commented 5 years ago

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 "https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch/issues/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?

Ynot1 commented 5 years ago

I found the same issue - discovery of new Alexa devices becomes more unreliable as more switches are added to the multiple-wemo code. 4 was my sweet spot. Might be a timing issue related to the small 45 sec or 1 minute period that Alexa spends searching for new devices - there is A LOT of traffic on the debug screen for most of that period with 4 switches enabled.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Egon notifications@github.com Sent: Sunday, August 12, 2018 1:11 PM To: kakopappa/arduino-esp8266-alexa-multiple-wemo-switch Cc: Ynot1; Author Subject: Re: [kakopappa/arduino-esp8266-alexa-multiple-wemo-switch] Alexa won't find more than 5 switches... (#52)

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 "#54https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch/issues/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?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch/issues/52#issuecomment-412311582, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AksU2oF9kaEwbbSwG3EjSmfcgUmo0nVKks5uP4CngaJpZM4VGkaX.