You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I needed to delete a bunch of retained messages and struggled to get the right parameters. Here is the answer: mqttspy.publish(topic, '', 0, true);
The trick is that you have to pass the retain parameter as true which is rather counter-intuitive.
Here is a script to delete any number of topics. You can export a topic list from the UI of course:
// Delete a bunch of retained messages
// Wrap the script in a method, so that you can do "return false;" in case of an error or stop request
function publish() {
var Thread = Java.type("java.lang.Thread");
// Define an array for topics we want to process
var topics = [
'topic1',
'topic2'
];
// Loop through each topic
topics.forEach(function(topic) {
// Publish blank payload with retain false
// removes retained messages
mqttspy.publish(topic, '', 0, true);
// Add some sleepy time and allow
// mqtt_spy to interrupt if needed
try {
Thread.sleep(1000);
} catch(err) {
return false;
}
});
// This means all OK, script has completed without any issues and as expected
// return false if needed
return true;
}
publish();
//EOF
Many thanks again for MQTT-Spy, a great tool! :)
The text was updated successfully, but these errors were encountered:
Hi, it took me a while to work this out.
I needed to delete a bunch of retained messages and struggled to get the right parameters. Here is the answer:
mqttspy.publish(topic, '', 0, true);
The trick is that you have to pass the retain parameter as true which is rather counter-intuitive.
Here is a script to delete any number of topics. You can export a topic list from the UI of course:
Many thanks again for MQTT-Spy, a great tool! :)
The text was updated successfully, but these errors were encountered: