No description
Find a file
sparky8512 b06a5973c1 Change default database name to starlinkstats
The README instructions @neurocis  added for the Docker container recommend this name, and I like that better than dishstats, so now it's the default.

"dish" can be useful to differentiate between the Starlink user terminal (dish) and the Starlink router, both of which expose gRPC services for polling status information, but that's more applicable to the measurement name (AKA series_name) and a hypothetical database that contained both would be more appropriately labelled "Starlink".
2021-01-11 13:03:19 -08:00
dishDumpStatus.py Readability improvements (or so PEP 8 style guide claims...) 2021-01-06 10:12:56 -08:00
dishHistoryInflux.py Change default database name to starlinkstats 2021-01-11 13:03:19 -08:00
dishHistoryMqtt.py SSL/TLS support for InfluxDB and MQTT scripts 2021-01-10 21:36:44 -08:00
dishHistoryStats.py Add InfluxDB and MQTT history stats scripts 2021-01-09 12:03:37 -08:00
dishStatusCsv.py SSL/TLS support for InfluxDB and MQTT scripts 2021-01-10 21:36:44 -08:00
dishStatusInflux.py Change default database name to starlinkstats 2021-01-11 13:03:19 -08:00
dishStatusMqtt.py SSL/TLS support for InfluxDB and MQTT scripts 2021-01-10 21:36:44 -08:00
Dockerfile Update Dockerfile 2021-01-10 23:41:44 -08:00
entrypoint.sh Update entrypoint.sh 2021-01-10 23:57:06 -08:00
get_history_notes.txt Initial upload of history parser and notes file 2020-12-22 15:51:37 -08:00
LICENSE Initial commit 2020-12-22 14:40:56 -08:00
parseJsonHistory.py Add InfluxDB and MQTT history stats scripts 2021-01-09 12:03:37 -08:00
README.md Update README.md 2021-01-11 00:01:50 -08:00
starlink_grpc.py Add InfluxDB and MQTT history stats scripts 2021-01-09 12:03:37 -08:00
starlink_json.py Small change to the interface between parser and calling scripts 2021-01-08 19:17:34 -08:00

starlink-grpc-tools

This repository has a handful of tools for interacting with the gRPC service implemented on the Starlink user terminal (AKA "the dish").

For more information on what Starlink is, see starlink.com and/or the r/Starlink subreddit.

Prerequisites

parseJsonHistory.py operates on a JSON format data representation of the protocol buffer messages, such as that output by gRPCurl. The command lines below assume grpcurl is installed in the runtime PATH. If that's not the case, just substitute in the full path to the command.

All the tools that pull data from the dish expect to be able to reach it at the dish's fixed IP address of 192.168.100.1, as do the Starlink Android app and iOS app. When using a router other than the one included with the Starlink installation kit, this usually requires some additional router configuration to make it work. That configuration is beyond the scope of this document, but if the Starlink app doesn't work on your home network, then neither will these scripts. That being said, you do not need the Starlink app installed to make use of these scripts.

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 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 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 on the server to map the 1.x username, password, and database names to their 2.0 equivalents.

Usage

parseJsonHistory.py takes input from a file and writes its output to standard output. The easiest way to use it is to pipe the grpcurl command directly into it. For example:

