Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting modbus4mqtt off the ground with or without docker #51

Open
kurt-klingbeil opened this issue Jan 12, 2024 · 2 comments
Open

Getting modbus4mqtt off the ground with or without docker #51

kurt-klingbeil opened this issue Jan 12, 2024 · 2 comments

Comments

@kurt-klingbeil
Copy link

I am looking for a way to move data from a PLC via modbus via mqtt to a online dashboard/portal.
I followed the bouncing ball...
When I ran the pip3 install --user modbus4mqtt I got a screenfull of stuff about
externally managed environment,

It suggested (sudo) apt install python3-modbus4mqtt
which, after giving my request some consideration, respectfully declined with a "unable to locate package" error

So I thought I'll venture into the mysterious Domain of Docker

Yesterday when I ran: docker pull tjhowse/modbus4mqtt:latest
i was told "permission denied"
Today when I naively and foolishly decided to try again...
it successfully pulled about a dozen "things" and appeared to have zero Cows...
When I then ran: docker run modbus4mqtt --help
I was told Unable to find image 'modbus4mqtt:latest' locally
pull access denied
repository does not exist or may require 'docker login'
I did docker run --help and got a screenfull of stuff which is incomprehensible at this point

There is a link to https://pypi.org/project/modbus4mqtt/Dockerfile - which 404's out
ditto for https://pypi.org/project/modbus4mqtt/modbus4mqtt/Sungrow_SH5k_20.yaml

So I am equally out of brilliant and dumb ideas.

I get the sense that docker is a little microcosm into which stuff can be installed without fouling the larger
pi-nest, but naively assumed that the docker pull would magically "pull it together'

The overall conceptual question I have is:
Is there a way to manually interact as a man-in-the-middle ?
i.e. issue some manual commands which test whether the modbus TCP connection is up and running
and coughing up data - kinda like using ModbusPoll ?
and conversely, to manually simulate the generation of "manual-modbus" data which would then be
mqtt-shovelled up into the dashboard
thereby segmenting a three-node commissioning into two two-nodes commissionings ?

Of course, any clues, hints, over-the-top spoonfeeding for pulling all the bits of string together
would be most welcome ;-)

best regards

@tjhowse
Copy link
Owner

tjhowse commented Jan 12, 2024

Hm, you may have found an error in the documentation! Try docker run tjhowse/modbus4mqtt:latest --help and see what you get.

The python environment problem you have experienced, the "externally managed environment" thing, is a symptom of how the python environment of the operating system would prefer not to be polluted with packages from pypi. One possible way out of your mire without using docker is to install modbus4mqtt into a "venv", or python virtual environment:

# This creates a virtual environment inside the ".venv" hidden directory
python3 -m venv .venv
# This "activates" the venv, such that python commands use your venv for the duration of your shell session
. .venv/bin/activate
# This installs modbus4mqtt into your venv
python3 -m pip install modbus4mqtt
# This runs modbus4mqtt from inside the venv.
python3 -m modbus4mqtt --help

The links on pypi.org unfortunately don't work, as they're relative paths to files in the repo on github: https://github.com/tjhowse/modbus4mqtt/blob/master/Dockerfile and https://github.com/tjhowse/modbus4mqtt/blob/master/modbus4mqtt/Sungrow_SH5k_20.yaml.

As for your commissioning: You may have success using command line utilities like mosquitto_sub and mosquitto_pub, from the mosquitto-clients debian package, to poke and prod at your MQTT broker. You can monitor for publications and publish your own test messages to the broker to simulate the action of modbus4mqtt to leave the hardware out of the loop until you're ready.

Hope that helps,
tjhowse.

@kurt-klingbeil
Copy link
Author

kurt-klingbeil commented Jan 12, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants