Grayda / node-orvibo

A node.js package to control Orvibo products
78 stars 18 forks source link

Example not working in Docker container #7

Closed gitgrimbo closed 7 years ago

gitgrimbo commented 8 years ago

My setup is:

I have used Docker to try and avoid having to install a C++ SDK, which seems to be required to compile the sleep library (using node-gyp?).

This is the Docker command I use to start a Node container:

docker run -it --rm --name node-orvibo -p 10000:10000/udp -p 9999:9999/udp -p 48899:48899/udp node:6 /bin/bash

I then run these commands from within the Docker container:

git clone https://github.com/Grayda/node-orvibo.git
cd node-orvibo/
npm install
cd examples/basic/
DEBUG=Orvibo node index.js

And this is the output from running the example program:

root@969a26ad1f72:/node-orvibo/examples/basic# DEBUG=Orvibo node index.js
  Orvibo Preparing connection and listening +0ms
  Orvibo Socket bound to port +14ms 10000
  Orvibo Broadcast set to true +2ms
  Orvibo Socket bound to port +1ms 9999
  Orvibo Broadcast set to true +1ms
  Orvibo Socket bound to port +0ms 48899
  Orvibo Broadcast set to true +1ms
  Orvibo Discovery packet sent +993ms
  Orvibo Message sent to 255.255.255.255:10000 with length 6 +3ms
  Orvibo Message received +3ms 686400067161 { address: '172.17.0.1', family: 'IPv4', port: 53351, size: 6 }
  Orvibo Parsing incoming message. Command ID is: +19ms 7161
  Orvibo Found something else: +1ms
  Orvibo Discovery packet sent +985ms
  Orvibo Message sent to 255.255.255.255:10000 with length 6 +1ms
  Orvibo Message received +1ms 686400067161 { address: '172.17.0.1', family: 'IPv4', port: 53351, size: 6 }
  Orvibo Parsing incoming message. Command ID is: +0ms 7161
  Orvibo Found something else: +1ms
  Orvibo Discovery packet sent +1s

From looking at the code that handles the 7161 command, it seems that my message is far too small. The code referenced uses substring such as message.substr(62, 6), but my message is seemingly only 12 characters in length.

Do you have any ideas? Thanks.

gitgrimbo commented 8 years ago

Thought I'd try the example on Win7 anyway, and it works (despite the npm install error).

Think sleep is only required in the setupDevice() method.

I'll leave this here in case anyone else tries to use Docker with node-orvibo, but I'm happy for it to be closed.

Grayda commented 8 years ago

Thanks for trying this out in Docker. I haven't used Docker in a little while, so I may not be much help. But what I find strange, is this:

Orvibo Message received +1ms 686400067161 { address: '172.17.0.1', family: 'IPv4', port: 53351, size: 6 }

I don't know where port 53351 is coming from, as my app doesn't use it, and it's not a port you've explicitly opened up, but the message received is the "discover" message that the code just sent out (Message sent to 255.255.255.255:10000 with length 6 +1ms).

So perhaps look into port forwarding, or reasons why port 53351 is being used. If I get a chance, I'll open up Docker (I got an invite to the beta the other day) and try and install / run this.

gitgrimbo commented 8 years ago

I think port 53351 is a random internal Docker container port. This internal port is reachable from the 'outside' as one of the -p port numbers, so from outside the Docker container/host you don't see 53351.

E.g. if I run the code I pasted above again I get a different port, 35893:

Orvibo Message sent to 255.255.255.255:10000 with length 6 +4ms
Orvibo Message received +2ms 686400067161 { address: '172.17.0.1', family: 'IPv4', port: 35893, size: 6 }
Orvibo Parsing incoming message. Command ID is: +19ms 7161
Orvibo Found something else: +1ms
Orvibo Discovery packet sent +983ms