WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Modbus  (Read 6229 times)

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Modbus
« on: May 25, 2016, 06:21:52 PM »
If you do any industrial stuff you eventually come across Modbus.
Been working on a networked sensor system, SCADA stuff expects various protocols.
Modbus on TCP is one of them.

It uses a request, response method.
The client asks the server(sensor) for data from certain registers.
The client can also write to some registers that can turn coils (relays, solenoid, valves etc) on and off.

Make a data.bin binary file with the preamble and data in it .
A simple test, use a modbus terminal on another PC (CAS modbus scanner?).
Run this on the Pi, cat data.bin | nc -l -p 502 > request.txt
Binary files, so hex viewer in MC is useful

In the micropython examples there is a server example.
https://github.com/micropython/micropython/tree/master/examples/network
It can be turned into a simple modbus server by changing the port to 502 and the CONTENT string contains the data.bin data.

No extra programs, tcz's, libraries, installs needed, just the basic piCore release.
SCADA at home?
Probably not a good idea for reactor control:)
People actually sell SCADA software that runs on Pi's.

SCADA client software for Pi's? not my problem yet:)
Plenty that runs on Windows and cost $$$.

Serial port modbus on Zero's, add a RS485 transceiver and you have really cheap sensor/control server units.
Modbus TCP is easier in a way because error checking is already in the Ethernet packets.

One little step closer to Pi's taking over the World.


Offline andyj

  • Hero Member
  • *****
  • Posts: 1021
Re: Modbus
« Reply #1 on: May 26, 2016, 04:36:26 AM »
I don't know how this would be useful without I/O. The market is already flooded with microcontrollers that aren't too expensive. We use a lot of them for wellhead control where PLC's are too much. An OPC-UA to modbus gateway might be interesting. Do you plan to use an RS-232 to RS-485 converter, or one of the USB to RS-485 cables?

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Modbus
« Reply #2 on: May 26, 2016, 05:22:33 AM »
How many I/O do you need, Pi's got lots.

Why go RS485 on a normal Pi, got Ethernet, just do ModbusTCP.
Modbus on TCP is easy, er now that I figured out it could be done.
Protocol is old, simpler than http etc, just the binary files can be pain to get your head around.
usocket in micropython handles it no problems even with busybox-httpd serving real web pages.
Maybe a dozen bytes per minute for one temperature sensor.

RS485 would be good for the Zero's.
Use cat5 cable, power and comms?
Do they make Power Over RS485 switch/routers?

Hmm, Modbus RS485 cat 5 LED home lighting system.
15 Watts per cable, max I have is 3x5watt LEDs in a triple fitting.
Going to need another few 10 packs of Zeros.
Camera controlled lighting? and a couple rolls cat 5?
That's now about 25 things I could put a Zero in at home.


Offline andyj

  • Hero Member
  • *****
  • Posts: 1021
Re: Modbus
« Reply #3 on: May 26, 2016, 05:42:09 AM »
When I think I/O I include analog like 4-20 mA. RS-485 is usually for polling devices for analog data which don't have Ethernet ports. Also, anything industrial / control related with an Ethernet port will almost certainly also support Modbus TCP. I've done enough Modicon programming to understand why Modbus is the way it is. The POE to RS-485 converters exist, but they're industrial and serious $$$. What do you have now that supports Modbus TCP? It wouldn't be much good if the Pi was the only thing that could talk it.

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Modbus
« Reply #4 on: May 26, 2016, 06:05:34 AM »
I use Pi's running piCore as gadgets in the University.
Monitor temperatures mainly, but I can use all sorts of i2c digital sensors.
Done temperature, humidity, voltage, current, power, light, colour, lux, magnetic heading, accelerometers, gyros.

Recently needed to connect my temperature monitors which have web servers, logging stuff for years, plotting daily temps talking to the big pro Schneider Modbus building management network. They use clunky old Modbus.
Now I can add all these sensors to Modbus stuff via Pi's, just plug them into the Uni network.
Non critical IoT sensor stuff.

As we make our own PCB's, a POE/RS485 hat/pcb may cost us $5-10.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1021
Re: Modbus
« Reply #5 on: May 26, 2016, 06:22:16 AM »
Have you looked at libmodbus?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Modbus
« Reply #6 on: May 26, 2016, 07:52:47 AM »
There are Python modules to work with Modbus, check https://pypi.python.org/pypi or make a Google search 'python modbus', watch this video

