bobaos-datapoint-sdk v1.0.5
Description
Allows to set, get, read datapoints from BAOS module. Automatically performs encoding/decoding KNX values from/to JS.
Usage example
In terminal:
npm install --save bobaos-datapoint-sdk
In js file:
const BobaosSdk = require('bobaos-datapoint-sdk');
const myDatapointSdk = BobaosSdk();
myDatapointSdk.on('connected', _ => {
console.log('connected!');
myDatapointSdk
.getAllDatapoints()
.forEach(t => {
t.getValue();
})
});
myDatapointSdk.on('value response', console.log);
myDatapointSdk.on('value indication', console.log);
// register error listener, if not then we may meet some unexpected behavior in case of error
myDatapointSdk.on('error', console.log);
BobaosSdk()
use default parameters for serial port which is the following:
defaultParams = {
serialPort: {
device: '/dev/ttyAMA0',
params: {
baudRate: 19200,
parity: "even",
dataBits: 8,
stopBits: 1
}
}
}
If you want to use custom params define you own and use it as an argument to BobaosSdk() expression.
So, now take a look at what is going on when we create object.
- Open connection to BAOS 838 module, send reset request.
- After opening port, send a lot of requests to get descriptions for datapoints 1-1000.
- Finally, we send request to get bus connected state.
- Callback on 'service' event do the following depending on service:
- if we got 'GetDatapointDescription.Res' service then we create Datapoint object, put it to the store.
- if we got 'GetDatapointValue.Res' or 'DatapointValue.Ind' service then we search for that datapoints in store, decode value and set it to store object.
- if we got 'GetServerItem.Res' and item number is 10(bus connected state) and it's value is 1 then we emit event 'connected'. At this moment all datapoints should be in store and following 'GetDatapointValue.Res', 'DatapointValue.Ind' will be handled according to datapoint type.
So, schematically:
|HOST BAOS|
| RESET -> |
| <- ACK |
| SetServItem 17, 0 -> | // disable indications
| <- ACK |
| <- SetServItemRes |
| GetDescr 1-30 -> |
| <- ACK |
| <- GetDescrRes |
....
....
| GetDescr 991-1000-> |
| <- ACK |
| <- GetDescrRes |
| ACK -> |
| SetServItem 17, 1 -> | // enable indications
| <- ACK |
| <- SetServItemRes |
| GetServItem 10 -> |
| <- ACK |
| <- ServItem |
// At this point sdk emits event 'connected' and now
// we are able to operate with datapoints.
// disable and enable indication are sent to be sure that we have got
// all datapoint descriptionsn when get Datapoint.Ind service.
API
Sdk.getAllDatapoints()
Returns array of all configured datapoints
Sdk.getAllDatapointDescriptions()
Returns array of description of all configured datapoints. Does not include datapoint objects.
Sdk.datapoint(id).setValue(value)
Example:
Sdk.datapoint(1).setValue(true); // for dpt1
Sdk.datapoint(2).setValue(128); // dpt5
Sdk.datapoint(3).setValue(22.5); // dpt9
Sdk.datapoint(id).readValue()
Send read request on KNX bus.
Sdk.datapoint(id).getValue()
Get value from BAOS module.
Sdk.datapoint(id).value
Current value of datapoint