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

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

Open
fabiox23 opened this issue Jul 3, 2022 · 5 comments
Open

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

fabiox23 opened this issue Jul 3, 2022 · 5 comments

Comments

@fabiox23
Copy link

fabiox23 commented Jul 3, 2022

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

  • Initialising Serial Noble Bluetooth LE
  • Initialising Serial Node Serial
  • Initialising Serial Node Socket
  • Initialising Serial Web Audio
  • Initialising Serial Web Bluetooth
  • Initialising Serial Web Serial
    Initialising Utils
    Initialising Status
    Initialising Assembler
    Initialising BoardJSON
    Initialising Compiler
    Initialising GetGitHub
    Initialising LocalModules
    Initialising Minify
    Initialising Unicode
    Initialising VersionChecker
    Initialising CoreModules
    Initialising Pretokenise
    Initialising SaveOnSend
    Initialising SetTime
    Searching for serial ports...
    Noble: getPorts - initialising...
    Noble: stateChange -> poweredOn
    Noble: Disable Web Bluetooth as we have Noble instead
    Noble: Starting scan
    PORTS:
    /dev/ttyAMA0 (undefined)
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c
    f3:fd:3e:12:bd:2c (Puck.js bd2c) RSSI -31
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c
    Noble: Found device: 78:bd:bc:09:cf:a7 78:bd:bc:09:cf:a7
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c
    Noble: Found device: 78:bd:bc:09:cf:a7 78:bd:bc:09:cf:a7
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c

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

  • Initialising Serial Noble Bluetooth LE
  • Initialising Serial Node Serial
  • Initialising Serial Node Socket
  • Initialising Serial Web Audio
  • Initialising Serial Web Bluetooth
  • Initialising Serial Web Serial
    Initialising Utils
    Initialising Status
    Initialising Assembler
    Initialising BoardJSON
    Initialising Compiler
    Initialising GetGitHub
    Initialising LocalModules
    Initialising Minify
    Initialising Unicode
    Initialising VersionChecker
    Initialising CoreModules
    Initialising Pretokenise
    Initialising SaveOnSend
    Initialising SetTime
    Connecting to 'f3:fd:3e:12:bd:2c'
    Noble: getPorts - initialising...
    Noble: stateChange -> poweredOn
    Noble: Disable Web Bluetooth as we have Noble instead
    Noble: Starting scan
    Port "f3:fd:3e:12:bd:2c" not found - checking ports again (5 attempts left)
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c
    Noble: Found UART device: Puck.js bd2c f3:fd:3e:12:bd:2c
    Noble: Stopping scan (openSerial)
    BT> Connecting
    BT> Connected
    Unable to connect!
    Done

Thanks.

@gfwilliams
Copy link
Member

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
Copy link
Author

fabiox23 commented Jul 4, 2022

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
Copy link
Member

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
Copy link
Author

fabiox23 commented Jul 4, 2022

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
Copy link
Member

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!

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

2 participants