Add simple script to reboot, stow, or unstow dish

As reported in issue #43, the unstow operation is not quite as straightforward to perform using grpcurl as reboot or stow.

This also serves as a simplified example of using reflection (via yagrc) to perform grpc operations on the dish.
This commit is contained in:
sparky8512 2022-04-19 11:17:14 -07:00
parent f08682af30
commit e01aea6bd4
2 changed files with 64 additions and 3 deletions

View file

@ -75,6 +75,16 @@ python3 dish_obstruction_map.py -t 3600 obstructions_%s.png
Run it with the `-h` command line option for full usage details, including control of the map colors and color modes.
#### Reboot and stow control
`dish_control.sh` is a simple stand alone script that can issue reboot, stow, or unstow commands to the dish:
```shell script
python3 dish_control.py reboot
python3 dish_control.py stow
python3 dish_control.py unstow
```
These operations can also be done using `grpcurl`, thus avoiding the need to use Python or install the required Python module dependencies. See [here](https://github.com/sparky8512/starlink-grpc-tools/wiki/Useful-grpcurl-commands) for specific `grpcurl` commands for these operations.
### The JSON parser script
`dish_json_text.py` operates on a JSON format data representation of the protocol buffer messages, such as that output by [gRPCurl](https://github.com/fullstorydev/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.
@ -96,7 +106,7 @@ The one bit of functionality this script has over the grpc scripts is that it su
```shell script
python3 dump_dish_status.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.
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 grpc example in this script assumes you have the [generated gRPC protocol modules](https://github.com/sparky8512/starlink-grpc-tools/wiki/gRPC-Protocol-Modules). For a (relatively) simple example of using reflection to avoid that requirement, see `dish_control.py`.
`poll_history.py` is another silly example, but this one illustrates how to periodically poll the status and/or bulk history data using the `starlink_grpc` module's API. It's not really useful by itself, but if you really want to, you can run it as:
```shell script
@ -181,8 +191,6 @@ Note that feeding a dashboard will likely need the `-t` script option to `dish_g
The [Wiki for this GitHub project](https://github.com/sparky8512/starlink-grpc-tools/wiki) has a little more information, and was originally planned to have more detail on some aspects of the history data, but that's mostly been obsoleted by changes to the gRPC service. It still may be updated some day with more use case examples or other information. In the mean time, it is configured as editable by anyone with a GitHub login, so if you have relevant content you believe to be useful, feel free to add it.
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.
No further data collection functionality is planned at this time. If there's something you'd like to see added, please feel free to open a feature request issue. Bear in mind, though, that functionality will be limited to that which the Starlink gRPC services support. In general, those services are limited to what is required by the Starlink app, so unless the app has some related feature, it is unlikely the gRPC services will be sufficient to implement it in these tools.
## Related Projects

53
dish_control.py Normal file
View file

@ -0,0 +1,53 @@
#!/usr/bin/python3
"""Manipulate operating state of a Starlink user terminal."""
import argparse
import logging
import sys
import grpc
from yagrc import reflector as yagrc_reflector
def parse_args():
parser = argparse.ArgumentParser(description="Starlink user terminal state control")
parser.add_argument("command", choices=["reboot", "stow", "unstow"])
parser.add_argument("-e",
"--target",
default="192.168.100.1:9200",
help="host:port of dish to query, default is the standard IP address "
"and port (192.168.100.1:9200)")
return parser.parse_args()
def main():
opts = parse_args()
logging.basicConfig(format="%(levelname)s: %(message)s")
reflector = yagrc_reflector.GrpcReflectionClient()
try:
with grpc.insecure_channel(opts.target) as channel:
reflector.load_protocols(channel, symbols=["SpaceX.API.Device.Device"])
request_class = reflector.message_class("SpaceX.API.Device.Request")
if opts.command == "reboot":
request = request_class(reboot={})
elif opts.command == "stow":
request = request_class(dish_stow={})
else: # unstow
request = request_class(dish_stow={"unstow": True})
stub = reflector.service_stub_class("SpaceX.API.Device.Device")(channel)
response = stub.Handle(request, timeout=10)
except grpc.RpcError as e:
if isinstance(e, grpc.Call):
msg = e.details()
else:
msg = "Unknown communication or service error"
logging.error(msg)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':
main()