Catch GrpcError in new example

Apparently, it was a little _too_ simple.

Also, update the description for seconds_to_first_nonempty_slot field to reflect some behavior this script was able to capture.
This commit is contained in:
sparky8512 2021-02-02 09:07:42 -08:00
parent f5f1bbdb84
commit ed2ef50581
2 changed files with 38 additions and 29 deletions

View file

@ -25,37 +25,43 @@ def run_loop(context):
counter = None counter = None
prev_triggered = False prev_triggered = False
while True: while True:
# `starlink_grpc.status_data` returns a tuple of 3 dicts, but in case try:
# the API changes to add more in the future, it's best to reference # `starlink_grpc.status_data` returns a tuple of 3 dicts, but in case
# them by index instead of direct assignment from the function call. # the API changes to add more in the future, it's best to reference
groups = starlink_grpc.status_data(context=context) # them by index instead of direct assignment from the function call.
status = groups[0] groups = starlink_grpc.status_data(context=context)
status = groups[0]
# On the other hand, `starlink_grpc.history_bulk_data` will always # On the other hand, `starlink_grpc.history_bulk_data` will always
# return 2 dicts, because that's all the data there is. # return 2 dicts, because that's all the data there is.
general, bulk = starlink_grpc.history_bulk_data(samples, start=counter, context=context) general, bulk = starlink_grpc.history_bulk_data(samples, start=counter, context=context)
except starlink_grpc.GrpcError:
# Dish rebooting maybe, or LAN connectivity error. Just ignore it
# and hope it goes away.
pass
else:
# The following is what actually does stuff with the data. It should
# be replaced with something more useful.
# The following is what actually does stuff with the data. It should # This computes a trigger detecting any packet loss (ping drop):
# be replaced with something more useful. #triggered = any(x > 0 for x in bulk["pop_ping_drop_rate"])
# This computes a trigger detecting samples marked as obstructed:
#triggered = any(bulk["obstructed"])
# This computes a trigger detecting samples not marked as scheduled:
triggered = not all(bulk["scheduled"])
if triggered or prev_triggered:
print("Triggered" if triggered else "Continued", "at:",
datetime.now(tz=timezone.utc))
print("status:", status)
print("history:", bulk)
if not triggered:
print()
# This computes a trigger detecting any packet loss (ping drop): prev_triggered = triggered
#triggered = any(x > 0 for x in bulk["pop_ping_drop_rate"]) # The following makes the next loop only pull the history samples that
# This computes a trigger detecting samples marked as obstructed: # are newer than the ones already examined.
#triggered = any(bulk["obstructed"]) samples = -1
# This computes a trigger detecting samples not marked as scheduled: counter = general["end_counter"]
triggered = not all(bulk["scheduled"])
if triggered or prev_triggered:
print("Triggered" if triggered else "Continued", "at:", datetime.now(tz=timezone.utc))
print("status:", status)
print("history:", bulk)
if not triggered:
print()
prev_triggered = triggered
# The following makes the next loop only pull the history samples that
# are newer than the ones already examined.
samples = -1
counter = general["end_counter"]
# And this is a not-very-robust way of implementing an interval loop. # And this is a not-very-robust way of implementing an interval loop.
# Note that a 4 second loop will poll the history buffer pretty # Note that a 4 second loop will poll the history buffer pretty

View file

@ -39,7 +39,10 @@ This group holds information about the current state of the user terminal.
: **snr** : Most recent sample value. See bulk history data for detail. : **snr** : Most recent sample value. See bulk history data for detail.
: **seconds_to_first_nonempty_slot** : Amount of time from now, in seconds, : **seconds_to_first_nonempty_slot** : Amount of time from now, in seconds,
until a satellite will be scheduled to be available for transmit/receive. until a satellite will be scheduled to be available for transmit/receive.
See also *scheduled* in the bulk history data. See also *scheduled* in the bulk history data. May report as a negative
number, which appears to indicate unknown time until next satellite
scheduled and usually correlates with *state* reporting as other than
"CONNECTED".
: **pop_ping_drop_rate** : Most recent sample value. See bulk history data for : **pop_ping_drop_rate** : Most recent sample value. See bulk history data for
detail. detail.
: **downlink_throughput_bps** : Most recent sample value. See bulk history : **downlink_throughput_bps** : Most recent sample value. See bulk history