Skip to content

Instantly share code, notes, and snippets.

@irjudson
Created October 8, 2014 18:48
Show Gist options
  • Save irjudson/dd06578d891628966b13 to your computer and use it in GitHub Desktop.
Save irjudson/dd06578d891628966b13 to your computer and use it in GitHub Desktop.
client.js
var assert = require('assert')
, config = require('./config')
, mqtt = require('mqtt');
var client = mqtt.createClient(config.mqtt_port, config.mqtt_host, {
'username': '54357f8a47b5a7f3095fcca4',
'password': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1NDM1N2Y4YTQ3YjVhN2YzMDk1ZmNjYTQiLCJpYXQiOjE0MTI3OTIyMjQsImV4cCI6MTQxMjg3ODYyNH0.m7BZMvkFJIvnMTz2ZbMvPduJikOYok-OJmId5eIWMek'
});
client.subscribe('temperature');
//setInterval(function() {
console.log('publishing.');
client.publish('temperature', JSON.stringify({
type:'temperature',
body: {
temperature: 45.1
}
}));
//}, 10000);
client.on('message', function (topic, message) {
console.log('received: ' + message);
var messageObject = JSON.parse(message);
console.log(messageObject.body.temperature);
assert(messageObject.body.temperature, 45.1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment