Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu tuannguyenssu/publisher.js Secret
Created Sep 29, 2019

Embed
What would you like to do?
var mqtt = require('mqtt');
var settings = {
mqttServerUrl : "localhost",
port : 18833,
topic : "myTopic"
}
var client = mqtt.connect('mqtt://' + settings.mqttServerUrl + ":" + settings.port);
client.on('connect', function () {
setInterval(function() {
var message = "Hello mqtt";
client.publish(settings.topic, message);
console.log('Sent ' + message + " to " + settings.topic);
}, 1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.