Skip to content

Instantly share code, notes, and snippets.

@adamvr
Last active April 25, 2019 08:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamvr/5555238 to your computer and use it in GitHub Desktop.
Save adamvr/5555238 to your computer and use it in GitHub Desktop.
Clearing mqtt retained messages using mqttjs
node_modules
/**
* Module dependencies
*/
var mqtt = require('mqtt');
/**
* Check command line arguments
*/
if (process.argv.length != 2) {
console.error('No topic specified');
process.exit(-1);
}
/**
* Topic to clear
*/
var topic = process.argv[1];
/**
* Do it!
*/
var c = mqtt.createClient();
c.on('connect', function() {
c.publish(topic, null, {retain: true});
c.end();
});
{
"name": "mqtt-topic-clear",
"version": "0.0.1",
"description": "Clear an mqtt topic of retained messages",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/5555238.git"
},
"keywords": [
"mqtt"
],
"author": "Adam Rudd",
"license": "BSD",
"dependencies": {
"mqtt": "~0.2.7"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment