ScriptingSubscriptions - kamilfb/mqtt-spy GitHub Wiki
To run a script for a given subscription, go to the connection settings (Menu -> Connections -> Connection settings / Ctrl + M), select your connection, then go to the Subscriptions tab and add a new entry with the subscription filter/topic and the location of the script. Then open the connection and your script should be run automatically.
function onMessage()
{
mqtt.publish(
"/reply", "<simpleReply><topic>" + receivedMessage.getTopic() + "</topic>"
+ "<payload><![CDATA[" + receivedMessage.getPayload() + "]]></payload>"
+ "</simpleReply>", 0, false);
return true;
}
function onMessage()
{
receivedMessage.setPayload("<tag>" + receivedMessage.getPayload() + "- modified :)</tag>");
return true;
}