Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

would connect over usb-uart or tcp, but get a bluetooth Error #81

Closed
Matthias-Hermsdorf opened this issue Oct 13, 2018 · 14 comments
Closed

Comments

@Matthias-Hermsdorf
Copy link

Matthias-Hermsdorf commented Oct 13, 2018

Hi,

i use a ESP32 and a Windows7 Laptop and Espruino Command-line Tool 0.1.13.
In the web ide the devices get connected, over COM7 USB2UART or tcp://192....:23

As far as I've read BLE is not supportet yet for the ESP32.
But this should not couse problems, because I don't use Bluetooth at all.

Equaly if I try

espruino -p COM7
espruino -p "COM7"
espruino -p "tcp://192.168.178.56:23"
espruino -p "tcp://192.168.178.56:2323" (why the other Port? I've seen it here)

I get:

Espruino Command-line Tool 0.1.13
-----------------------------------

connecting to ''tcp://192.168.178.56:23''                                   
C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\bluetoo
th-hci-socket\lib\usb.js:70                                                 
throw new Error('No compatible USB Bluetooth 4.0 device found!');       
^                                                                       
                                                                        
Error: No compatible USB Bluetooth 4.0 device found!
at BluetoothHciSocket.bindUser (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\bluetooth-hci-socket\lib\usb.js:70:11)
at BluetoothHciSocket.bindRaw (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\bluetooth-hci-socket\lib\usb.js:28:8)
at Hci.init (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\noble\lib\hci-socket\hci.js:101:35)
at NobleBindings.init (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\noble\lib\hci-socket\bindings.js:82:13)
at Noble.<anonymous> (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\noble\lib\noble.js:57:24)

at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

But why?

@gfwilliams
Copy link
Member

Does it actually fail, or is that message just displayed?

When the tool starts it tries to get a list of available ports to see if the one you supplied on the command-line can be found - that means checking out all the various connection types. If it can't find a bluetooth device then it might complain but it should still work with other connection methods.

... having said that, really that warning should only be displayed if --verbose was set

@Matthias-Hermsdorf
Copy link
Author

Hi,
I edit my post and added the stacktrace.
After that error I got back to my shell.
Its not handelt as warning.

@gfwilliams
Copy link
Member

Wow, that's frustrating - looks like it may not even be part of the tools so I'm not sure it's something that can be trapped.

You can always just delete the node_modules/noble folder and it should work great.

@Matthias-Hermsdorf
Copy link
Author

Thanks.
Yes, you are right. Deleting noble works. Now it connects without complain.

@AkosLukacs
Copy link

I ran into the same error on Win10 with Espruino Command-line Tool 0.1.21.
But I have a Pixl board and BLE does work with the Web ide. After deleting the node_modules/noble folder, the CLI works, but obviously can't connect to the Pixl...

Some details: I have a Wifi and a Pixl board, can connect to both of them using the web ide. Updated both to the latest firmware, but can't connect to them using the CLI.

  • Running the IDE in the browser, I can connect with bluetooth to the Pixl.
  • Installed the chrome-app, that can connect to the Pixl and the Wifi.
  • Installed the native app, that only connects to the Wifi via USB

Before deleting node_modules/noble, if I triedespruino or espruino --list, or espruino --no-ble or espruino --no-ble --list, espruino -p COM3 (the Wifi is on COM3 right now), I got the same error and stacktrace as @Matthias-Hermsdorf

Any idea, what might be the problem? Other than Windows 10 of course :) Or how to get the CLI working with BLE on win?

Thanks!

@gfwilliams
Copy link
Member

It's really strange about noble - it seems unique to Windows 10. I'll file an issue at: noble/noble#847

Can you try pairing the Pixl with Windows 10 first and see if that helps? If winnus is installed (it will have been if you had the windows development tools needed to compile native modules) then it uses Windows Bluetooth APIs to access Bluetooth devices, so it should work fine.

It's just frustrating that those Windows APIs require the device to be paired first.

