Skip to content

ScriptingSubscriptions

Kamil Baczkowicz edited this page Oct 9, 2016 · 1 revision

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.

Samples

Auto-reply


function onMessage()
{	
	mqtt.publish(
			"/reply", "<simpleReply><topic>" + receivedMessage.getTopic() + "</topic>" 
			+ "<payload><![CDATA[" + receivedMessage.getPayload() + "]]></payload>"
			+ "</simpleReply>", 0, false);

	return true;
}

Modify/reformat payload

function onMessage()
{	
	receivedMessage.setPayload("<tag>" + receivedMessage.getPayload() + "- modified :)</tag>");

	return true;
}