mbs38 / spiciermodbus2mqtt Goto Github PK
View Code? Open in Web Editor NEWThis project forked from owagner/modbus2mqtt
Modbus master which publishes via MQTT
License: Other
This project forked from owagner/modbus2mqtt
Modbus master which publishes via MQTT
License: Other
Hello,
I was using the spiciermodbus2mqtt from some time, and was always working.
I updated the other day the raspbian to bookworm, and update the spiciermodbus2mqtt to the latest version (i'm not completely sure which version i was at) and now i cannot write anymore.
Any ideas of what could go wrong?
MQTT LOG:Received PUBLISH (d0, q0, r1, m0), 'mc6_music_teste/mc6/set/SetTemperature', ... (3 bytes)
Writing to device mc6, Slave-ID=16 at Reference=64 using function code 6 FAILED! (Devices responded with errorcode IllegalFunction. Maybe bad configuration?)
Hi,
I just tried to test modbus2mqtt against one of my Modbus TCP devices. I fell over an error regarding an missing option for PAHO-MQTT but found out in the issues that I have to use an older version (pip3 install paho-mqtt==1.6.1
)
Unfortunately after doing that I got the following error:
File "D:\_coding_\modbus2mqtt_testing\venv\Lib\site-packages\modbus2mqtt\modbus2mqtt.py", line 127, in __init__
self.next_due=time.clock_gettime(0)+self.rate*random.uniform(0,1)
^^^^^^^^^^^^^^^^^^
AttributeError: module 'time' has no attribute 'clock_gettime'
I started the program from the CLI inside my VENV with:
modbus2mqtt --tcp 192.168.10.99 --mqtt-host 192.168.10.5 --config config.csv
and the content of my minimal config is like this:
"type","topic","col2","col3","col4","col5","col6"
poll,ebyte,1,0,2,input_status,1.0
ref,di_01,0,r
Where I am trying to read one Digital Input located on Holding Register 0, 2 Bytes long (R:Function 02).
Modbus ID of the device is 1 and IP like mentioned above.
Am I doing something wrong?
regards
Chris
Hi,
I dived a little deeper now into the concept of your software but from a Docker point of view the Dockerfile is very inconvenient because it always tries to load a "modbus2mqtt.csv" file and one is not able to pass different parameters / arguments to it.
For me a usual usecase would be to roll out the software along with other packages (like mosquitto, node-red, etc.) in a docker-compose package, which makes it very easy to get a solution which you can copy to many projects.
I have changed your Dockerfile a little so that it can use arguments from a docker-compose.yaml file.
# changed Dockerfile
FROM python:alpine
WORKDIR /app
COPY modbus2mqtt.py ./
COPY modbus2mqtt modbus2mqtt/
RUN mkdir -p /app/conf/
# upgrade pip to avoid warnings during the docker build
RUN pip install --root-user-action=ignore --upgrade pip
RUN pip install --root-user-action=ignore --no-cache-dir pyserial pymodbus
RUN pip install --root-user-action=ignore --no-cache-dir paho-mqtt==1.6.1
#OLD ENTRYPOINT FROM REPO
#ENTRYPOINT [ "python", "-u", "./modbus2mqtt.py"]
#CMD ["--config", "/app/conf/ebyte_test.csv", "--mqtt-host", "192.168.10.5", "--tcp", "192.168.10.99"]
# ARGS available at build time and defined in docker-compose.yaml
ARG CONF # =<DEFAULT VALUE>
ARG MODBUSHOST # =<DEFAULT VALUE>
ARG MQTTHOST # =<DEFAULT VALUE>
# CMD command list is not using a shell. ARG Variables are not resolved for that reason.
# We are using the docker CMD directive along with a string that we have build up before.
ENV CMDLINE="python -u modbus2mqtt.py --config /app/conf/$CONF --mqtt-host $MQTTHOST --tcp $MODBUSHOST --avoid-fc6 --verbosity 4"
CMD $CMDLINE
In order to use this with a docker-compose.yaml see my example below:
version: '3.8'
services:
modbus2mqtt_ebyte:
container_name: modbus_ebyte
build:
context: ./build_modbus2mqtt # Cloned github repo with own Dockerfile. CHANGED Dockerfile ENTRYPOINT to accept environment variables (see below)
args:
CONF: "ebyte_me31_aaax2240.csv"
MQTTHOST: "192.168.10.5"
MODBUSHOST: "192.168.10.99"
privileged: true
restart: unless-stopped
environment:
- TZ=Europe/Berlin
volumes:
- "/opt/mqtt_control/modbus2mqtt:/app/conf" # local folder with configuration files is mounted to the /app/conf of the image
I have a folder on my system /opt/mqtt_control/modbus2mqtt
where all the configuration files live that I am planning to create for all my modbus devices. In order to spawn a lot of different modbus devices without hassle I just have to copy the above part into a new service and only change the service and container name, the MODBUSHOST
and the CONF
Arguments. That's it.
Maybe some users find this useful. You could also consider to change the Dockerfile in your repo because if you provide default values for the ARGS the functionality with normal Docker would not change but you could change Arguments while running the Docker run Command along with ENV variables and are able to use Docker Compose easily.
regards
Chris
Dockerfile builds image which does not work with serial connection.
Adding otion [serial] to pymodbus (see pymodbus documentation) helps:
[...]
RUN pip install --root-user-action=ignore --no-cache-dir pymodbus[serial]
[...]
Hello,
Sorry to go again, just to try to help the good project.
0.68 looks like its not running, i installed by hand asyncio which was not in the dependencies, but it doesn't start.
pi@homebridge:/etc/systemd/system $ modbus2mqtt --tcp 192.168.50.142 --config /etc/modbus2mqtt/zantia.csv --mqtt-host localhost --always-publish --verbosity 4
<coroutine object main at 0xf693be28>
sys:1: RuntimeWarning: coroutine 'main' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
pi@homebridge:/etc/systemd/system $
current source is unable to run with current paho-mqtt version (2.0) - https://pypi.org/project/paho-mqtt/#history
Exception ignored in: <function Client.__del__ at 0x7fa23b524ca0>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 874, in __del__
self._reset_sockets()
File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1133, in _reset_sockets
self._sock_close()
File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1119, in _sock_close
if not self._sock:
AttributeError: 'Client' object has no attribute '_sock'
Traceback (most recent call last):
File "modbus2mqtt.py", line 4, in <module>
main()
File "/root/spicierModbus2mqtt-master/modbus2mqtt/modbus2mqtt.py", line 427, in main
asyncio.run(async_main(), debug=False)
File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/root/spicierModbus2mqtt-master/modbus2mqtt/modbus2mqtt.py", line 571, in async_main
mqc=mqtt.Client(client_id=clientid)
TypeError: __init__() missing 1 required positional argument: 'callback_api_version'
Quickfix: nail version to 1.6.1 in Dockerfile:
RUN pip install --root-user-action=ignore --no-cache-dir --upgrade paho-mqtt==1.6.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.