espruino / EspruinoTools

JavaScript library of tools for Espruino - used for the Web IDE, CLI, etc.
Apache License 2.0
150 stars 89 forks source link

Cannot connect to puck.js on raspios/bullseye/arm64 #152

Open fabiox23 opened 2 years ago

fabiox23 commented 2 years ago

I am unable to connect to a Puck.js with espruino-cli (v 0.1.45) on a 64-bit RaspiOS on a Raspberry Pi A 3+, the same Puck.js can be connected from a legacy 32 bit OS version. espruino-cli installed with "npm install -g espruino". The Puck.js is listed but cannot be connected to. Any thoughts about the cause of this? In reality, I am also unable to pair to the device with bluetoothctl, although it is discoverable. Again, this works on the 32 bit OS version.

espruino-cli.js -v --list

0.1.45 Espruino Command-line Tool 0.1.45

Acorn library not found - you'll need it for compiled code Found /usr/local/lib/node_modules/espruino/libs/targz.js Found /usr/local/lib/node_modules/espruino/libs/utf8.js Found /usr/local/lib/node_modules/espruino/libs/esprima/escodegen.js Found /usr/local/lib/node_modules/espruino/libs/esprima/esmangle.js Found /usr/local/lib/node_modules/espruino/libs/esprima/esprima.js Found /usr/local/lib/node_modules/espruino/espruino.js Found /usr/local/lib/node_modules/espruino/core/codeWriter.js Found /usr/local/lib/node_modules/espruino/core/config.js Found /usr/local/lib/node_modules/espruino/core/env.js Found /usr/local/lib/node_modules/espruino/core/flasher.js Found /usr/local/lib/node_modules/espruino/core/flasherESP8266.js Found /usr/local/lib/node_modules/espruino/core/modules.js Found /usr/local/lib/node_modules/espruino/core/notifications.js Found /usr/local/lib/node_modules/espruino/core/serial.js Found /usr/local/lib/node_modules/espruino/core/serial_chrome_serial.js No chrome.serial - Chrome Serial disabled Found /usr/local/lib/node_modules/espruino/core/serial_chrome_socket.js No chrome.sockets - Chrome Socket disabled Found /usr/local/lib/node_modules/espruino/core/serial_frame.js serial_frame: Not running in a browser Found /usr/local/lib/node_modules/espruino/core/serial_noble.js Found /usr/local/lib/node_modules/espruino/core/serial_node_serial.js Found /usr/local/lib/node_modules/espruino/core/serial_node_socket.js Found /usr/local/lib/node_modules/espruino/core/serial_web_audio.js Found /usr/local/lib/node_modules/espruino/core/serial_web_bluetooth.js Found /usr/local/lib/node_modules/espruino/core/serial_web_serial.js Found /usr/local/lib/node_modules/espruino/core/serial_websocket_local.js Found /usr/local/lib/node_modules/espruino/core/serial_websocket_relay.js Found /usr/local/lib/node_modules/espruino/core/serial_winnus.js Not on Windows, Winnus not needed Found /usr/local/lib/node_modules/espruino/core/terminal.js Found /usr/local/lib/node_modules/espruino/core/utils.js Found /usr/local/lib/node_modules/espruino/plugins/assembler.js Found /usr/local/lib/node_modules/espruino/plugins/boardJSON.js Found /usr/local/lib/node_modules/espruino/plugins/compiler.js Found /usr/local/lib/node_modules/espruino/plugins/getGitHub.js Found /usr/local/lib/node_modules/espruino/plugins/localModules.js Found /usr/local/lib/node_modules/espruino/plugins/minify.js Found /usr/local/lib/node_modules/espruino/plugins/pretokenise.js Found /usr/local/lib/node_modules/espruino/plugins/saveOnSend.js Found /usr/local/lib/node_modules/espruino/plugins/setTime.js Found /usr/local/lib/node_modules/espruino/plugins/unicode.js UTF8 Library loaded successfully Found /usr/local/lib/node_modules/espruino/plugins/versionChecker.js Initialising CodeWriter Initialising Config Initialising Env Initialising Flasher Initialising FlasherESP8266 Initialising Modules Initialising Notifications Initialising Serial

espruino-cli.js -v -p f3:fd:3e:12:bd:2c

0.1.45 Espruino Command-line Tool 0.1.45

