Skip to content

Instantly share code, notes, and snippets.

@imrehg
Created May 27, 2016 12:39
Show Gist options
  • Select an option

  • Save imrehg/db9b9c95ff9be72a8f5dbd4210f47ebf to your computer and use it in GitHub Desktop.

Select an option

Save imrehg/db9b9c95ff9be72a8f5dbd4210f47ebf to your computer and use it in GitHub Desktop.
Telemetry
AUTOBAHN_DEBUG = true;
var https = require('https');
https.globalAgent.options.rejectUnauthorized = false;
var autobahn = require('autobahn');
var connection = new autobahn.Connection({
url: 'wss://ingest.epeakgears.com:1337/ws'
, realm: 'xyala'
});
console.log('starting...');
var intervalA = {}
, intervalB = {}
, autosession = []
;
var gimmeSensorz = function() {
return {
sensors:[
{
channel: 'sensora', // [*] The channel the sensor will publish data
name: 'TemperatureSensor', // [*] The default sensor name
type: 'Temperature', // The sensor type (temperature, voltage, etc)
manufacturer: 'Epeak Gears', // The sensor manufacturer
version: '1.0', // The sensor version
hardware: 'blah blah blah...' // Additional hardware informations
},
{
channel: 'sensorb', // [*] The channel the sensor will publish data
name: 'CPU Frequency', // [*] The default sensor name
type: 'Frequency', // The sensor type (temperature, voltage, etc)
manufacturer: 'Epeak Gears', // The sensor manufacturer
version: '1.0', // The sensor version
hardware: 'blah blah blah...' // Additional hardware informations
}
]
};
}
var start = function() {
// Create fake sensors
var device = 'azerty';
// Fake sensor A
intervalA = setInterval(function(){
var randomValue = randomNumber(30, 50);
var uri = device + '.sensora';
autosession.publish(uri, [{data:randomValue}]);
console.log('published value "'+randomValue+'" to topic ' + uri)
}, 1000);
// Fake sensor B
intervalB = setInterval(function(){
var randomValue = randomNumber(400, 600);
var uri = device + '.sensorb';
autosession.publish(uri, [{data:randomValue/100}]);
console.log('published value "'+randomValue+'" to topic ' + uri)
}, 1000);
};
// Returns a random number between min and max
var randomNumber = function(min, max) {
min = typeof min !== 'undefined' ? min : 0;
max = typeof max !== 'undefined' ? max : 100;
return Math.floor(Math.random() * (max - min + 1)) + min;
};
connection.onopen = function (session) {
console.log("Connected to network with Session ID: "+session.id);
session.register('azerty.proc_list_sensors2', gimmeSensorz).then(function(reg){
autosession = session;
console.log("procedure registered");
start();
}, function(err) {
console.log("failed to register procedure: " + err.error);
});
};
connection.onclose = function (reason, details) {
console.log(reason);
};
connection.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment