Beebotte Node.JS SDK
Bugs / Feature Requests
Think you.ve found a bug? Want to see a new feature in beebotte? Please open an
issue in github. Please provide as much information as possible about the issue type and how to reproduce it.
https://github.com/beebotte/bbt_node/issues
Install
To install the most recent release from npm, run:
npm install beebotte
Introduction
This Node.js library provides:
- REST client, and,
- Stream pub/sub client to Beebotte API
The Stream API supports two transports:
Remember, Beebotte resource description uses a two levels hierarchy:
- Channel: physical or virtual connected object (an application, an arduino, a coffee machine, etc) providing some resources
- Resource: most elementary part of Beebotte, this is the actual data source (temperature from a domotics sensor)
Usage
REST Connector
var bbt = require('beebotte');
var client = new bbt.Connector({apiKey: 'API KEY', secretKey: 'SECRET KEY'});
client.write(
{channel: 'mychannel', resource: 'resource1', data: 'Hello World'},
function(err, res) {
if(err) throw(err);
console.log(res);
});
client.write(
{channel: 'mychannel', resource: 'resource1', data: 'Hello World'},
function(err, res) {
if(err) throw(err);
console.log(res);
});
client.read({
channel: 'mychannel',
resource: 'resource1',
limit: 5
}, function(err, res) {
if(err) throw(err);
console.log(res);
});
Stream Connector - MQTT transport
var bbt = require('beebotte');
var transport = {
type: 'mqtt',
apiKey: 'API KEY',
secretKey: 'SECRET KEY',
}
client = new bbt.Stream({ transport: transport });
client.on('connected', function() {
client.subscribe( 'mychannel', 'myresource', function(message){
console.log(message);
})
.on('subscribed', function(sub) {
client.publish( 'mychannel', 'myresource', 'Hello World');
});
});
You can use the Channel Token to authenticate the connection. Using the Channel Token grants read and write access to any resource of that channel. This is the recommended authentication sc
heme.
var transport = {
type: 'mqtt',
token: 'CHANNEL_TOKEN'
}
Stream Connector - Socket.io transport
var bbt = require('beebotte');
var transport = {
type: 'socketio',
apiKey: 'API KEY',
secretKey: 'SECRET KEY'
}
var transport = {
type: 'socketio',
apiKey: 'API KEY',
auth_endpoint: 'YOUR AUTH ENDPOINT',
}
client = new bbt.Stream({ transport: transport });
client.on('connected', function() {
client.subscribe( 'mychannel', 'myresource', {read: true, write: true}, function(message){
console.log(message);
})
.on('subscribed', function(sub) {
client.publish( 'mychannel', 'myresource', 'Hello World');
});
});
You can use the Channel Token to authenticate the connection. Using the Channel Token grants read and write access to any resource of that channel. This is the recommended authentication scheme.
var transport = {
type: 'socketio',
token: 'CHANNEL_TOKEN'
}
Alternatively, you could specify an authentication endpoint (see client authentication)
var transport = {
type: 'socketio',
apiKey: 'API KEY',
auth_endpoint: 'YOUR AUTH ENDPOINT',
}
License
Copyright 2020 Beebotte.
The MIT License