Last active
October 4, 2015 16:34
-
-
Save bachwehbi/a938f4bc8fdde5e6a732 to your computer and use it in GitHub Desktop.
Simple example showing how to use MQTT in Beebotte. This code uses the MQTT.js Node client library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2013-2014 Beebotte <contact@beebotte.com> | |
// This program is published under the MIT License (http://opensource.org/licenses/MIT). | |
///////////////////////////////////////////////////////////// | |
// This code uses the Beebotte API, you must have an account. | |
// You can register here: http://beebotte.com/register | |
///////////////////////////////////////////////////////////// | |
var mqtt = require('mqtt') | |
client = mqtt.connect('mqtt://mqtt.beebotte.com', | |
//Authenticate with your channel token, | |
{username: 'token:YOUR_CHANNEL_TOKEN', password: ''} | |
//alternatively, you can authenticate with your SECRET KEY | |
//{username: 'YOUR_SECRET_KEY', password: ''} | |
); | |
client.on('message', function (topic, message) { | |
console.log(topic + ' ' + message); | |
}); | |
client.subscribe('mychannel/myresource'); | |
setInterval(function() { | |
client.publish('mychannel/myresource', 'Hello World'); | |
}, 1000 /* 1 second */); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment