def test_subscribe_resources(self): import logging logging.basicConfig(level=logging.DEBUG) # an example: subscribing to resource value changes # creates an Observer listening to resource value changes for devices # whose id starts with `016` and resource paths start with `/3/0/` from mbed_cloud import ConnectAPI api = ConnectAPI() # prepare a channel channel = api.subscribe.channels.ResourceValues(device_id='016*', resource_path='/3/0/*') # start listening for updates observer = api.subscribe(channel) # on the first update for the channel, block for the specified timeout print(observer.next().block(timeout=120000))
def test_subscribe_device_state(self): # an example: subscribing to device state changes # creates an Observer listening to device state changes for devices # whose id starts with `016` from mbed_cloud import ConnectAPI api = ConnectAPI() # prepare a channel channel = api.subscribe.channels.DeviceStateChanges( device_id='016*', # here, `channel` refers to the filterable device state received from # the notification system channel=[ api.subscribe.channels.ChannelIdentifiers.registrations, api.subscribe.channels.ChannelIdentifiers.registrations_expired ] ) # start listening for updates observer = api.subscribe(channel) # on the first update for the channel, block for the specified timeout print(observer.next().block(timeout=120000))
def test_subscribe(self): # an example: subscribe to resource values from mbed_cloud import ConnectAPI # Create an instance of the Connect API connect_api = ConnectAPI() # Configure a subscription to receive resource value changes on all devices channel = connect_api.subscribe.channels.ResourceValues(device_id="*") # Contact Pelion Device Management to actually make the configured subscription observer = connect_api.subscribe(channel) # Print the subscription notifications received while True: print(observer.next().block()) # end of example break connect_api.subscribe.unsubscribe_all()