50ButtonsEach / fliclib-linux-hci

Flic SDK for Linux
305 stars 55 forks source link

Can't add new buttons. Client won't connect. #116

Open Sawtaytoes opened 1 month ago

Sawtaytoes commented 1 month ago

Error when doing new FlicClient on the latest version I pulled down today:

node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED ::1:5551
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
Emitted 'error' event on FlicClient instance at:
    at FlicClient.rawClient.onError (/home/pi/projects/fliclib-linux-hci/clientlib/nodejs/fliclibNodeJs.js:911:6)
    at Socket.onError (/home/pi/projects/fliclib-linux-hci/clientlib/nodejs/fliclibNodeJs.js:158:6)
    at Socket.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 5551
}

Node.js v18.18.0

Not sure when this broke, but I re-added my Flic buttons at least a year ago, so it was working back then provided I updated the SDK at that time too.

These are the commands I use to start the flicd server and add buttons:

pi@Apple-Pi:~ $ cat ./scripts/start-filc-daemon.sh
#!/bin/bash

echo "Checking for Bluetooth service"
bluetoothServiceState=$(service bluetooth status | grep 'active (running)')

if [ "$bluetoothServiceState" != "" ]; then
  echo "Bluetooth service found. Running command..."
  sudo ~/projects/fliclib-linux-hci/bin/armv6l/flicd -f ~/flic-db.sqlite3 -w -s 0.0.0.0 -d
else
  echo "Bluetooth service not found. Trying again."
  sleep 2
  bash "$0" && exit
fi
pi@Apple-Pi:~ $ cat ./scripts/scan-new-clients.sh
#!/bin/bash

node ~/projects/fliclib-linux-hci/clientlib/nodejs/newscanwizard.js

Starting flicd and scanning

pi@Apple-Pi:~ $ ./scripts/start-filc-daemon.sh
Checking for Bluetooth service
Bluetooth service found. Running command...
Available HCI devices found:

Trying hci0
Flic server is now up and running!
Entering daemon state...
pi@Apple-Pi:~ $ ./scripts/scan-new-clients.sh
node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED ::1:5551
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
Emitted 'error' event on FlicClient instance at:
    at FlicClient.rawClient.onError (/home/pi/projects/fliclib-linux-hci/clientlib/nodejs/fliclibNodeJs.js:911:6)
    at Socket.onError (/home/pi/projects/fliclib-linux-hci/clientlib/nodejs/fliclibNodeJs.js:158:6)
    at Socket.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 5551
}

Node.js v18.18.0

I know it's running, just not why it won't connect all of a sudden. I'm listening on 0.0.0.0, so that should cover all interfaces. Also, I can connect to this service from another device just fine with new FlicClient. It's only when running the scanner that it has issues.

Am I missing something or forgetting how this worked? Did something change since I ran this command last?

What are the steps I should be doing to add new devices?

Sawtaytoes commented 1 month ago

I just remembered something. I recently updated all my Raspberry Pis from Bullseye to Bookworm. It's possible this new OS version came with a new Node.js version.

If that's the case, what can we do to fix this? Do we need to patch the Flic Node.js library?

Sawtaytoes commented 1 month ago

It's an IPv6 thing. I have no clue why ::1:5551 doesn't work, but changing it from localhost to 127.0.0.1 fixed the issue in newscanwizard.

Is this something we should hardcode, or can we update flicd to listen on IPv6 interfaces too?

Emill commented 1 month ago

Mabye Node did something that changed localhost to default to IPv6 rather than IPv4. I'll see what I can do. Either making it work on IPv6 or just change the node script.