Acorn library not found - you'll need it for compiled code Found /usr/local/lib/node_modules/espruino/libs/targz.js Found /usr/local/lib/node_modules/espruino/libs/utf8.js Found /usr/local/lib/node_modules/espruino/libs/esprima/escodegen.js Found /usr/local/lib/node_modules/espruino/libs/esprima/esmangle.js Found /usr/local/lib/node_modules/espruino/libs/esprima/esprima.js Found /usr/local/lib/node_modules/espruino/espruino.js Found /usr/local/lib/node_modules/espruino/core/codeWriter.js Found /usr/local/lib/node_modules/espruino/core/config.js Found /usr/local/lib/node_modules/espruino/core/env.js Found /usr/local/lib/node_modules/espruino/core/flasher.js Found /usr/local/lib/node_modules/espruino/core/flasherESP8266.js Found /usr/local/lib/node_modules/espruino/core/modules.js Found /usr/local/lib/node_modules/espruino/core/notifications.js Found /usr/local/lib/node_modules/espruino/core/serial.js Found /usr/local/lib/node_modules/espruino/core/serial_chrome_serial.js No chrome.serial - Chrome Serial disabled Found /usr/local/lib/node_modules/espruino/core/serial_chrome_socket.js No chrome.sockets - Chrome Socket disabled Found /usr/local/lib/node_modules/espruino/core/serial_frame.js serial_frame: Not running in a browser Found /usr/local/lib/node_modules/espruino/core/serial_noble.js Found /usr/local/lib/node_modules/espruino/core/serial_node_serial.js Found /usr/local/lib/node_modules/espruino/core/serial_node_socket.js Found /usr/local/lib/node_modules/espruino/core/serial_web_audio.js Found /usr/local/lib/node_modules/espruino/core/serial_web_bluetooth.js Found /usr/local/lib/node_modules/espruino/core/serial_web_serial.js Found /usr/local/lib/node_modules/espruino/core/serial_websocket_local.js Found /usr/local/lib/node_modules/espruino/core/serial_websocket_relay.js Found /usr/local/lib/node_modules/espruino/core/serial_winnus.js Not on Windows, Winnus not needed Found /usr/local/lib/node_modules/espruino/core/terminal.js Found /usr/local/lib/node_modules/espruino/core/utils.js Found /usr/local/lib/node_modules/espruino/plugins/assembler.js Found /usr/local/lib/node_modules/espruino/plugins/boardJSON.js Found /usr/local/lib/node_modules/espruino/plugins/compiler.js Found /usr/local/lib/node_modules/espruino/plugins/getGitHub.js Found /usr/local/lib/node_modules/espruino/plugins/localModules.js Found /usr/local/lib/node_modules/espruino/plugins/minify.js Found /usr/local/lib/node_modules/espruino/plugins/pretokenise.js Found /usr/local/lib/node_modules/espruino/plugins/saveOnSend.js Found /usr/local/lib/node_modules/espruino/plugins/setTime.js Found /usr/local/lib/node_modules/espruino/plugins/unicode.js UTF8 Library loaded successfully Found /usr/local/lib/node_modules/espruino/plugins/versionChecker.js Initialising CodeWriter Initialising Config Initialising Env Initialising Flasher Initialising FlasherESP8266 Initialising Modules Initialising Notifications Initialising Serial

Thanks.

gfwilliams commented 2 years ago

Is the first trace the 64 bit one that didn't work? Because the latter one shows Connected but then Unable to connect...

That is odd... And you definitely did the setcap command in each case? It looks like it, but it's worth checking

fabiox23 commented 2 years ago

Yes, I did run setcap. Both traces are from raspio64 (bullseye), so the puck.js is found and briefly connects but then it says "Unable to connect!".

Does espruino-cli have any dependency with bluez at all? Because bluetoothctl cannot pair (or connect) with the puck either, although if I just copy the old files from /var/lib/bluetooth//f3:fd:3e:12:bd:2c/ from the 32-bit set-up and restart bluetoothd, it does pair and connect.

Also, to be honest, with espruino-cli, I have seen the connection failing at times on a 32-bit version, when I tried again 20 seconds later, it worked.

Any suggestions to fix this would be great because I have now upgraded my raspberry pi based product to use raspio64-bullseye.

Many thanks.

gfwilliams commented 2 years ago

Hi,

That's interesting - maybe can you try after doing sudo /etc/init.d/bluetooth stop?

Noble (the library we use) actually attempts to connect directly to the bluetooth module via HCI, and totally avoids bluez - but it's possible that maybe the bluetooth implementation in the OS is trying to use it at the same time and so is breaking things?

There is another option for comms which I disabled for now because it was causing too much trouble (https://github.com/espruino/EspruinoTools/blob/master/core/serial_node_ble.js.broken) but that one would go via bluez and I guess might be better - although if bluez itself isn't working well, that may not be the best option

fabiox23 commented 2 years ago

Hi,

does the setcap command need to be reissued after reboot or is it a one-off?

When stopping bluetoothd, the puck doesn't even get listed with "espruino --list".

Sometimes, it doesn't connect with the 32-bit version either. After I removed the battery and then reinserted it, it connected (32 bit only). Confused...

Is there a more thorough way to debug the tool? The "-v" flag does not show why it is throwing up the error after connecting.

Thanks.

gfwilliams commented 2 years ago

does the setcap command need to be reissued after reboot or is it a one-off?

No, it's once per Node.js binary - so if you update Node.js you have to do it again.

Sometimes, it doesn't connect with the 32-bit version either. After I removed the battery and then reinserted it, it connected

Well that's odd - although the Puck can only hold one open connection - so if some other device was connected to it, that would have stopped you. And then power cycling it would kill the connection and it'd work.

Is there a more thorough way to debug the tool?

There's not a huge amount, no. What I'd suggest is you just try the code here: https://www.espruino.com/Interfacing#node-js-javascript

That's basically identical, but it's just the raw code so might give you some insight into what's going on if it throws any errors. If it works then that's all a bit strange too!