Add Bluetooth to Gladys 4

Gna gna gna :stuck_out_tongue:

If we go with that (noble), how can I help?

I noticed that your code (already quite substantial) already supports nut but nothing about Xiaomi temperature sensors, for example.

Do I need to create a new file dedicated to this device or does the communication happen with the generic function?

Hello, I was seeing:

  • 1 generic Bluetooth service that knows the standards, and above all implements the core
  • 1 service per « brand Â» based on the Bluetooth service, and containing its own characteristics: nut, awox
 xiaomi


Today if my code still supports nut, it’s a mistake on my part. I thought I had removed all traces of the « brands Â».

Looking at the pull request files on GitHub, I thought I saw nut somewhere. But maybe it wasn’t the last commit.

I think the best idea is to start with a generic service, with a file for each brand.

This will mainly allow us to support a few models in Gladys more quickly and improve support as updates are released.

Do you have a to-do list or something similar to list the points to resolve before a PR?
This would allow me to help you with a specific point without stepping on each other’s toes!

I think it will be difficult to work in parallel, but I still have a to-do list https://github.com/atrovato/Gladys/projects/10

I’ve made quite a bit of progress; I’m currently validating the basic functions, then I plan to move on to the advanced functions.

I think I can be ready for Pierre-Gilles’ return, even though I would like to provide a stable test image to the community first.

Upon rethinking, it would be necessary to control the time between two requests on a sensor.

This is more of a global reflection on Gladys. For some sensors, it makes sense to collect values every 1 minute (door opening sensor for example?) but a temperature sensor does not need to be contacted as often.

@pierre-gilles what’s your opinion (when you’re back from vacation obviously)?

I agree with you, this is information to be set at the device level, but for now I have set the maximum defined value. This value will be editable via a common graphical component. The modification has already been made on the Tasmota HTTP PR which is awaiting testers
 Not wanting to risk conflicts, I consider that this form is not part of this service.

That’s exactly it, it needs to be done globally. Even better if it’s already done, I would test it with the Bluetooth module as soon as possible (for now I only have that).

The best would be to be able to do something like:

  • During the day, I retrieve the values every 15 minutes
  • At night, it will be every 30 minutes

Since sensors usually run on batteries, you need to save as much energy as possible and not query unnecessarily.

@pierre-gilles I’m bringing up a topic that is becoming relevant for the Bluetooth service: subscribing to an event on the server side to detect the creation of a new device via the classic API.

The goal is to be able to subscribe to the « notify Â» messages sent by the Bluetooth device as soon as it is created. This allows not to poll this device, but to let the device send the data.

But for this, I need to:

  • either create a new endpoint in the Bluetooth service to manage the creation of the device (but I don’t like this option),
  • or be notified of the creation of a new device

In this case, I need to know this information only for Bluetooth devices, but in the long term (GoogleHome connector) we might need to be informed of the creation of any device.

Hello @AlexTrovato

What you want to do seems similar to the MQTT broker principle or did I not understand?

Hello @Reno,
what do you mean by the MQTT broker principle?

Regarding my last message, I mainly want the Gladys core to send an event once a device creation is successful so that services can receive it and process it if needed. In the case of Bluetooth, it would be subscribing to the device’s notifications.

Good evening everyone,
a first testable version of the Bluetooth service is available: v4.0.0-bluetooth.1.

Only the « pure Â» Bluetooth service is available, the generic features defined by the recognized specifications are:

  • the battery level
  • the temperature sensor (in its 3 forms according to the GATT spec)

Here are the Bluetooth GATT specifications, do not hesitate to report a feature to me that is compatible with Gladys, I will try to add it.

In theory, Gladys should subscribe to devices that allow notifications, but for the moment only at the startup of Gladys.
This allows to receive the data sent directly by the device, rather than looping to ask the device for the data.

I have not been able to get the service to work under Windows, even via Docker, but Gladys still starts.

I continue to work on opening the service to other specific services (including AwoX and the migration of known modules in v3).

For the record, test images are available here:

Thank you, I look forward to your feedback.

Hello, I tried to access it but couldn’t via the browser.

By default on the Raspberry Pi, I have Gladys on port 80, Gladys Zigbee2mqtt on port 81, and I wanted to follow the same, so on port 82. As a result, the browser can’t access it.

I’m using this Docker insertion:

docker run -d \
    --restart=always \
    --privileged \
    --network=gladys-net \
    --name gladys-BT \
    -p 82:82 \
    -e NODE_ENV=production \
    -e SERVER_PORT=82 \
    -e TZ=Europe/Paris \
    -e SQLITE_FILE_PATH=/var/lib/gladysassistant/gladys-production-bt.db \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v ${PWD}/gladysassistant:/var/lib/gladysassistant \
    -v /dev:/dev \
    atrovato/gladys

I think I did it right, don’t I?

Hello,
I think you need to add the tag to the image (on this version, I couldn’t generate the manifest).

Another version with some UI changes is being generated.

I therefore advise you to replace atrovato/gladys with atrovato/gladys:v4.0.0-bluetooth.1-arm.

@AlexTrovato, thank you, I will remember to add the tag now.

I can access Gladys, but I have an error message in the Bluetooth configuration:
The Bluetooth module is not available, please check that it is enabled.

However, the Bluetooth works fine in the command line.

Bizarre


I know that for noble (node-ble) you need to allow node to access Bluetooth, but with Docker, I don’t know how to apply it. I’m not sure if it’s necessary for Docker.

Maybe you have some information in the logs?

Oops, forgot, sorry
pi@gladys:~ $ docker logs gladys-BT

> gladys-server@ start:prod /src/server
> cross-env NODE_ENV=production node index.js

