Last active
April 25, 2019 08:28
-
-
Save adamvr/5555238 to your computer and use it in GitHub Desktop.
Clearing mqtt retained messages using mqttjs
This file contains hidden or 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
node_modules |
This file contains hidden or 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
/** | |
* 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(); | |
}); |
This file contains hidden or 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
{ | |
"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