Skip to content

Commit

Permalink
sample script, service metjod, public access
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjacobsen committed Aug 4, 2020
1 parent 27a491d commit 643d42a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions java/src/jmri/jmrix/mqtt/MqttAdapter.java
Expand Up @@ -143,6 +143,10 @@ public void publish(String topic, byte[] payload) {
}
}

public void publish(String topic, String payload) {
publish(topic, payload.getBytes());
}

public MqttClient getMQttClient() {
return (mqttClient);
}
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/mqtt/MqttSystemConnectionMemo.java
Expand Up @@ -62,7 +62,7 @@ void setMqttAdapter(MqttAdapter ma) {
mqttAdapter = ma;
}

MqttAdapter getMqttAdapter() {
public MqttAdapter getMqttAdapter() {
return mqttAdapter;
}
}
22 changes: 22 additions & 0 deletions jython/SendMqttMessage.py
@@ -0,0 +1,22 @@
# Example of how to define how to send an arbitrary Mqtt message
#
# To see the result e.g. (your broker and channel may vary)
# mosquitto_sub -v -h 'test.mosquitto.org' -t '/trains/#'
#
# Author: Bob Jacobsen, copyright 2020

import jmri
import java
import jarray
from org.python.core.util import StringUtil

# Find the MqttAdapter
mqqtAdapter = jmri.InstanceManager.getDefault( jmri.jmrix.mqtt.MqttSystemConnectionMemo ).getMqttAdapter()


# create some content
topic = "jmri/test/topic" # note this will be prefixed by configured channel, i.e. "/trains/"
payload = "message content"

# send
mqqtAdapter.publish(topic, payload)

0 comments on commit 643d42a

Please sign in to comment.