2020-12-22 22:16:33 -06:00
|
|
|
#!/usr/bin/python3
|
2021-02-04 22:02:45 -06:00
|
|
|
"""Simple example of get_status request using grpc call directly."""
|
2021-02-01 22:47:18 -06:00
|
|
|
|
2022-08-17 15:59:22 -05:00
|
|
|
import sys
|
|
|
|
|
2020-12-22 22:16:33 -06:00
|
|
|
import grpc
|
|
|
|
|
2022-08-17 15:59:22 -05:00
|
|
|
try:
|
|
|
|
from spacex.api.device import device_pb2
|
|
|
|
from spacex.api.device import device_pb2_grpc
|
|
|
|
except ModuleNotFoundError:
|
2022-09-14 14:55:50 -05:00
|
|
|
print("This script requires the generated gRPC protocol modules. See README file for details.",
|
2022-08-17 15:59:22 -05:00
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2020-12-22 22:16:33 -06:00
|
|
|
|
2022-12-01 19:50:29 -06:00
|
|
|
def wrap_ser(self, **kwargs):
|
|
|
|
ret = device_pb2.Request.SerializeToString(self, **kwargs)
|
|
|
|
print("request:", ret)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def wrap_des(s):
|
|
|
|
print("response:", s)
|
|
|
|
#return "Hello"
|
|
|
|
return device_pb2.Response.FromString(s)
|
|
|
|
|
2020-12-30 12:17:02 -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.
|
2021-01-06 12:12:56 -06:00
|
|
|
with grpc.insecure_channel("192.168.100.1:9200") as channel:
|
2022-12-01 19:50:29 -06:00
|
|
|
method = channel.unary_unary('/SpaceX.API.Device.Device/Handle',
|
|
|
|
request_serializer=wrap_ser,
|
|
|
|
response_deserializer=None
|
|
|
|
#response_deserializer=wrap_des
|
|
|
|
)
|
|
|
|
response = method(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
|
|
|
|
2021-02-01 22:47:18 -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
|
|
|
|
2021-02-01 22:47:18 -06:00
|
|
|
# Check if connected
|
2022-05-25 18:41:07 -05:00
|
|
|
print("Not connected" if response.dish_get_status.HasField("outage") else "Connected")
|