MQTT to Modbus

3,376 views
Skip to first unread message

Vinay Puli

unread,
Apr 17, 2013, 2:53:54 AM4/17/13
to mq...@googlegroups.com
Any one interested in a device which can read modbus inputs and publish it to MQTT topics over GPRS please contact. We have a ready implementation.

Best Regards,
Vinay Puli

Evgeny Boger

unread,
Oct 25, 2015, 3:30:53 PM10/25/15
to MQTT
Hi,

We implemented Modbus RTU <=> MQTT bridge for Linux as part as a development of our Linux-based automation controllers.
It's open source and licensed under MIT license. 

In case anyone is interested, please feel free to use it. Patches and comments are always welcome.




среда, 17 апреля 2013 г., 9:53:54 UTC+3 пользователь Vinay Puli написал:

Abdul Hakeem

unread,
Oct 28, 2015, 9:56:27 PM10/28/15
to mq...@googlegroups.com

Vinay,

Are you able to send the details of the MQTT over GPRS implementation ?

Cheers,

Abdul Hakeem

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

IoT Engineer

unread,
Nov 16, 2015, 3:01:56 AM11/16/15
to MQTT
Hi Vinay,
We are looking for the modbus to MQTT bridge for arduino. It would be helpful if you can share some information.

Simon Platten

unread,
Nov 16, 2015, 3:46:35 AM11/16/15
to mq...@googlegroups.com
Not sure how this could work, modbus is a polled protocol, MQTT is as far away from this as could be, in that content is subscribed to and published when available.

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Andy Stanford-Clark

unread,
Nov 16, 2015, 4:05:57 AM11/16/15
to mq...@googlegroups.com
This is quite a common pattern for "legacy" protocols... you poll modbus in a loop on one side, and "report by exception" to the MQTT side when something changes significantly (e.g. value changes at all, or moves outside a deadband, (e.g. temperature change >= 0.5 degrees)).
For the other way, you subscribe to your "control" topic and push them through to modbus when a message comes in.

Nice little job for an Arduino ;)

Andy

Joel J. Bender

unread,
Nov 16, 2015, 10:06:29 AM11/16/15
to mq...@googlegroups.com
> This is quite a common pattern for "legacy" protocols... you poll modbus in a loop on one side, and "report by exception" to the MQTT side when something changes significantly (e.g. value changes at all, or moves outside a deadband, (e.g. temperature change >= 0.5 degrees)). For the other way, you subscribe to your "control" topic and push them through to modbus when a message comes in.

This is exactly the application I'm working on (sadly, it's not at the top of my list), and there are some interesting twists. Like the fact that MQTT doesn't have a payload format standard (are coils mapped to 1/0 integers, true/false, set/reset strings, etc) and MODBUS doesn't either (but there are some common ones like signed/unsigned, big/little endian, single/double/quad registers per value, and at least two different floating point formats).

Are you considering the "bridge" to be a MODBUS client, server, or both?


Joel

Arlen Nipper

unread,
Nov 16, 2015, 10:11:34 AM11/16/15
to mq...@googlegroups.com
This very use case was one of the primary reasons MQTT was invented in the first place. If only we would have had access to the current population of DIY boards 16 years ago!


-Arlen

Simon Platten

unread,
Nov 16, 2015, 10:19:42 AM11/16/15
to mq...@googlegroups.com
Modbus is a protocol I'm very familiar with having written implementions for Slave and Master for serial and TCP.  There are lots of slightly different implementations  of the protocol around, for example some are base 0 where as others are base 1, when it comes to floating point data, there are lots of different encoding methods.

If the idea is to write a gateway that will buffer data in between an MQTT broker and the actual modbus systems then consider that the modbus protocol doesn't include any timestamping so you wouldn't be able to tell how old data is.



Joel

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Shubha Sudhir

unread,
Nov 16, 2015, 11:36:44 PM11/16/15
to mq...@googlegroups.com
The idea is to have a gateway that will be a Modbus Master and its polls the connected slaves. The gateway(client) will then publish all the modbus data (all topics) via MQTT to a broker. An another MQTT client connected to the same broker (running on a server) will subscribe to the required topic and move the data into a CSV and time stamp will be appended along with the data. In this case, the data will be stored irrespective of any threshold or a delta.

I am trying to replace the POST/GET of REST architecture in an existing system with MQTT PUB/ SUB.

Vinay Puli

unread,
Nov 19, 2015, 3:23:20 AM11/19/15
to MQTT
It could basically be a subtopic on mqtt with every device ID. Please write to me in detail to my mail ID about your requirement.



BR
Vinay

Librae L

unread,
Nov 19, 2015, 3:33:00 AM11/19/15
to mq...@googlegroups.com, MQTT

Hello folks,

Fortunately this is also very similar to the project we are currently working on.
We have supported both MQTT and Modbus together at runtime. They share the same buffer to sync data, which behaves like a bridge.
As Simon has mentioned, intend to keep the data from out of date, we can add timestamp to each set of data.

So, we have verified and it works.
Modbus and MQTT can live together well.

