diff --git a/samples/shadow.py b/samples/shadow.py index 2d61e8d2..6540ad99 100644 --- a/samples/shadow.py +++ b/samples/shadow.py @@ -245,7 +245,7 @@ def user_input_thread_fn(): http_proxy_options=proxy_options, ca_filepath=args.root_ca, client_id=args.client_id, - clean_session=False, + clean_session=True, keep_alive_secs=6) else: @@ -256,7 +256,7 @@ def user_input_thread_fn(): client_bootstrap=client_bootstrap, ca_filepath=args.root_ca, client_id=args.client_id, - clean_session=False, + clean_session=True, keep_alive_secs=6, http_proxy_options=proxy_options) @@ -279,15 +279,6 @@ def user_input_thread_fn(): # Subscribe to necessary topics. # Note that is **is** important to wait for "accepted/rejected" subscriptions # to succeed before publishing the corresponding "request". - print("Subscribing to Delta events...") - delta_subscribed_future, _ = shadow_client.subscribe_to_shadow_delta_updated_events( - request=iotshadow.ShadowDeltaUpdatedSubscriptionRequest(thing_name=args.thing_name), - qos=mqtt.QoS.AT_LEAST_ONCE, - callback=on_shadow_delta_updated) - - # Wait for subscription to succeed - delta_subscribed_future.result() - print("Subscribing to Update responses...") update_accepted_subscribed_future, _ = shadow_client.subscribe_to_update_shadow_accepted( request=iotshadow.UpdateShadowSubscriptionRequest(thing_name=args.thing_name), @@ -318,6 +309,15 @@ def user_input_thread_fn(): get_accepted_subscribed_future.result() get_rejected_subscribed_future.result() + print("Subscribing to Delta events...") + delta_subscribed_future, _ = shadow_client.subscribe_to_shadow_delta_updated_events( + request=iotshadow.ShadowDeltaUpdatedSubscriptionRequest(thing_name=args.thing_name), + qos=mqtt.QoS.AT_LEAST_ONCE, + callback=on_shadow_delta_updated) + + # Wait for subscription to succeed + delta_subscribed_future.result() + # The rest of the sample runs asyncronously. # Issue request for shadow's current state.