In the first article I talked about the goal, made a short description of the project. In this publication I will talk about the current state of affairs and the development of the project.
History does not repeat, history improves.
Quote from a pack of tobacco. Next, I will show what has improved in four months of working on the project.
At the moment, all the source code of the project are located at .
Since the serial port holds only one connection, it was decided to create the bdsd.sock service. The service keeps the serial port connection with the Weinzierl KNX BAOS 838 kBerry module on the one hand, and on the other hand, listens to the UNIX socket at $ XDG_RUNTIME_DIR / bdsd.sock. Clients communicate with the socket using the BDSM (Bobaos Datapoint Sdk Message) protocol. Description .
The service serves to make it possible to connect simultaneously with several clients. Suppose you need to run the CLI for debugging and, at the same time, another service, for example - a plugin to support socket.io or mqtt.
Installation:
$ sudo npm install -g bdsd.sock --unsafe-perm
Run:
$ bdsd.sock
To automatically start at system startup, you can use systemd capabilities. Instructions, as well as the service file are available in the repository.
Naturally, for the service to work, you need to configure access to the UART Raspberry Pi. Instructions for setting is in the previous publication.
In addition to IPC added support for data types. When the bdsd.sock service is started, it polls the BAOS module about the stored dataphone (GetDatapointDescription.Req) and then stores all of its values, including the type (DPT1, DPT5, etc.). For the client, this means that it is not necessary to manually convert the set of bytes, bdsd.sock does this work by itself.
It was:
bobaos> setDatapointValue -s 2 -v 128 -t dpt5
It became:
bobaos> setValue -s 2 -v 128
It was:
bobaos> getDatapointValue -s 1 { service: 'GetDatapointValue.Res', direction: 'response', error: false, start: 1, number: 1, payload: [ { id: 1, state: 16, length: 2, value: <Buffer 0c 56> } ] }
It became:
bobaos> getValue -s 1 { id: 1, value: 22.2, raw: { type: 'Buffer', data: [ 12, 86 ] } }
bdsd.client - client library for nodejs projects. Available in npm.
Installation:
$ npm install --save bdsd.client
Example:
let myClient = require('bdsd.client')(); let myInterval = null; myClient.on('connect', _ => { console.log('connected to bdsd.sock'); if (myInterval === null) { myInterval = setInterval(_ => { myClient .getValue(42) .then(payload => { return myClient .setValue(payload.id, !payload.value); }) .catch(e => { console.log('an error occurred', e); }); }, 5000); } });
In this example, we invert the datapoint value 42 every 5 seconds. The client API is implemented on promises, the description is available on the repository page .
There are no client libraries for other programming languages, but, since open source project, the ability to write is welcome. Description of the protocol .
Socket.io interface for interacting with clients of other machines, for example, in the local network.
Installation:
$ sudo npm install -g bdsd-io --unsafe-perm $ bdsd-io
Customer example:
const socket = require('socket.io-client')('http://<RPi ip address>:49199'); socket.on('connect', _ => { console.log('Connected to bobaos server!'); socket.emit('get value', 1, function(err, payload) { if (err) { throw new Error(err) } console.log('Got datapoint 1 value: ', payload); }); // socket.on('value', function(payload){ console.log('got broadcasted value:', payload); }); })
bdsd-io supports the following methods:
Replaced by bobaos-cli came the new command line interface bdsd-cli . I use it on each object for debugging. It is more convenient to set, read, and receive values from the KNX bus than from the ETS in that it is controlled via the command line, which significantly increases the speed of work.
Installation and use:
$ sudo npm install -g bdsd-cli --unsafe-perm $ bdsd-cli connected bobaos> setValue -s 999 -v 'Hello, friend' { id: 999 } bobaos> getValue -s 999 { id: 999, value: 'Hello, friend', raw: { type: 'Buffer', data: [ 72, 101, 108, 108, 111, 44, 32, 102, 114, 105, 101, 110, 100, 0 ] } } bobaos> getDescription -s 999 { id: 999, value: { id: 999, dpt: 'dpt16', flags: { priority: 'low', communication: true, read: false, write: true, readOnInit: false, transmit: true, update: false }, length: 14 } } broadcasted value: { id: 1, value: 22.3, raw: { type: 'Buffer', data: [ 12, 91 ] } } bobaos> setProgrammingMode -v 1 Set programming mode: success bobaos> setProgrammingMode -v 0
List of commands:
Over time, many things improve and develop. Including the bobaos-project, the work on which is in full swing and the ideas of practical application are being actively implemented. As an example, with a half-kick, you can raise a bot for a telegram notifying about events in your home :)
There is an interesting trail for the project ahead and I will keep you updated on the progress. Until the following publications.
Source: https://habr.com/ru/post/354246/
All Articles