Mqtt

javadoc

MQTT is one of the protocols lumped in with the "Internet of Things" (IoT) and it can be used for lots of things. An MQTT client has been borged into MRL.

 

Here's a screenshot from my Android phone running MyMQTT connected to the same broker.

 

And below is some text output from my MQTT broker (mosquitto running on a Beagle Bone Black). You can see the MRL client ("MRL MQTT python") and the Android app (".1416095691833").

950325066: New connection from 10.0.0.8 on port 1883.
950325066: Invalid protocol "MQTT" in CONNECT from 10.0.0.8.
950325066: Socket read error on client (null), disconnecting.
950325066: New connection from 10.0.0.8 on port 1883.
950325066: New client connected from 10.0.0.8 as MRL MQTT python (c1, k60).
950325066: Sending CONNACK to MRL MQTT python (0)
950325067: Received PUBLISH from MRL MQTT python (d0, q2, r0, m1, 'mrl', ... (25 bytes))
950325067: Sending PUBREC to MRL MQTT python (Mid: 1)
950325067: Received PUBREL from MRL MQTT python (Mid: 1)
950325067: Sending PUBCOMP to MRL MQTT python (Mid: 1)
950325067: Sending PUBLISH to .1416095691833 (d0, q1, r0, m1, 'mrl', ... (25 bytes))
950325067: Received PUBACK from .1416095691833 (Mid: 1)
950325127: Received PINGREQ from MRL MQTT python
950325127: Sending PINGRESP to MRL MQTT python
950325127: Received PINGREQ from .1416095691833
950325127: Sending PINGRESP to .1416095691833
950325187: Received PINGREQ from MRL MQTT python
950325187: Sending PINGRESP to MRL MQTT python
950325198: Received PINGREQ from .1416095691833
950325198: Sending PINGRESP to .1416095691833
950325221: Socket read error on client MRL MQTT python, disconnecting.
950325279: Received PINGREQ from .1416095691833
950325279: Sending PINGRESP to .1416095691833
950325339: Received PINGREQ from .1416095691833
950325339: Sending PINGRESP to .1416095691833
950325429: Client .1416095691833 has exceeded timeout, disconnecting.
 
Below is a screenshot from my phone about to publish a message to the channel (mrl/) that MRL is subscribed to.
 
And now below you can see how the message is displayed in the MQTT GUI (which needs a lot of work).
 

References:

  • MQTT Wikipedia
  • OwnTracks (MQTT based GPS location sharing app for smart phones. Good guide for setting up a broker)

Examples:


#file : service/Mqtt.py edit raw
#########################################
# Mqtt.py
# more info @: http://myrobotlab.org/service/Mqtt
#########################################

topic = "myrobotlab/test"
qos = 2
broker = "tcp://broker.mqttdashboard.com:1883" 

clientID = "MRLMQTTpython1"
mqtt = Runtime.createAndStart("mqtt", "Mqtt")
print mqtt.getDescription()

mqtt.setBroker(broker)
mqtt.setQos(qos)
mqtt.setPubTopic(topic)
mqtt.setClientId(clientID)
mqtt.connect(broker)
# authentification mqtt.connect(broker,"guest","guest")

mqtt.subscribe("myrobotlab/test", 0)
mqtt.publish("hello myrobotlab world")

mqtt.addListener("publishMqttMsgString", "python", "publishMqttMsgString")
	 
#  MQTT call-back

def publishMqttMsgString(msg):
	print "message : ",msg[0]
  print "topic : ",msg[1]