starlink-grpc-tools/starlink_grpc_tools/dump_dish_status.py

32 lines
975 B
Python
Raw Normal View History

2020-12-22 22:16:33 -06:00
#!/usr/bin/python3
"""Simple example of get_status request using grpc call directly."""
import sys
2020-12-22 22:16:33 -06:00
import grpc
try:
from spacex.api.device import device_pb2
from spacex.api.device import device_pb2_grpc
except ModuleNotFoundError:
2023-08-31 22:15:04 -05:00
print(
"This script requires the generated gRPC protocol modules. See README file for details.",
file=sys.stderr,
)
sys.exit(1)
2020-12-22 22:16:33 -06:00
# Note that if you remove the 'with' clause here, you need to separately
# call channel.close() when you're done with the gRPC connection.
with grpc.insecure_channel("192.168.100.1:9200") as channel:
stub = device_pb2_grpc.DeviceStub(channel)
response = stub.Handle(device_pb2.Request(get_status={}), timeout=10)
2020-12-22 22:16:33 -06:00
2020-12-23 09:25:30 -06:00
# Dump everything
2020-12-22 22:16:33 -06:00
print(response)
2020-12-23 09:25:30 -06:00
# Just the software version
print("Software version:", response.dish_get_status.device_info.software_version)
2020-12-23 09:25:30 -06:00
# Check if connected
print("Not connected" if response.dish_get_status.HasField("outage") else "Connected")