mqtt serial message without ethernet

hewi picture hewi · Jun 5, 2016 · Viewed 10.4k times · Source

everywhere I look, if it comes to MQTT messaging, it is all over Ethernet. Unfortunately, I do not have Ethernet wires available.

I am automating my home, wanting to use mqtt as messaging service. My buttons give a signal (like light 'on') to an arduino board running a mqtt client. How do i put out the mqtt message on the serial lines so the transmitted message can be straight forwardly be picked up by an mqtt broker, without using the ethernet cables?

Answer

njh picture njh · Jun 5, 2016

I am trying to achieve similar goals for my house automation, although I do have Cat5e in the walls, so could use Ethernet.

Here are some possibilities for using MQTT over serial communication:

  • Use SLIP between the Arduino and the gateway. The SerialIP client library which implements TCP/IP over serial: http://playground.arduino.cc/Code/SerialIP . Although I have not tested if this works with a MQTT client library. Nick O'Leary's MQTT Client theoretically works with any implementation of the Arduino 'Client' class.
  • It may be possible to implement MQTT directly over serial, without TCP/IP, although I am not aware of any gateways to do this.
  • MQTT-SN (a slightly different protocol to MQTT) was designed for sending messages over unreliable transport, and may be better suited to a serial line. If you are interested in publish-only, I wrote a very basic library to send MQTT-SN packets over serial: https://github.com/njh/DangerMinusOne
  • You could use something like Node-RED on the Linux gateway, talking some other serial protocol (Firmata?) to the Arduino and then converting to MQTT using Node-RED.

I did start looking at MQTT over serial implementations but one of the problems I didn't resolve was how to deal with multiple devices:

  • Adding lots of serial ports to Linux is complex/expensive (well sort of https://twitter.com/njh/status/570298977310150656)
  • Reliable serial over longer distances requires extra components for RS-485
  • MQTT doesn't work well over half-duplex, without an extra layer of software to deal with a master polling slaves for messages

So I am current looking at implementing MQTT-SN for the ENC28j60 ethernet controller...