Thanks,
Librae (lib...@linkgo.io)


--

daniel....@gmail.com

unread,
Nov 22, 2015, 9:54:23 AM11/22/15
to MQTT
Hi Sy

yes the problem is that modbus comes with different protocols over ethernet and serial port. We use a BASIC programmable device that can poll modbus, extract relevant data and send it over mqtt to the broker (or as subscriber). 
Pls have a look on the two examples. It could be easily combined, e.g. send data from mqtt to the modbus display or access some modbus io and send the state to mqtt broker.



Best regards

Dani

Simon Platten

unread,
Nov 22, 2015, 10:02:51 AM11/22/15
to mq...@googlegroups.com
Hi Dani,

MQTT with a broker is easy enough to set-up, create topics and subscribe to topics.  Modbus is quite an easy protocol to write, however as previously mentioned it is very deterministic where as MQTT isn't.  A Modbus master makes a poll for data and the slave must respond to the poll.  With MQTT it only publishes topics when new data arrives, it doesn't respond to a request.

However what you would need is an application that sits in the middle.  For discussion purposes, lets call the application a router, the router would have two sides...a near side (modbus slave) and a far side (MQTT subscriber).  The application would need to be configured to map modbus addresses (analog registers or discrete I/O) to topics.  When a update is received on the far side by the router it would have to buffer this data in some kind of map.  When a modbus request is received on the near side of the router the application would respond with data from its internal map.

I hope this makes sense?

Kind Regards,
Simon

daniel....@gmail.com

unread,
Nov 22, 2015, 10:21:12 AM11/22/15
to MQTT
Hi Simon

yes exactly. Maybe let me explain some more. We build a device (hardware) with a small mips processor that has a build in rs485 and mqtt stack. It runs a BASIC interpreter with extended command set. That is what you describe as application in the middle. 
This sends out e.g. a request over sunspec / modbus to a inverter or energy meter and then sends this information to the broker. Other devices may subscribe to that message and switch on / off loads (e.g. headpump, poolpump, smart heater..).
It is possible to make the loads "smart". If new smart meter values are not arriving anymore, they can switch off itself after a while... 

I agree to that limitation of mqtt, a gateway application with "application in the middle" is not the solution in all cases. "Critical" applications need some smart logic locally.

Dani

Simon Platten

unread,
Nov 22, 2015, 10:29:10 AM11/22/15
to mq...@googlegroups.com
Hi Dani,

MQTT is very different from modbus, from what you are saying you understand the difference and the solution, I wouldn't refer to it as a limitation of MQTT, its just different technologies aimed as solving different problems.  Once thing I would like to see added to MQTT would be deadbands.

A long time ago a company I worked with tried to implement a communications protocol based on reporting by exception, similar to MQTT in that when data changed it was published, the problem with this kind of protocol is that it demands lot of bandwidth in order for the case when lots of things change at once...but the problem was that the bandwidth was very minimal, less than 9600 baud.   When everything changed as it often did the network wasn't capable of responding without getting bunged up.  So a polled protocol was used instead...Some years later I revisited this system and by adding protocol the whole thing worked just fine, because data is only published when it changes by more than a specified tolerance, which could be tweaked.

If MQTT was used to publish single registers or discretes individually then deadbands would help to reduce traffic and keep the system effecient.

Kind Regards,
Simon

daniel....@gmail.com

unread,
Nov 22, 2015, 12:21:42 PM11/22/15
to MQTT
Hi Simon

yes true, mqtt is a different technology, it is not a problem or limitation. 

I will address different devices over modbus, ethernet (snmp) or custom serial protocoll similar to good old modem AT command style. 

The battery charger and inverters (battery to grid) for the solar battery are directly connected to the energy meter, it is a control loop to keep the house excess energy and grid power consumption minimal. Those averaged infos should be send e.g. every minute over mqtt and distributed to the loads. Solar inverters will send production data every minute too (mainly for statistics). Loads such as smart heater (heats up water in the boiler) also use mqtt to modbus "gateway" with data every minute (internally they have several heating stages, which are swtiched by relay, wearout of the relay is a concern, so switching every 5-15 minutes). For a small installation that should not be a problem with a local server.
Some loads e.g. coffee machine switch heater stage on and off very quickly (pulsed). It is very difficult to compensate those ripples even with a control loop with 1Hz or even faster. So I'll ignore that. I think even modbus would not be suitable for this purpose, as it uses baudrates below 115k and e.g. a func 3 register read is already 7 bytes or so. Reading multiple registers (e.g. 3 for the phase) we quickyl end up in 10-100ms range. Inverters normally also respond within a couple of seconds...

Best regards

Dani

Glen Ansell

unread,
Jul 27, 2016, 12:32:36 PM7/27/16
to MQTT
Hi Vinay

We would be very interested in your product. How can I receive further details please ?

Thanks

Glen

Andrew Elwell

unread,
Jul 28, 2016, 5:56:29 AM7/28/16
to mq...@googlegroups.com

Holy thread ressurection batman!

