diff --git a/README.md b/README.md index bb51ea9..e0442ba 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ All the tools that pull data from the dish expect to be able to reach it at the The scripts that don't use `grpcurl` to pull data require the `grpcio` Python package at runtime and generating the necessary gRPC protocol code requires the `grpcio-tools` package. Information about how to install both can be found at https://grpc.io/docs/languages/python/quickstart/ +The scripts that use [MQTT](https://mqtt.org/) for output require the `paho-mqtt` Python package. Information about how to install that can be found at https://www.eclipse.org/paho/index.php?page=clients/python/index.php + +The scripts that use [InfluxDB](https://www.influxdata.com/products/influxdb/) for output require the `influxdb` Python package. Information about how to install that can be found at https://github.com/influxdata/influxdb-python. Note that this is the (slightly) older version of the InfluxDB client Python module, not the InfluxDB 2.0 client. It can still be made to work with an InfluxDB 2.0 server, but doing so requires using `influx v1` [CLI commands](https://docs.influxdata.com/influxdb/v2.0/reference/cli/influx/v1/) on the server to map the 1.x username, password, and database names to their 2.0 equivalents. + ## Usage For `parseJsonHistory.py`, the easiest way to use it is to pipe the `grpcurl` command directly into it. For example: diff --git a/dishStatusCsv.py b/dishStatusCsv.py index 0a32ee8..3b8e31b 100644 --- a/dishStatusCsv.py +++ b/dishStatusCsv.py @@ -1,13 +1,24 @@ #!/usr/bin/python3 +###################################################################### +# +# Output get_status info in CSV format. +# +# This script pulls the current status once and prints to stdout. +# +###################################################################### import grpc import spacex.api.device.device_pb2 import spacex.api.device.device_pb2_grpc +import datetime + with grpc.insecure_channel('192.168.100.1:9200') as channel: stub = spacex.api.device.device_pb2_grpc.DeviceStub(channel) response = stub.Handle(spacex.api.device.device_pb2.Request(get_status={})) +timestamp = datetime.datetime.utcnow() + status = response.dish_get_status # More alerts may be added in future, so rather than list them individually, @@ -16,7 +27,8 @@ alert_bits = 0 for alert in status.alerts.ListFields(): alert_bits |= (1 if alert[1] else 0) << (alert[0].number - 1) -print(",".join([status.device_info.id, status.device_info.hardware_version, status.device_info.software_version, +print(",".join([timestamp.replace(microsecond=0).isoformat(), status.device_info.id, + status.device_info.hardware_version, status.device_info.software_version, spacex.api.device.dish_pb2.DishState.Name(status.state)]) + "," + ",".join(str(x) for x in [status.device_state.uptime_s, status.snr, status.seconds_to_first_nonempty_slot, status.pop_ping_drop_rate, status.downlink_throughput_bps, status.uplink_throughput_bps, diff --git a/dishStatusInflux.py b/dishStatusInflux.py index 7afa3f9..e39150c 100644 --- a/dishStatusInflux.py +++ b/dishStatusInflux.py @@ -1,4 +1,12 @@ #!/usr/bin/python3 +###################################################################### +# +# Write get_status info to an InfluxDB database. +# +# This script will periodically poll current status and write it to +# the specified InfluxDB database in a loop. +# +###################################################################### from influxdb import InfluxDBClient from influxdb import SeriesHelper diff --git a/dishStatusMqtt.py b/dishStatusMqtt.py index 9b2c52c..a0993cc 100644 --- a/dishStatusMqtt.py +++ b/dishStatusMqtt.py @@ -1,4 +1,12 @@ #!/usr/bin/python3 +###################################################################### +# +# Publish get_status info to a MQTT broker. +# +# This script pulls the current status once and publishes it to the +# specified MQTT broker. +# +###################################################################### import paho.mqtt.publish import grpc