modpoll 0.7.0__tar.gz → 0.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {modpoll-0.7.0 → modpoll-0.7.2}/PKG-INFO +53 -34
- {modpoll-0.7.0 → modpoll-0.7.2}/README.md +51 -32
- {modpoll-0.7.0 → modpoll-0.7.2}/modpoll/arg_parser.py +1 -1
- {modpoll-0.7.0 → modpoll-0.7.2}/modpoll/main.py +1 -1
- {modpoll-0.7.0 → modpoll-0.7.2}/modpoll/modbus_task.py +5 -0
- {modpoll-0.7.0 → modpoll-0.7.2}/modpoll/mqtt_task.py +7 -2
- {modpoll-0.7.0 → modpoll-0.7.2}/pyproject.toml +2 -2
- {modpoll-0.7.0 → modpoll-0.7.2}/LICENSE +0 -0
- {modpoll-0.7.0 → modpoll-0.7.2}/modpoll/__init__.py +0 -0
- {modpoll-0.7.0 → modpoll-0.7.2}/modpoll/__main__.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: modpoll
|
|
3
|
-
Version: 0.7.
|
|
4
|
-
Summary: A New Command
|
|
3
|
+
Version: 0.7.2
|
|
4
|
+
Summary: A New Command-line Tool for Modbus and MQTT
|
|
5
5
|
Home-page: https://helloysd.gitlab.io/modpoll
|
|
6
6
|
License: MIT
|
|
7
7
|
Author: Ying Shaodong
|
|
@@ -21,7 +21,7 @@ Requires-Dist: requests (>=2.28.1,<3.0.0)
|
|
|
21
21
|
Project-URL: Repository, https://github.com/gavinying/modpoll
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
23
23
|
|
|
24
|
-
# modpoll - A New Command-line Tool for Modbus
|
|
24
|
+
# modpoll - A New Command-line Tool for Modbus and MQTT
|
|
25
25
|
|
|
26
26
|
[](https://gitlab.com/helloysd/modpoll/-/commits/master)
|
|
27
27
|
[](https://gitlab.com/helloysd/modpoll/-/blob/master/LICENSE)
|
|
@@ -107,8 +107,9 @@ pipx upgrade modpoll
|
|
|
107
107
|
Let's start exploring *modpoll* with *modsim* device, run the following command to get a first glimpse,
|
|
108
108
|
|
|
109
109
|
```bash
|
|
110
|
-
modpoll
|
|
111
|
-
|
|
110
|
+
modpoll \
|
|
111
|
+
--tcp modsim.topmaker.net \
|
|
112
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
112
113
|
```
|
|
113
114
|
|
|
114
115
|
<p align="center">
|
|
@@ -181,23 +182,30 @@ The configuration can be either a local file or a remote public URL resource.
|
|
|
181
182
|
If you are blocked by company firewall for online device or prefer a local test, you can launch your own device simulator by running *modsim* locally,
|
|
182
183
|
|
|
183
184
|
```bash
|
|
184
|
-
docker run -p 5020:5020 helloysd/modsim
|
|
185
|
+
docker run --rm -p 5020:5020 helloysd/modsim
|
|
185
186
|
```
|
|
186
187
|
|
|
187
|
-
It will create a virtual Modbus TCP device running at `localhost:5020`, and
|
|
188
|
+
It will create a virtual Modbus TCP device running at `localhost:5020`, and you can open a new terminal, poll the virtual device using *modpoll* tool,
|
|
188
189
|
|
|
189
190
|
```bash
|
|
190
|
-
modpoll
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
modpoll \
|
|
192
|
+
--tcp localhost \
|
|
193
|
+
--tcp-port 5020 \
|
|
194
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
193
195
|
```
|
|
194
196
|
|
|
195
197
|
> Use `sudo` before the docker command if you want to use the standard port `502`.
|
|
196
198
|
|
|
197
199
|
```bash
|
|
198
|
-
sudo docker run -p 502:5020 helloysd/modsim
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
sudo docker run --rm -p 502:5020 helloysd/modsim
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
In a new terminal,
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
modpoll \
|
|
207
|
+
--tcp localhost \
|
|
208
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
201
209
|
```
|
|
202
210
|
|
|
203
211
|
### Publish data to MQTT broker
|
|
@@ -207,9 +215,10 @@ This is a useful function of this new *modpoll* tool, which provides a simple wa
|
|
|
207
215
|
The following example uses a public MQTT broker `mqtt.eclipseprojects.io` for test purpose. You can also set up your own MQTT broker locally using [mosquitto](https://mosquitto.org/download/).
|
|
208
216
|
|
|
209
217
|
```bash
|
|
210
|
-
modpoll
|
|
211
|
-
|
|
212
|
-
|
|
218
|
+
modpoll \
|
|
219
|
+
--tcp modsim.topmaker.net \
|
|
220
|
+
--mqtt-host mqtt.eclipseprojects.io \
|
|
221
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
213
222
|
```
|
|
214
223
|
|
|
215
224
|
With successful data polling and publishing, you can subscribe the topic `modpoll/modsim` on the same MQTT broker `mqtt.eclipseprojects.io` to view the collected data.
|
|
@@ -247,27 +256,33 @@ The *modpoll* tool will subscribe to the topic `<mqtt_topic_prefix>/<deviceid>/s
|
|
|
247
256
|
```
|
|
248
257
|
|
|
249
258
|
|
|
250
|
-
## Run
|
|
259
|
+
## Run with docker
|
|
251
260
|
|
|
252
261
|
A docker image has been provided for user to directly run the program without local installation,
|
|
253
262
|
|
|
254
263
|
```bash
|
|
255
|
-
docker run helloysd/modpoll
|
|
264
|
+
docker run --rm helloysd/modpoll
|
|
256
265
|
```
|
|
257
266
|
|
|
258
267
|
It shows the version of the program by default.
|
|
259
268
|
|
|
260
|
-
Similar to the above *modsim* test, we can poll data with `docker run`,
|
|
269
|
+
Similar to the above *modsim* test, we can poll data with `docker run`, in order to avoid printing out received data, the argument `--daemon` or `-d` is recommended to use with docker.
|
|
261
270
|
|
|
262
271
|
```bash
|
|
263
|
-
docker run helloysd/modpoll
|
|
272
|
+
docker run --rm helloysd/modpoll \
|
|
273
|
+
modpoll -d \
|
|
274
|
+
--tcp modsim.topmaker.net \
|
|
275
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
264
276
|
```
|
|
265
277
|
|
|
266
278
|
If you want to load a local configure file, you need to mount a local folder onto container volume,
|
|
267
279
|
for example, if the child folder `examples` contains the config file `modsim.csv`, we can use it via the following command,
|
|
268
280
|
|
|
269
281
|
```bash
|
|
270
|
-
docker run -v $(pwd)/examples:/app/examples helloysd/modpoll
|
|
282
|
+
docker run --rm -v $(pwd)/examples:/app/examples helloysd/modpoll \
|
|
283
|
+
modpoll -d \
|
|
284
|
+
--tcp modsim.topmaker.net \
|
|
285
|
+
--config /app/examples/modsim.csv
|
|
271
286
|
```
|
|
272
287
|
|
|
273
288
|
|
|
@@ -276,34 +291,38 @@ for example, if the child folder `examples` contains the config file `modsim.csv
|
|
|
276
291
|
- Connect to Modbus TCP device
|
|
277
292
|
|
|
278
293
|
```bash
|
|
279
|
-
modpoll
|
|
280
|
-
|
|
294
|
+
modpoll \
|
|
295
|
+
--tcp 192.168.1.10 \
|
|
296
|
+
--config examples/modsim.csv
|
|
281
297
|
```
|
|
282
298
|
|
|
283
299
|
- Connect to Modbus RTU device
|
|
284
300
|
|
|
285
301
|
```bash
|
|
286
|
-
modpoll
|
|
287
|
-
|
|
288
|
-
|
|
302
|
+
modpoll \
|
|
303
|
+
--rtu /dev/ttyUSB0 \
|
|
304
|
+
--rtu-baud 9600 \
|
|
305
|
+
--config contrib/eniwise/scpms6.csv
|
|
289
306
|
```
|
|
290
307
|
|
|
291
308
|
- Connect to Modbus TCP device and publish data to MQTT broker
|
|
292
309
|
|
|
293
310
|
```bash
|
|
294
|
-
modpoll
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
311
|
+
modpoll \
|
|
312
|
+
--tcp modsim.topmaker.net \
|
|
313
|
+
--tcp-port 5020 \
|
|
314
|
+
--mqtt-host mqtt.eclipseprojects.io \
|
|
315
|
+
--config examples/modsim.csv
|
|
298
316
|
```
|
|
299
317
|
|
|
300
318
|
- Connect to Modbus TCP device and export data to local csv file
|
|
301
319
|
|
|
302
320
|
```bash
|
|
303
|
-
modpoll
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
321
|
+
modpoll \
|
|
322
|
+
--tcp modsim.topmaker.net \
|
|
323
|
+
--tcp-port 5020 \
|
|
324
|
+
--export data.csv \
|
|
325
|
+
--config examples/modsim.csv
|
|
307
326
|
```
|
|
308
327
|
|
|
309
328
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# modpoll - A New Command-line Tool for Modbus
|
|
1
|
+
# modpoll - A New Command-line Tool for Modbus and MQTT
|
|
2
2
|
|
|
3
3
|
[](https://gitlab.com/helloysd/modpoll/-/commits/master)
|
|
4
4
|
[](https://gitlab.com/helloysd/modpoll/-/blob/master/LICENSE)
|
|
@@ -84,8 +84,9 @@ pipx upgrade modpoll
|
|
|
84
84
|
Let's start exploring *modpoll* with *modsim* device, run the following command to get a first glimpse,
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
|
-
modpoll
|
|
88
|
-
|
|
87
|
+
modpoll \
|
|
88
|
+
--tcp modsim.topmaker.net \
|
|
89
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
89
90
|
```
|
|
90
91
|
|
|
91
92
|
<p align="center">
|
|
@@ -158,23 +159,30 @@ The configuration can be either a local file or a remote public URL resource.
|
|
|
158
159
|
If you are blocked by company firewall for online device or prefer a local test, you can launch your own device simulator by running *modsim* locally,
|
|
159
160
|
|
|
160
161
|
```bash
|
|
161
|
-
docker run -p 5020:5020 helloysd/modsim
|
|
162
|
+
docker run --rm -p 5020:5020 helloysd/modsim
|
|
162
163
|
```
|
|
163
164
|
|
|
164
|
-
It will create a virtual Modbus TCP device running at `localhost:5020`, and
|
|
165
|
+
It will create a virtual Modbus TCP device running at `localhost:5020`, and you can open a new terminal, poll the virtual device using *modpoll* tool,
|
|
165
166
|
|
|
166
167
|
```bash
|
|
167
|
-
modpoll
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
modpoll \
|
|
169
|
+
--tcp localhost \
|
|
170
|
+
--tcp-port 5020 \
|
|
171
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
170
172
|
```
|
|
171
173
|
|
|
172
174
|
> Use `sudo` before the docker command if you want to use the standard port `502`.
|
|
173
175
|
|
|
174
176
|
```bash
|
|
175
|
-
sudo docker run -p 502:5020 helloysd/modsim
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
sudo docker run --rm -p 502:5020 helloysd/modsim
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
In a new terminal,
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
modpoll \
|
|
184
|
+
--tcp localhost \
|
|
185
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
178
186
|
```
|
|
179
187
|
|
|
180
188
|
### Publish data to MQTT broker
|
|
@@ -184,9 +192,10 @@ This is a useful function of this new *modpoll* tool, which provides a simple wa
|
|
|
184
192
|
The following example uses a public MQTT broker `mqtt.eclipseprojects.io` for test purpose. You can also set up your own MQTT broker locally using [mosquitto](https://mosquitto.org/download/).
|
|
185
193
|
|
|
186
194
|
```bash
|
|
187
|
-
modpoll
|
|
188
|
-
|
|
189
|
-
|
|
195
|
+
modpoll \
|
|
196
|
+
--tcp modsim.topmaker.net \
|
|
197
|
+
--mqtt-host mqtt.eclipseprojects.io \
|
|
198
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
190
199
|
```
|
|
191
200
|
|
|
192
201
|
With successful data polling and publishing, you can subscribe the topic `modpoll/modsim` on the same MQTT broker `mqtt.eclipseprojects.io` to view the collected data.
|
|
@@ -224,27 +233,33 @@ The *modpoll* tool will subscribe to the topic `<mqtt_topic_prefix>/<deviceid>/s
|
|
|
224
233
|
```
|
|
225
234
|
|
|
226
235
|
|
|
227
|
-
## Run
|
|
236
|
+
## Run with docker
|
|
228
237
|
|
|
229
238
|
A docker image has been provided for user to directly run the program without local installation,
|
|
230
239
|
|
|
231
240
|
```bash
|
|
232
|
-
docker run helloysd/modpoll
|
|
241
|
+
docker run --rm helloysd/modpoll
|
|
233
242
|
```
|
|
234
243
|
|
|
235
244
|
It shows the version of the program by default.
|
|
236
245
|
|
|
237
|
-
Similar to the above *modsim* test, we can poll data with `docker run`,
|
|
246
|
+
Similar to the above *modsim* test, we can poll data with `docker run`, in order to avoid printing out received data, the argument `--daemon` or `-d` is recommended to use with docker.
|
|
238
247
|
|
|
239
248
|
```bash
|
|
240
|
-
docker run helloysd/modpoll
|
|
249
|
+
docker run --rm helloysd/modpoll \
|
|
250
|
+
modpoll -d \
|
|
251
|
+
--tcp modsim.topmaker.net \
|
|
252
|
+
--config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv
|
|
241
253
|
```
|
|
242
254
|
|
|
243
255
|
If you want to load a local configure file, you need to mount a local folder onto container volume,
|
|
244
256
|
for example, if the child folder `examples` contains the config file `modsim.csv`, we can use it via the following command,
|
|
245
257
|
|
|
246
258
|
```bash
|
|
247
|
-
docker run -v $(pwd)/examples:/app/examples helloysd/modpoll
|
|
259
|
+
docker run --rm -v $(pwd)/examples:/app/examples helloysd/modpoll \
|
|
260
|
+
modpoll -d \
|
|
261
|
+
--tcp modsim.topmaker.net \
|
|
262
|
+
--config /app/examples/modsim.csv
|
|
248
263
|
```
|
|
249
264
|
|
|
250
265
|
|
|
@@ -253,34 +268,38 @@ for example, if the child folder `examples` contains the config file `modsim.csv
|
|
|
253
268
|
- Connect to Modbus TCP device
|
|
254
269
|
|
|
255
270
|
```bash
|
|
256
|
-
modpoll
|
|
257
|
-
|
|
271
|
+
modpoll \
|
|
272
|
+
--tcp 192.168.1.10 \
|
|
273
|
+
--config examples/modsim.csv
|
|
258
274
|
```
|
|
259
275
|
|
|
260
276
|
- Connect to Modbus RTU device
|
|
261
277
|
|
|
262
278
|
```bash
|
|
263
|
-
modpoll
|
|
264
|
-
|
|
265
|
-
|
|
279
|
+
modpoll \
|
|
280
|
+
--rtu /dev/ttyUSB0 \
|
|
281
|
+
--rtu-baud 9600 \
|
|
282
|
+
--config contrib/eniwise/scpms6.csv
|
|
266
283
|
```
|
|
267
284
|
|
|
268
285
|
- Connect to Modbus TCP device and publish data to MQTT broker
|
|
269
286
|
|
|
270
287
|
```bash
|
|
271
|
-
modpoll
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
288
|
+
modpoll \
|
|
289
|
+
--tcp modsim.topmaker.net \
|
|
290
|
+
--tcp-port 5020 \
|
|
291
|
+
--mqtt-host mqtt.eclipseprojects.io \
|
|
292
|
+
--config examples/modsim.csv
|
|
275
293
|
```
|
|
276
294
|
|
|
277
295
|
- Connect to Modbus TCP device and export data to local csv file
|
|
278
296
|
|
|
279
297
|
```bash
|
|
280
|
-
modpoll
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
298
|
+
modpoll \
|
|
299
|
+
--tcp modsim.topmaker.net \
|
|
300
|
+
--tcp-port 5020 \
|
|
301
|
+
--export data.csv \
|
|
302
|
+
--config examples/modsim.csv
|
|
284
303
|
```
|
|
285
304
|
|
|
286
305
|
|
|
@@ -5,7 +5,7 @@ from . import __version__
|
|
|
5
5
|
|
|
6
6
|
def get_parser():
|
|
7
7
|
parser = argparse.ArgumentParser(
|
|
8
|
-
description=f"modpoll v{__version__} - A New Command
|
|
8
|
+
description=f"modpoll v{__version__} - A New Command-line Tool for Modbus and MQTT"
|
|
9
9
|
)
|
|
10
10
|
parser.add_argument(
|
|
11
11
|
"-v",
|
|
@@ -37,7 +37,7 @@ def get_utc_time():
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def app(name="modpoll"):
|
|
40
|
-
print("\nmodpoll - A New Command
|
|
40
|
+
print("\nmodpoll - A New Command-line Tool for Modbus and MQTT\n", flush=True)
|
|
41
41
|
|
|
42
42
|
signal.signal(signal.SIGINT, _signal_handler)
|
|
43
43
|
|
|
@@ -155,6 +155,9 @@ class Poller:
|
|
|
155
155
|
elif "int64" == ref.dtype:
|
|
156
156
|
ref.update_value(decoder.decode_64bit_int())
|
|
157
157
|
cur_ref += ref.ref_width
|
|
158
|
+
elif "float16" == ref.dtype:
|
|
159
|
+
ref.update_value(decoder.decode_16bit_float())
|
|
160
|
+
cur_ref += ref.ref_width
|
|
158
161
|
elif "float32" == ref.dtype:
|
|
159
162
|
ref.update_value(decoder.decode_32bit_float())
|
|
160
163
|
cur_ref += ref.ref_width
|
|
@@ -231,6 +234,8 @@ class Reference:
|
|
|
231
234
|
self.ref_width = 4
|
|
232
235
|
elif "uint64" == dtype:
|
|
233
236
|
self.ref_width = 4
|
|
237
|
+
elif "float16" == dtype:
|
|
238
|
+
self.ref_width = 1
|
|
234
239
|
elif "float32" == dtype:
|
|
235
240
|
self.ref_width = 2
|
|
236
241
|
elif "float64" == dtype:
|
|
@@ -26,7 +26,8 @@ def _on_connect(client, userdata, flags, rc, properties=None):
|
|
|
26
26
|
log.info("Connection successful")
|
|
27
27
|
# Subscribing in on_connect() means that if we lose the connection and
|
|
28
28
|
# reconnect then subscriptions will be renewed.
|
|
29
|
-
|
|
29
|
+
qos = userdata.get("qos", 0) # Default to QoS 0 if not provided
|
|
30
|
+
client.subscribe(f"{args.mqtt_topic_prefix}+/set", qos)
|
|
30
31
|
elif rc == 1:
|
|
31
32
|
log.warning("Connection refused - incorrect protocol version")
|
|
32
33
|
elif rc == 2:
|
|
@@ -83,7 +84,11 @@ def mqttc_setup(config):
|
|
|
83
84
|
else:
|
|
84
85
|
clientid = args.mqtt_clientid
|
|
85
86
|
global mqttc
|
|
86
|
-
mqttc = mqtt.Client(
|
|
87
|
+
mqttc = mqtt.Client(
|
|
88
|
+
clientid,
|
|
89
|
+
clean_session=(args.mqtt_qos == 0),
|
|
90
|
+
userdata={"qos": args.mqtt_qos},
|
|
91
|
+
)
|
|
87
92
|
if args.mqtt_use_tls:
|
|
88
93
|
if args.mqtt_tls_version == "tlsv1.2":
|
|
89
94
|
tlsVersion = ssl.PROTOCOL_TLSv1_2
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "modpoll"
|
|
3
|
-
version = "0.7.
|
|
4
|
-
description = "A New Command
|
|
3
|
+
version = "0.7.2"
|
|
4
|
+
description = "A New Command-line Tool for Modbus and MQTT"
|
|
5
5
|
authors = ["Ying Shaodong <helloysd@gmail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
homepage = "https://helloysd.gitlab.io/modpoll"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|