I've done this on a raspberry Pi: see http://blog.elwell.org.uk/2016/01/growatt-inverter-monitoring-with.html (github link to code in blog): reads modus serial, publishes json to mqtt and more.

Andrew

banjaxed

unread,
Aug 19, 2016, 11:38:29 AM8/19/16
to MQTT
This thread certainly seems to exhibit bursts of activity every now and then!
Here's a new product in which you may be interested:


Note that this is a subtly different solution to some of the others mentioned here.
It does not take the place of the Modbus master: it is aimed at existing, operational Modbus networks.

Full disclosure: I'm one of the engineers responsible for developing SmartSwarm.
I'm not interested in any commercial questions (use the form on the website), but I am interested in any technical feedback, questions, or discussions.

Regards,
Ben.

Bhagawat Rawat

unread,
Oct 3, 2016, 7:06:34 AM10/3/16
to MQTT
Hi Vinay, we are looking for purchasing such a device.
Can you please contact @ 9913844737 or bhag...@unitary.io 

gid...@legrange.me

unread,
Nov 14, 2016, 2:50:08 PM11/14/16
to MQTT
I've written and open sourced a Java implementation of a Modbus RTU (serial) to MQTT bridge. I've tested it and am using it on a Raspberry Pi 

crujzo jam

unread,
Nov 21, 2016, 6:28:38 AM11/21/16
to MQTT
The page is showing 404 Error. Do you have other location/Page


On Monday, October 26, 2015 at 1:00:53 AM UTC+5:30, Evgeny Boger wrote:

Paul Fremantle

unread,
Nov 21, 2016, 6:44:13 AM11/21/16
to mq...@googlegroups.com
Its working fine for me.

Paul

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+unsubscribe@googlegroups.com.

To post to this group, send email to mq...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Paul Fremantle
Doctoral Researcher, University of Portsmouth, School of Computing
Visiting Scientist, Institute of the Architecture of Application Systems, Stuttgart
Visiting Lecturer, Software Engineering Programme, Oxford University
Co-Founder, WSO2
Apache Member and Committer
twitter: pzfreo / skype: paulfremantle / blog: http://pzf.fremantle.org

gid...@legrange.me

unread,
Nov 23, 2016, 1:55:15 AM11/23/16
to MQTT
It's working, but if you still have trouble, go to github.com and search for modbus-mqtt and select language Java, and you'll see it there. 

Gideon 

Prabhu Hiremath

unread,
Jun 29, 2018, 3:15:20 PM6/29/18
to MQTT
Hi vinay I am interested to work on the Modbus RTU/TCP using mqtt communication. can you help me please.


On Wednesday, April 17, 2013 at 12:23:54 PM UTC+5:30, Vinay Puli wrote:

srivani...@yitsol.com

unread,
Dec 17, 2018, 2:23:48 AM12/17/18
to MQTT
Hi Vinay,

This is Srivani from YITSOL.

I am interested to work on the Modbus RTU/TCP using mqtt communication. can you help me please.

Thanks
Srivani

Ranjith Kumar Diraviyam

unread,
Dec 17, 2018, 6:16:54 AM12/17/18
to MQTT
Hey Srivani, 

We wrote an example for connecting Modbus data received via TCP to MQTTRoute. 


But you can use this for any Broker. 

Thanks, 
Ranjith 

srivani

unread,
Dec 17, 2018, 6:27:36 AM12/17/18
to mq...@googlegroups.com, am...@yitsol.com

Hi Ranjith,

 

Thanks for your reply. Will check and get back to you for any clarifications.

 

Thanks

Srivani

--

To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.

To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.

Karl Palsson

unread,
Dec 17, 2018, 9:48:44 AM12/17/18
to mq...@googlegroups.com

Your "example" relies on compiled code provided only as a pyc and
as dlls. This is.... not a very good way of doing examples.

Sincerely,
Karl P

Ranjith Kumar Diraviyam <ran...@dsmrk.com> wrote:
> Hey Srivani,
>
> We wrote an example for connecting Modbus data received via TCP
> to MQTTRoute.
>
> Modbus to MQTT Broker
> <https://www.bevywise.com/blog/modbus-iot-data-integration-with-mqttroute/>
signature.html

Ranjith Kumar Diraviyam

unread,
Dec 17, 2018, 9:41:25 PM12/17/18
to MQTT
Dear Karl, 

I understand. 

This example is built using the PyModbusTCP and the MQTTClient of Bevywise. The main objective of the example is allowing the customer to modify the way they want their Modbus Data to be transformed into MQTT Packets. 

Hope I am clear. 

Thanks, 
Ranjith 

ran...@bevywise.com

unread,
Feb 6, 2019, 7:54:39 AM2/6/19
to MQTT
Hello All !! 

We have rolled out an updated IoT Gateway which has a configuration interface and does the data query from Modbus and send to any MQTT Platform based on your configuration. 


The current release is a early access version. Please try and let us know your feedback. 

Thanks, 
Ranjith 
Reply all
Reply to author
Forward
0 new messages