Initialising OpenZWave 1.6.1051 binary addon for Node.JS.
    OpenZWave Security API is ENABLED
    ZWave device db    : /usr/local/etc/openzwave
    User settings path : /src/server/services/zwave/node_modules/openzwave-shared/build/Release/../../
    Option Overrides : --Logging false --ConsoleOutput false --SaveConfiguration true
2020-10-03T21:16:02+0200 <info> index.js:19 (Object.start) Starting telegram service
2020-10-03T21:16:02+0200 <info> index.js:13 (Object.start) Starting usb service
2020-10-03T21:16:02+0200 <info> index.js:16 (Object.start) Starting zwave service
2020-10-03T21:16:02+0200 <info> index.js:15 (Object.start) Starting Bluetooth service
2020-10-03T21:16:03+0200 <info> index.js:20 (Object.start) Starting Open Weather service
2020-10-03T21:16:03+0200 <warn> service.start.js:18 (Service.start) Unable to start service bluetooth
2020-10-03T21:16:03+0200 <warn> service.start.js:19 (Service.start) Error: EAFNOSUPPORT, Address family not supported by protocol
at new Hci (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:74:18)
at new NobleBindings (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:25:15)
at Object.<anonymous> (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:546:18)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at module.exports (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/resolve-bindings.js:13:12)
at Object.<anonymous> (/src/server/services/bluetooth/node_modules/@abandonware/noble/index.js:2:49)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at BluetoothManager.start (/src/server/services/bluetooth/lib/commands/bluetooth.start.js:16:20)
at Object.start (/src/server/services/bluetooth/index.js:16:22)
at Service.start (/src/server/lib/service/service.start.js:13:19)
at /src/server/lib/service/service.startAll.js:9:79
at Array.map (<anonymous>)
at Service.startAll (/src/server/lib/service/service.startAll.js:9:54)
at Object.start (/src/server/lib/index.js:104:23)
at async /src/server/index.js:18:3 {
  errno: 97,
  code: 'EAFNOSUPPORT',
  syscall: 'socket'
}
2020-10-03T21:16:03+0200 <info> service.start.js:16 (Service.start) Service telegram is not configured, so it was not started.
2020-10-03T21:16:03+0200 <info> service.start.js:16 (Service.start) Service zwave is not configured, so it was not started.
2020-10-03T21:16:03+0200 <info> service.start.js:16 (Service.start) Service openweather is not configured, so it was not started.
2020-10-03T21:16:03+0200 <info> service.start.js:16 (Service.start) Service mqtt is not configured, so it was not started.
2020-10-03T21:16:03+0200 <info> index.js:63 (Server.<anonymous>) Server listening on port 82
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys-server@ start:prod: `cross-env NODE_ENV=production node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gladys-server@ start:prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-03T19_33_41_998Z-debug.log

> gladys-server@ start:prod /src/server
> cross-env NODE_ENV=production node index.js

Initialising OpenZWave 1.6.1051 binary addon for Node.JS.
    OpenZWave Security API is ENABLED
    ZWave device db    : /usr/local/etc/openzwave
    User settings path : /src/server/services/zwave/node_modules/openzwave-shared/build/Release/../../
    Option Overrides : --Logging false --ConsoleOutput false --SaveConfiguration true
2020-10-03T21:35:36+0200 <info> index.js:16 (Object.start) Starting zwave service
2020-10-03T21:35:36+0200 <info> index.js:13 (Object.start) Starting usb service
2020-10-03T21:35:36+0200 <info> index.js:19 (Object.start) Starting telegram service
2020-10-03T21:35:36+0200 <info> index.js:15 (Object.start) Starting Bluetooth service
2020-10-03T21:35:37+0200 <info> index.js:20 (Object.start) Starting Open Weather service
2020-10-03T21:35:37+0200 <warn> service.start.js:18 (Service.start) Unable to start service bluetooth
2020-10-03T21:35:37+0200 <warn> service.start.js:19 (Service.start) Error: EAFNOSUPPORT, Address family not supported by protocol
at new Hci (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:74:18)
at new NobleBindings (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:25:15)
at Object.<anonymous> (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:546:18)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at module.exports (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/resolve-bindings.js:13:12)
at Object.<anonymous> (/src/server/services/bluetooth/node_modules/@abandonware/noble/index.js:2:49)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at BluetoothManager.start (/src/server/services/bluetooth/lib/commands/bluetooth.start.js:16:20)
at Object.start (/src/server/services/bluetooth/index.js:16:22)
at Service.start (/src/server/lib/service/service.start.js:13:19)
at /src/server/lib/service/service.startAll.js:9:79
at Array.map (<anonymous>)
at Service.startAll (/src/server/lib/service/service.startAll.js:9:54)
at Object.start (/src/server/lib/index.js:104:23)
at async /src/server/index.js:18:3 {
  errno: 97,
  code: 'EAFNOSUPPORT',
  syscall: 'socket'
}
2020-10-03T21:35:37+0200 <info> service.start.js:16 (Service.start) Service zwave is not configured, so it was not started.
2020-10-03T21:35:37+0200 <info> service.start.js:16 (Service.start) Service telegram is not configured, so it was not started.
2020-10-03T21:35:37+0200 <info> service.start.js:16 (Service.start) Service openweather is not configured, so it was not started.
2020-10-03T21:35:37+0200 <info> service.start.js:16 (Service.start) Service mqtt is not configured, so it was not started.
2020-10-03T21:35:37+0200 <info> index.js:63 (Server.<anonymous>) Server listening on port 82
pi@gladys:~ $

Aren’t you on Windows?

not on raspberry pi 3b+