https://www.youtube.com/watch?v=EAXJ_3dfeNI&noredirect=1

and so on.

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Modbus
« Reply #7 on: May 26, 2016, 12:16:56 PM »
Looked at lots of Python libraries.
Not sure how to install them in piCore.
Tested them in Raspbian, big and clunky, way more than I needed to start with.
Same sort of thing for C, tiny programs gets compiled with massive libraries.

Might try porting the python code to Lua/Luajit, they are both small tcz's that have worked before for GPIO etc
Micropython is looking pretty good, seems to be getting better and is now useful and comes already working:).

Offline dbasberg

  • Newbie
  • *
  • Posts: 8
Re: Modbus
« Reply #8 on: November 23, 2016, 12:13:39 PM »
Have you looked at libmodbus?

I would like to use libmodbus on a PI running piCore.  I have a solar charge controller that does Modbus RS485 serial.  I can switch on/off an inverter based on values from the charge controller.  Can I get libmodbus for use on piCore 8?
Douglas S. Basberg, MSEE, PE
embedded controls consultant
HAM call N8VY

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Modbus
« Reply #9 on: November 24, 2016, 09:28:30 AM »
libmodbus.tcz added to piCore-8 repo.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline dbasberg

  • Newbie
  • *
  • Posts: 8
Re: Modbus
« Reply #10 on: November 24, 2016, 07:36:11 PM »
libmodbus.tcz added to piCore-8 repo.

Much appreciated Bela! 8)

I am also looking into how to do MQTT from piCore.  I have started distributing small nodes that speak MQTT and I would like to add this project to that system.
Douglas S. Basberg, MSEE, PE
embedded controls consultant
HAM call N8VY

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Modbus
« Reply #11 on: November 25, 2016, 12:01:54 AM »
I am also looking into how to do MQTT from piCore.  I have started distributing small nodes that speak MQTT and I would like to add this project to that system.

There are many possibilities. There are MQTT C6C++ libraries, Python, Perl, etc. modules.

Are you looking for an MQTT server like mosquitto?


« Last Edit: November 25, 2016, 02:00:16 AM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline dbasberg

  • Newbie
  • *
  • Posts: 8
Re: Modbus
« Reply #12 on: November 25, 2016, 07:12:32 PM »
I am also looking into how to do MQTT from piCore.  I have started distributing small nodes that speak MQTT and I would like to add this project to that system.

There are many possibilities. There are MQTT C6C++ libraries, Python, Perl, etc. modules.

Are you looking for an MQTT server like mosquitto?

I am aware of people using Rasbian that are using the Pi as an MQTT server and they are using mosquitto.  I did a small program in that environment and had esp8266 nodes as clients.
My current project would use piCore and an MQTT client package.  The smaller and simpler the better.  I would prefer C language.

When I looked at the app repos, I saw an app with a name of node.tcz  Is that something like node-red or node-js?  I have not done a project with either, but it looks intriguing for IoT from building blocks for quick prototyping.  The node-red on the pi jessie can do MQTT and Modbus with some downloaded add-ons.  I will download the node-doc file from the app repos and read it.

I wrote programs on an 8 bit processor with 64K ROM and 2K RAM in assembly language that ran car engines.  Now I issue one statement in Python and I get 50K of someone else's code that runs under an O/S and shares the processor with dozens of other tasks.  It is getting to require too much sophistication for me to keep up.  My 10 acre homestead is probably where I belong now. ;)
Douglas S. Basberg, MSEE, PE
embedded controls consultant
HAM call N8VY

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Modbus
« Reply #13 on: November 25, 2016, 10:27:13 PM »

When I looked at the app repos, I saw an app with a name of node.tcz  Is that something like node-red or node-js? 


It is node.js You can get more info about a package reading the .info file

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Modbus
« Reply #14 on: November 25, 2016, 10:29:27 PM »
I did a small program in that environment and had esp8266 nodes as clients.


There is an esp8266 port of MicroPython, see

forum.micropython.org/viewforum.php?f=16
 
MicroPython is Python3 implementation for micro controllers with low resources. It is worth to try or at least look around at the Forum what others are doing.
« Last Edit: November 25, 2016, 10:34:10 PM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."