Basic Usage
modpoll v1.1.0 - A New Command-line Tool for Modbus and MQTT
usage: modpoll [-h] [-v] -f CONFIG [-d] [-r RATE] [-1] [--interval INTERVAL]
[--tcp TCP] [--tcp-port TCP_PORT] [--udp UDP]
[--udp-port UDP_PORT] [--rtu RTU] [--rtu-baud RTU_BAUD]
[--rtu-parity {none,odd,even}] [--timeout TIMEOUT] [-o EXPORT]
[--mqtt-version {3.1.1,5.0}] [--mqtt-host MQTT_HOST]
[--mqtt-port MQTT_PORT] [--mqtt-clientid MQTT_CLIENTID]
[--mqtt-topic-prefix MQTT_TOPIC_PREFIX]
[--mqtt-publish-topic-pattern MQTT_PUBLISH_TOPIC_PATTERN]
[--mqtt-subscribe-topic-pattern MQTT_SUBSCRIBE_TOPIC_PATTERN]
[--mqtt-diagnostics-topic-pattern MQTT_DIAGNOSTICS_TOPIC_PATTERN]
[--mqtt-qos {0,1,2}] [--mqtt-user MQTT_USER]
[--mqtt-pass MQTT_PASS] [--mqtt-use-tls] [--mqtt-insecure]
[--mqtt-cacerts MQTT_CACERTS]
[--mqtt-tls-version {tlsv1.2,tlsv1.1,tlsv1}] [--mqtt-single]
[--diagnostics-rate DIAGNOSTICS_RATE] [--autoremove]
[--loglevel {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--timestamp]
[--delay DELAY] [--framer {default,ascii,binary,rtu,socket}]
Named Arguments
- -v, --version
show program’s version number and exit
- -f, --config
A local path or URL of Modbus configuration file. Required!
- -d, --daemon
Run in daemon mode without printing result. Recommended to use with docker
Default: False
- -r, --rate
The sampling rate (s) to poll modbus device, Defaults to 10.0
Default: 10.0
- -1, --once
Only run polling at one time
Default: False
- --interval
The time interval in seconds between two polling, Defaults to 1.0
Default: 1.0
- --tcp
Act as a Modbus TCP master, connecting to host TCP
- --tcp-port
Port for MODBUS TCP. Defaults to 502
Default: 502
- --udp
Act as a Modbus UDP master, connecting to host UDP
- --udp-port
Port for MODBUS UDP. Defaults to 502
Default: 502
- --rtu
pyserial URL (or port name) for RTU serial port
- --rtu-baud
Baud rate for serial port. Defaults to 9600
Default: 9600
- --rtu-parity
Possible choices: none, odd, even
Parity for serial port. Defaults to none
Default: “none”
- --timeout
Response time-out seconds for MODBUS devices, Defaults to 3.0
Default: 3.0
- -o, --export
The file name to export references/registers
- --mqtt-version
Possible choices: 3.1.1, 5.0
MQTT version. Defaults to MQTT v3.1.1
Default: “3.1.1”
- --mqtt-host
MQTT server address. Skip MQTT setup if not specified
- --mqtt-port
1883 for non-TLS or 8883 for TLS, Defaults to 1883
Default: 1883
- --mqtt-clientid
MQTT client name, If qos > 0, set unique name for multiple clients
- --mqtt-topic-prefix
(DEPRECATED) Topic prefix for MQTT subscribing/publishing. Defaults to None
- --mqtt-publish-topic-pattern
Topic pattern for MQTT publish. Use <device_name> as placeholder for the device names in Modbus config. Defaults to “modpoll/<device_name>”
Default: “modpoll/<device_name>”
- --mqtt-subscribe-topic-pattern
Topic pattern for MQTT subscribe. Use <device_name> as placeholder for the device names in Modbus config. Defaults to “modpoll/<device_name>/set”
Default: “modpoll/<device_name>/set”
- --mqtt-diagnostics-topic-pattern
Topic pattern for MQTT diagnostics. Use <device_name> as placeholder for the device names in Modbus config. Defaults to None
- --mqtt-qos
Possible choices: 0, 1, 2
MQTT QoS value. Defaults to 0
Default: 0
- --mqtt-user
Username for authentication (optional)
- --mqtt-pass
Password for authentication (optional)
- --mqtt-use-tls
Use TLS
Default: False
- --mqtt-insecure
Use TLS without providing certificates
Default: False
- --mqtt-cacerts
Path to ca keychain
- --mqtt-tls-version
Possible choices: tlsv1.2, tlsv1.1, tlsv1
TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1
Default: “tlsv1.2”
- --mqtt-single
Publish each value in a single topic. If not specified, groups all values in one topic.
Default: False
- --diagnostics-rate
Time in seconds as publishing period for each device diagnostics
Default: 0
- --autoremove
Automatically remove poller if modbus communication has failed 3 times.
Default: False
- --loglevel
Possible choices: DEBUG, INFO, WARNING, ERROR, CRITICAL
Set log level, Defaults to INFO
Default: “INFO”
- --timestamp
Add timestamp to the result
Default: False
- --delay
Time to delay sending first request in seconds after connecting. Default to 0
Default: 0
- --framer
Possible choices: default, ascii, binary, rtu, socket
The type of framer for modbus message. Use default framer if not specified.
Default: “default”
The config option is required.
Commandline Usage
Connect to Modbus TCP device
modpoll --tcp 192.168.1.10 --config examples/modsim.csv
Connect to Modbus RTU device
modpoll --rtu /dev/ttyUSB0 --rtu-baud 9600 --config contrib/eniwise/scpms6.csv
Connect to Modbus TCP device and publish data to remote MQTT broker
modpoll --tcp 192.168.1.10 --config examples/modsim.csv --mqtt-host mqtt.eclipseprojects.io
Connect to Modbus TCP device and export data to local csv file
modpoll --tcp modsim.topmaker.net --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv --export data.csv