@AkosLukacs
Copy link

An update: node-bluetooth-hci-socket readme says, it needs WinUsb driver for windows, installed that and made some progress:
The version installed with Espruino CLI 0.5.1, and that has a "nice" line:
this._usbDevice = usb.findByIds(0x0a5c, 0x21e8) || usb.findByIds(0x19ff, 0x0239) || usb.findByIds(0x0a12, 0x0001) || usb.findByIds(0x0b05, 0x17cb) || usb.findByIds(0x8087, 0x07dc)|| usb.findByIds(0x8087, 0x0a2b);
It's been changed since, and my PID / VID wasn't in the list.

Added it, and now espruino --list does work:

PS C:\dev> espruino --list
Espruino Command-line Tool 0.1.21
-----------------------------------

PORTS:
  fd:2f:b9:cd:7b:bb (Pixl.js 7bbb)

But espruino (if I'm correct that should connect to the first available device) fails:

PS C:\dev> espruino
Espruino Command-line Tool 0.1.21
-----------------------------------

(node:15716) UnhandledPromiseRejectionWarning: Error: No Ports Found
    at C:\Users\_\AppData\Roaming\npm\node_modules\espruino\bin\espruino-cli.js:745:17
    at eval (eval at loadJS (C:\Users\_\AppData\Roaming\npm\node_modules\espruino\index.js:10:10), <anonymous>:119:11)
    at eval (eval at loadJS (C:\Users\_\AppData\Roaming\npm\node_modules\espruino\index.js:10:10), <anonymous>:48:7)
    at promise.then.ports (C:\Users\_\AppData\Roaming\npm\node_modules\espruino\node_modules\@serialport\stream\stream.js:664:27)
    at <anonymous>
(node:15716) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:15716) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

And the terminal just hangs there, have to kill it.

@gfwilliams
Copy link
Member

Can you connect to your Pixl.js with espruino -p fd:2f:b9:cd:7b:bb?

If so, maybe you could give a pull request to bluetooth-hci-socket for the this._usbDevice line with your device in it so that upsteam Noble gets it?

But yes, espruino should connect to the first port. Could you try it again? it's possible that sometimes it doesn't see the device within the given timeout.

Also, update and try now, and the hang when selecting ports should be gone. --no-ble should also work

@AkosLukacs
Copy link

AkosLukacs commented Dec 6, 2018

Thanks, connecting directly to Pixl.js did work in 0.1.21!

My VID/PID pair is already in the current node-bluetooth-hci-socket
source, but it's not released. Looking at the issues, looks like development / maintenance is stalled.

In Espruino cli 0.1.22 npm package, there is no /lib folder, and dies at line 86 in index.js.

Commenting out that line, and adding my VID to bluetooth-hci-socket, it runs, but either can't find any devices, or fails at

espruino\node_modules\noble\lib\hci-socket\hci.js:582
    this.address = result.toString('hex').match(/.{1,2}/g).reverse().join(':');
                                                          ^

TypeError: Cannot read property 'reverse' of null

Also, can't connect directly with espruino -p fd:2f:b9:cd:7b:bb :(

espruino --list --no-ble does work:

> espruino --list --no-ble
Espruino Command-line Tool 0.1.22
-----------------------------------

PORTS:
  COM3 (Microsoft)

Also espruino --no-ble -p COM3 does connect to the Espruino Wifi.

But espruino --no-ble just drops back to console immediately:

Espruino Command-line Tool 0.1.22
-----------------------------------

