openbci-archive / OpenBCI_NodeJS_Wifi

NodeJS driver for the Wifi Shield
MIT License
16 stars 13 forks source link

Issues connecting Wifi on Windows #26

Closed retiutut closed 5 years ago

retiutut commented 5 years ago

My Wifi shield has an address of 10.0.1.12 and is attached to a Ganglion board.

Able to connect and stream data using auto-detect and wifi direct on a Mac running OS X Mojave with OpenBCI_NodeJS_Wifi tests and in the Hub.

Using a Windows 10 machine, getStreamingWiFiDirect.js produces an error. This same error is happening in the current GUI when trying to connect, along with other errors stemming from a failure to connect.

PS C:\Users\Retiutut\Documents\GitHub\OpenBCI_NodeJS_Wifi\examples\getStreamingWiFiDirect> node getStreamingWifiDirect.js
TCP: on port:  51599
Attempting to connect to 10.0.1.12
-> POST: 10.0.1.12/tcp {"ip":"192.168.56.1","output":"raw","port":51599,"delimiter":false,"latency":16667}
server listening 192.168.56.1:62971
STATUS: 504
No more data in response.
BODY: {"connected":false,"delimiter":false,"ip":"192.168.56.1","output":"raw","port":51599,"latency":16667}
Error: ERROR: CODE: 504 MESSAGE: {"connected":false,"delimiter":false,"ip":"192.168.56.1","output":"raw","port":51599,"latency":16667}
    at IncomingMessage.res.once (C:\Users\Retiutut\Documents\GitHub\OpenBCI_NodeJS_Wifi\openBCIWifi.js:1120:16)
    at Object.onceWrapper (events.js:276:13)
    at IncomingMessage.emit (events.js:193:15)
    at endReadableNT (_stream_readable.js:1129:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)
andrewjaykeller commented 5 years ago

Looks like the wifi shield failed to connect to your computers server. I would check you computers firewall permissions or the permissions on the nodejs file?

Here is the line of code that is producing that error

Cheers

retiutut commented 5 years ago

I turned off Windows Firewall and set VSCode to "Run as Admin". Still getting same error.

andrewjaykeller commented 5 years ago

Could you create a test application that streams data into the nodejs application to test the internal server? It sounds like we need to approach this problem from another angle.

retiutut commented 5 years ago

Here is a successful log when using Mac. I notice that my host machine starts with 10. just like the WiFi shield

TCP: on port:  60127
Attempting to connect to 10.0.1.12
-> POST: 10.0.1.12/tcp {"ip":"10.0.1.19","output":"raw","port":60127,"delimiter":false,"latency":16667}
server listening 10.0.1.19:61087
STATUS: 200
No more data in response.
BODY: {"connected":true,"delimiter":false,"ip":"10.0.1.19","output":"raw","port":60127,"latency":16667}
Connected to 10.0.1.12

The Windows machine IP address starts with 192.

andrewjaykeller commented 5 years ago

i agree with your edit, what is your windows computer ip address?

retiutut commented 5 years ago

The Windows machine is supposedly at 192.168.56.1

andrewjaykeller commented 5 years ago

seems weird those ip addresses are so different right?

retiutut commented 5 years ago

Woah now.... Windows 10 says my IP address should be 10.0.1.14! Bug found!

andrewjaykeller commented 5 years ago

awesome, im in class, be back later, lmk if u find the solution 🚀

retiutut commented 5 years ago

Looking into a fix using parameters for ip.address(), as seen in https://github.com/indutny/node-ip/issues/79

retiutut commented 5 years ago

@andrewjaykeller Got it working using

 this.wifiServerUDP.bind({
    address: ip.address("Ethernet", "ipv4")
  });

I think a more generalized fix would select Ethernet, or a WiFi network interface if Ethernet is not available. What are your thoughts?

andrewjaykeller commented 5 years ago

This could be a huge fix for windows users who have had WiFi connection issues on windows!

retiutut commented 5 years ago

Just tried the above code on a Mac, and the network interfaces follow a different standard (ex en0, en1). The fix for this issue should be contained to Windows OS case.

retiutut commented 5 years ago

To fix this issue, the following now happens on WindowsOS only: