Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mqtt serial message without ethernet

Tags:

arduino

mqtt

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?

like image 305
hewi Avatar asked Jun 04 '16 23:06

hewi


People also ask

How can I implement MQTT over serial communication?

Here are some possibilities for using MQTT over serial communication: Use SLIP between the Arduino and the gateway. It may be possible to implement MQTT directly over serial, without TCP/IP, although I am not aware of any gateways to do this.

Is it possible to implement MQTT without TCP/IP?

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.

Can I use MQTT with an Arduino?

These principles also turn out to make the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium. Actually you can use MQTT with an Arduino board using Arduino Ethernet Client api.

How does MQTT work on the LAN?

Those messages are formed by a topic and a payload A device can publish messages to the LAN and it can subscribe to messages on the LAN. Now when I say "publish to the LAN" that is a bit of a eufemism, because in fact a node will be publishing its messages and subscribing to messages from a so called MQTT broker.


2 Answers

As I was looking for the same answer and didn't find anything to my liking, I decided to write an implementation that enables any Bluetooth, USB or pure serial port communication to send MQTT message. You can find the result here : https://github.com/vortex314/serial2mqtt It enables any linux machine ( Raspberry Pi 1, Raspi 3 , PC ) to act as a gateway. It's written in C++ so should be lightweight enough for small devices. Hope this helps.

Update 27/6 : build folder contains pre-build version for Linux Intel and Raspberry.

like image 164
Lieven Avatar answered Oct 12 '22 08:10

Lieven


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...

like image 27
njh Avatar answered Oct 12 '22 10:10

njh