grpcurl -plaintext -d {\"get_history\":{}} 192.168.100.1:9200 SpaceX.API.Device.Device/Handle | python parseJsonHistory.py

For more usage options, run:

python parseJsonHistory.py -h

When used as-is, parseJsonHistory.py will summarize packet loss information from the data the dish records. There's other bits of data in there, though, so that script (or more likely the parsing logic it uses, which now resides in starlink_json.py) could be used as a starting point or example of how to iterate through it. Most of the data displayed in the Statistics page of the Starlink app appears to come from this same get_history gRPC response. See the file get_history_notes.txt for some ramblings on how to interpret it.

The other scripts can do the gRPC communication directly, but they require some generated code to support the specific gRPC protocol messages used. These would normally be generated from .proto files that specify those messages, but to date (2020-Dec), SpaceX has not publicly released such files. The gRPC service running on the dish appears to have server reflection enabled, though. grpcurl can use that to extract a protoset file, and the protoc compiler can use that to make the necessary generated code:

grpcurl -plaintext -protoset-out dish.protoset 192.168.100.1:9200 describe SpaceX.API.Device.Device
mkdir src
cd src
python3 -m grpc_tools.protoc --descriptor_set_in=../dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/device.proto
python3 -m grpc_tools.protoc --descriptor_set_in=../dish.protoset --python_out=. --grpc_python_out=. spacex/api/common/status/status.proto
python3 -m grpc_tools.protoc --descriptor_set_in=../dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/command.proto
python3 -m grpc_tools.protoc --descriptor_set_in=../dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/common.proto
python3 -m grpc_tools.protoc --descriptor_set_in=../dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/dish.proto
python3 -m grpc_tools.protoc --descriptor_set_in=../dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi.proto
python3 -m grpc_tools.protoc --descriptor_set_in=../dish.protoset --python_out=. --grpc_python_out=. spacex/api/device/wifi_config.proto

Then move the resulting files to where the Python scripts can find them.

Once those are available, the dishHistoryStats.py script can be used in place of the grpcurl | parseJsonHistory.py pipeline, with most of the same command line options.

To collect and record summary stats every hour, you can put something like the following in your user crontab:

00 * * * * [ -e ~/dishStats.csv ] || ~/bin/dishHistoryStats.py -H >~/dishStats.csv; ~/bin/dishHistoryStats.py >>~/dishStats.csv

dishHistoryInflux.py and dishHistoryMqtt.py are similar, but they send their output to an InfluxDB server and a MQTT broker, respectively. Run them with -h command line option for details on how to specify server and/or database options.

dishDumpStatus.py is even simpler. Just run it as:

python3 dishDumpStatus.py

and revel in copious amounts of dish status information. OK, maybe it's not as impressive as all that. This one is really just meant to be a starting point for real functionality to be added to it. The information this script pulls is mostly what appears related to the dish in the Debug Data section of the Starlink app.

dishStatusCsv.py, dishStatusInflux.py, and dishStatusMqtt.py output the same status data, but to various data backends. As with the corresponding history scripts, run them with -h command line option for usage details.

To Be Done (Maybe)

There are reboot and dish_stow requests in the Device protocol, too, so it should be trivial to write a command that initiates dish reboot and stow operations. These are easy enough to do with grpcurl, though, as there is no need to parse through the response data. For that matter, they're easy enough to do with the Starlink app.

Other Tidbits

The Starlink Android app actually uses port 9201 instead of 9200. Both appear to expose the same gRPC service, but the one on port 9201 uses an HTTP/1.1 wrapper, whereas the one on port 9200 uses HTTP/2.0, which is what most gRPC tools expect.

The Starlink router also exposes a gRPC service, on ports 9000 (HTTP/2.0) and 9001 (HTTP/1.1).

Docker for InfluxDB ( & MQTT under development )

Initialization of the container can be performed with the following command:

docker run -d --name='starlink-grpc-tools' -e INFLUXDB_HOST={InfluxDB Hostname} \
    -e INFLUXDB_PORT={Port, 8086 usually} \
    -e INFLUXDB_USER={Optional, InfluxDB Username} \
    -e INFLUXDB_PWD={Optional, InfluxDB Password} \
    -e INFLUXDB_DB={Pre-created DB name, starlinkstats works well} \
    neurocis/starlink-grpc-tools dishStatusInflux.py -v

dishStatusInflux.py -v is optional and will run same but not -verbose, or you can replace it with one of the other scripts if you wish to run that instead. I (neurocis) will push a Grafana dashboard in the near future, or please create and share your own.