npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bdsd-io

v2.0.10

Published

Socket.io support for Bobaos Datapoint Sdk

Downloads

6

Readme

bdsd-io: Socket.IO support for Bobaos Datapoint Sdk

Installation

Before installing this module, make sure that bdsd.sock is installed and configured properly. If not, follow instructions on repository page.

Is it configured and systemd service is running then proceed to following steps:

1. Install bdsd-io package by npm

$ sudo npm install -g bdsd-io --unsafe-perm
$ bdsd-io --help
Options:
  --help          Show help                                            [boolean]
  --version       Show version number                                  [boolean]
  --sockfile, -s  path to socket file.     [default: "/run/user/1000/bdsd.sock"]
  --port, -p      port that socket.io listens to                [default: 49199]

2. Create service file in user systemd folder

$ touch ~/.config/systemd/user/bdsd-io.service

Then add following to this file using your favourite text editor:

[Unit]
Description=Socket.IO support for Bobaos Datapoint Sdk Daemon

[Service]
ExecStart=/usr/bin/env bdsd-io

[Install]
WantedBy=default.target

3. Enable service

$ systemctl --user daemon-reload
$ systemctl --user enable bdsd-io.service

4. Start service

$ systemctl --user start bdsd-io.service

Usage

Now you may connect to bdsd-io service by using socket.io-client library.

Node.JS client:

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);
  });
})

Browser:

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://<RPi ip address>:49199');
  socket.on('connect', function(){
    console.log('Connected to bobaos server!');
    io.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);
  });
</script>

You may also check example folder for nodejs and CommandFusion example.

By default, socket.io binds to port 49199. If you want to use other you may change it in index.js file.

Protocol

In order to communicate through socket.io you should use socket.emit function.

socket.emit(<method>, [params], callback);

Methods

1. get datapoonts

Get description for all configured datapoints.

Request:

socket.emit('get datapoints', function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

[ { id: 1,
    length: 2,
    flags:
     { priority: 'low',
       communication: true,
       read: true,
       write: true,
       readOnInit: false,
       transmit: true,
       update: false },
    dpt: 'dpt9' },
  { id: 2,
    length: 1,
    flags:
     { priority: 'low',
       communication: true,
       read: false,
       write: true,
       readOnInit: false,
       transmit: true,
       update: false },
    dpt: 'dpt5' } ]

2. get description

Get description for specified datapoint.

Requires datapoint id as parameter.

Request:

socket.emit('get description', 1, function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

{ id: 1,
  value:
   { id: 1,
     dpt: 'dpt9',
     flags:
      { priority: 'low',
        communication: true,
        read: true,
        write: true,
        readOnInit: false,
        transmit: true,
        update: false },
     length: 2 } }

3. get value

Get value for specified datapoint.

Requires datapoint id as parameter.

Request:

socket.emit('get value', 1, function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

{ id: 1, value: 19.9 }

4. set value

Set datapoint value and send it to KNX bus.

Requires datapoint id as parameter.

Requires datapoint value as parameter

Request:

socket.emit('set value', 1, 20, function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

{ id: 1 }

5. read value

Send read request to KNX bys.

Requires datapoint id as parameter.

Request:

socket.emit('read value', 1, function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

{ id: 1}

6. get stored value

Send read request to KNX bys.

Requires datapoint id as parameter.

Request:

socket.emit('get stored value', 1, function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

{ id: 1, value: 1, raw: {type: 'Buffer', data: [1]}}

7. read values

Send read request for multiple values

Requires array of datapoints.

Request:

socket.emit('read value', [1], function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

{ id: 1}

8. set values

Send read request to KNX bys.

Requires datapoint values as an array: [{id: 1, value: 1}, {id: 2, value: 2}]

Request:

socket.emit('set values', [{id: 1, value: 1}, {id: 2, value: 2}], function(err, res) {
  if (err) {
    throw err;
  }
  console.log(res);
});

Response:

[{id: 1, value: 1}, {id: 2, value: 2}]

Incoming events

1. Value indication

When datapoint changed on bus, e.g. temperature value were sent on change, you will receive 'value' event. So, you should register this event:

socket.on('value', function(payload) {
  console.log('broadcasted value', payload);
})

When running:

broadcasted value { id: 1, value: 19.9 }
broadcasted value { id: 1, value: 20.2 }