biddster / node-red-contrib-wemo-emulator

Why might you want to emulate Wemo? Well I wanted to be able to control my Node-RED Raspberry Pi using my Amazon Echo. The Echo has Wemo support built in so I thought I'd give it a try.
17 stars 9 forks source link

Cant see more than 11 devices #8

Closed JontWeightman closed 4 years ago

JontWeightman commented 7 years ago

Hi, I have set up 14 wemo emulator nodes all with different ports and ID's but only 11 are showing up on Alexa - any ideas ?

Thanks

biddster commented 7 years ago

I'm assuming you've repeatedly told Alexa to scan. Took a few scans for alexa to see all of my devices.

I'm not sure that the number is the issue, I have 9 configured at the moment and they're 100% reliable.

mikebiddell commented 7 years ago

I think the ports probably need to be contiguous

Toshibass commented 7 years ago

I have 15 wemo emulator nodes setup all found by Alexa and all work 100% the ports are not continuous meaning I started at port 55555 with ID 001 through to port 55565 with ID 011 then there's a gap were I intend to add more nodes, I start again at port 55577 with ID 023 through to port 55580 ID 026 I did have to ask Alexa twice to scan before they were all picked up.

mikebiddell commented 7 years ago

Yeah..... it was just a theory. But my ports are contiguous and are discovered in one attempt???? Dunno.... just a theory

JontWeightman commented 7 years ago

Is there any "rules" or logic around the range for the port numbers - contiguous or not ?

Jonathan

On 19 Dec 2016, at 17:03, mikebiddell notifications@github.com wrote:

Yeah..... it was just a theory. But my ports are contiguous and are discovered in one attempt???? Dunno.... just a theory

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

biddster commented 7 years ago

No rules that I know of. The only thing is to specify them and make sure they are free. Run:

$ netstat -l 

on your pi and make sure there are no clashes.

Toshibass commented 7 years ago

Further to my post above, yesterday I added 3 additional wemo emulator nodes to my setup I repeatedly asked Alexa to scan but it would only picked up 1 additional node then I tried stoping and restarting node-red that solved the problem like scanning after restarting enabled Alexa to pick up alll the addition nodes I guess that's linked to issue #6 (no problem as long as you remember to restart node-red after making changes to your wemo emulator node setup)

jbardi commented 7 years ago

I know this is a few months old, but since the issue still exists I thought I'd add my situation to the list.

I have 26 nodes, and I can only get it to recognize 19 of them. Been scanning on and off for a few hours, restarted node-red many times, still always only recognizes 19 devices. All my ports are in sequence, starting at 33301 to 33326, and my Unique IDs are 0001 to 0026

Running netstat -l shows all 26 ports are online and listening, so I have no idea why Alexa can't recognize the last 7 devices

Also, it is finding them in order... the 19 devices are on ports 33301 to 33319, so it is just skipping the devices at ports 33320 to 33326

And it took about 10 scans of Alexa in order to recognize those 19 devcies... it went from like 6, then 9, then 10, then 12, etc, etc until it finally settled on 19 and won't find any more.

I have 5 Alexa devices (1 Echo and 4 Echo Dots). I have 2 separate Amazon accounts, 1 tied to the Echo and two Echo Dots, and the second account tied to the remaining 2 Echo dots, and both accounts find the same 19 devices, yet when I test with 3rd party Wemo apps on my iPhone, they are able to find all 26 devices, so this looks to be a problem with Amazon and the way in which their firmware looks for Wemo devices.

buserror commented 7 years ago

I also have the problem, with just 11 nodes... Also uppon re-scanning, some appear 'offline' (even tho they still work!) Anyway, I found this in the log when I restarted node-red. Hope this helps!

(node) warning: possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit. Trace at process.addListener (events.js:239:17) at EmulatedDevice._initSsdp (/home/nodered/.node-red/node_modules/node-red-contrib-wemo-emulator/node_modules/wemore/lib/emulate.js:122:13) at Server. (/home/nodered/.node-red/node_modules/node-red-contrib-wemo-emulator/node_modules/wemore/lib/emulate.js:101:14) at Server.g (events.js:260:16) at emitNone (events.js:67:13) at Server.emit (events.js:166:7) at emitListeningNT (net.js:1276:10) at nextTickCallbackWith1Arg (node.js:431:9) at process._tickDomainCallback (node.js:394:17)

biddster commented 7 years ago

It might be that there are echo limits https://github.com/armzilla/amazon-echo-ha-bridge/issues/12. The echo ha bridge is truncating at 26.

jbardi commented 7 years ago

Ok, so this is not an echo limit. I have checked a lot of sources, and as far as I can tell, there are no limits to how many devices, wemo or otherwise, can be added to an alexa device.

I was also receiving the EventEmitter memory leak error. By default, node.js only allows 10 listeners per process, as most use cases would be closing down those listeners, but in this case, we need 1 active listener for each emulated wemo device.

The only way I was able to fix the problem was by editing the emulate.js file in the wemore node_module that biddster is using for this node in order to allow for unlimited listeners. Obviously this is not the best option, as an update to wemore would break this, but since wemore has not been updated in over a year, I feel comfortable making this change.

If you are interested, you can edit the emulate.js file in the wemore lib folder.

It is located at ~/.node-red/node_modules/node-red-contrib-wemo-emulator/node_modules/wemore/lib/emulate.js

Make the following change:

On line 122 of emulate.js, is the line: process.on('exit', this.close.bind(this));

So in order to bypass the 10 listener limit for node.js, you have to add the following line just below it, at line number 123: process.setMaxListeners(0);

Once I did this and restarted node-red, the EventEmitter memory leak error went away, and my devices showed up in Alexa.

biddster commented 7 years ago

Many, many thanks for doing the investigation on this. I've been struggling for time lately.

Maybe we could just increment the max listeners every time the wemo node gets created?

biddster commented 6 years ago

0.5.0 has been released with the fix suggested by @jbardi, please give it a test folks and report back.

biddster commented 4 years ago

Closing due to inactivity. Please reopen if the issue still persists.