Using first port, {"path":"COM3","usb":[483,5740],"description":"Microsoft"}
Connecting to 'COM3'
PS C:\dev>```

Will try to dig into it later.

@gfwilliams
Copy link
Member

Ok, think I fixed the lib issue for you.

It's possible that the USB device you have just doesn't actually work with Noble?

If you let WIndows 10 handle it and paired then Winnus would probably work. As-is I imagine Bluetooth on Windows 10 is now broken until you mess with Zadig/WinUSB?

connecting directly to Pixl.js did work in 0.1.21!

Hmm - all that changed I believe was using newer versions of Noble. You could go back to using an old one?

@AkosLukacs
Copy link

The lib issue is fixed indeed!

At first, didn't know what winnus is, but cloned it, and after pairing, it works with the default windows driver. winnus.write("LED1.write(1)\r"); turns on the Pixl.js backlight :)

Tried 0.1.21 and 0.1.23 again, both versions work "sometimes". Feels like Zadig / WinUSB driver / Noble is not exactly stable on my machine :( Uninstall + reinstall the driver, and it works again :/
Winnus fells a bit more stable.

@tve
Copy link

tve commented Feb 10, 2019

FYI, I'm also having ble related issues. This is on Linux Manjaro (an Arch derivative). The standard invocation pauses for half a second when saying "Connecting" and then exits:

> espruino -p 'tcp://heatmat.voneicken.com:23'
Espruino Command-line Tool 0.1.23
-----------------------------------

Connecting to 'tcp://heatmat.voneicken.com:23'
>

Explicitly disabling BLE gets me a step further:

tve@soumak /h/s/esp8266> espruino --no-ble -p 'tcp://heatmat.voneicken.com:23'
Espruino Command-line Tool 0.1.23
-----------------------------------

Connecting to 'tcp://heatmat.voneicken.com:23'
>>Connected

but after that TTY input is dead. Double ctrl-C does nothing, ctrl-Z does nothing. I have to kill node from another terminal to exit...

Running with verbose enabled shows a bunch of warnings (I removed the "Found..." lines):

0.1.23
Espruino Command-line Tool 0.1.23
-----------------------------------

Acorn library not found - you'll need it for compiled code
No chrome.serial - Chrome Serial disabled
No chrome.sockets - Chrome Socket disabled
No 'serialport' module found
Not on Windows, Winnus not needed
Initialising CodeWriter
Initialising Config
Initialising Env
Initialising Flasher
Initialising Modules
Initialising Notifications
Initialising Serial
  - Initialising Serial Noble Bluetooth LE
  - Initialising Serial Node Socket
  - Initialising Serial Web Bluetooth
Initialising Utils
Initialising Status
Initialising Assembler
Initialising BoardJSON
Initialising Compiler
Initialising GetGitHub
Initialising LocalModules
Initialising Minify
Initialising SaveOnSend
Initialising SetTime
Initialising Unicode
Initialising VersionChecker
Connecting to 'tcp://heatmat.voneicken.com:23'
Noble: module couldn't be loaded, no node.js Bluetooth Low Energy
 { Error: Cannot find module 'bluetooth-hci-socket'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Module.require (internal/modules/cjs/loader.js:657:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/usr/lib/node_modules/espruino/node_modules/noble/lib/hci-socket/hci.js:6:26)
    at Module._compile (internal/modules/cjs/loader.js:721:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3) code: 'MODULE_NOT_FOUND' }
Noble: getPorts - not initialised
No navigator.bluetooth - Web Bluetooth not enabled

Ugh, some of the issues are probably because I'm running node.js V11. I'm now off trying to figure out how to install an ancient version of node without messing up my whole system...

@gfwilliams
Copy link
Member

Well, the Bluetooth errors/warnings are pretty much expected if the modules haven't installed properly, but they shouldn't cause you any problems. Once it says Connecting to 'tcp://... I'm pretty sure it's handed all comms over to the TCPIP library.

Are you sure it's not just that your device isn't responding on TCP/IP?

I just tried netcat -l 2323 and espruino -p tcp://localhost:2323 and it works great here - albeit with a ~5 sec delay while it waits for the print("<","<<",JSON.stringify(process.env),">>",">") command it sent to complete - which obviously doesn't happen with netcat.

If you compile Espruino for Linux and do ./espruino --telnet then espruino -p tcp://localhost:2323 that works great as well.

@tve
Copy link

tve commented Feb 11, 2019

Using node.js V8 solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants