def my_application(api):
    """An example application.

    - Registers a webhook with mbed cloud services
    - Requests the value of a resource
    - Prints the value when it arrives
    """
    device = api.list_connected_devices().first()
    print('using device #', device.id)
    api.delete_device_subscriptions(device.id)

    try:
        print('setting webhook url to:', ngrok_url)
        api.update_webhook(ngrok_url)
        print('requesting resource value for:', resource_path)
        deferred = api.get_resource_value_async(device_id=device.id, resource_path=resource_path)
        print('waiting for async #', deferred.async_id)
        result = deferred.wait(15)
        print('webhook sent us this payload value:', repr(result))
        return result
    except Exception:
        print(traceback.format_exc())
    finally:
        api.delete_webhook()
        print("Deregistered and unsubscribed from all resources. Exiting.")
        exit(1)
def my_application ( api ) : device = api . list_connected_devices ( ) . first ( ) print ( 'using device #' , device . id ) api . delete_device_subscriptions ( device . id ) try : print ( 'setting webhook url to:' , ngrok_url ) api . update_webhook ( ngrok_url ) print ( 'requesting resource value for:' , resource_path ) deferred = api . get_resource_value_async ( device_id = device . id , resource_path = resource_path ) print ( 'waiting for async #' , deferred . async_id ) result = deferred . wait ( 15 ) print ( 'webhook sent us this payload value:' , repr ( result ) ) return result except Exception : print ( traceback . format_exc ( ) ) finally : api . delete_webhook ( ) print ( "Deregistered and unsubscribed from all resources. Exiting." ) exit ( 1 )
An example application.

    - Registers a webhook with mbed cloud services
    - Requests the value of a resource
    - Prints the value when it arrives