API¶
Async Object¶
-
class
mbed_connector_api.asyncResult(callback='')¶ AsyncResult objects returned by all mbed_connector_api library calls. Make sure to check the
.isDone()function and the.errorvariable before accessing the.resultvariable.Variables: - error – False if no error, if error then populated by :class:’connectorError.response_codes` object
- result – initial value: {}
- status_code – status code returned from REST request
- raw_data – raw returned object form the request
Connector API¶
-
class
mbed_connector_api.connector(token, webAddress='https://api.connector.mbed.com', port='80')¶ Interface class to use the connector.mbed.com REST API. This class will by default handle asyncronous events. All function return :class:’.asyncResult’ objects
-
debug(onOff, level='DEBUG')¶ Enable / Disable debugging
Parameters: onOff (bool) – turn debugging on / off Returns: none
-
deleteAllSubscriptions()¶ Delete all subscriptions on the domain (all endpoints, all resources)
Returns: successful .status_code/.is_done. Check the.errorReturn type: asyncResult
-
deleteCallback()¶ Delete the Callback URL currently registered with Connector.
Returns: successful .status_code/.is_done. Check the.errorReturn type: asyncResult
-
deleteEndpoint(ep, cbfn='')¶ Send DELETE message to an endpoint.
Parameters: - ep (str) – name of endpoint
- cbfn (fnptr) – Optional - callback funtion to call when operation is completed
Returns: successful
.status_code/.is_done. Check the.errorReturn type:
-
deleteEndpointSubscriptions(ep)¶ Delete all subscriptions on specified endpoint
epParameters: ep (str) – name of endpoint Returns: successful .status_code/.is_done. Check the.errorReturn type: asyncResult
-
deleteResourceSubscription(ep, res)¶ Delete subscription to a resource
reson an endpointepParameters: Returns: successful
.status_code/.is_done. Check the.errorReturn type:
-
getApiVersions()¶ Get the REST API versions that connector accepts.
Returns: :class:asyncResult object, populates error and result fields Return type: asyncResult
-
getCallback()¶ Get the callback URL currently registered with Connector.
Returns: callback url in .result, error if applicable in.errorReturn type: asyncResult
-
getConnectorVersion()¶ GET the current Connector version.
Returns: asyncResult object, populates error and result fields Return type: asyncResult
-
getEndpointSubscriptions(ep)¶ Get list of all subscriptions on a given endpoint
epParameters: ep (str) – name of endpoint Returns: successful .status_code/.is_done. Check the.errorReturn type: asyncResult
-
getEndpoints(typeOfEndpoint='')¶ Get list of all endpoints on the domain.
Parameters: typeOfEndpoint (str) – Optional filter endpoints returned by type Returns: list of all endpoints Return type: asyncResult
-
getLimits()¶ return limits of account in async result object.
Returns: asyncResult object, populates error and result fields Return type: asyncResult
-
getPreSubscription()¶ Get the current pre-subscription data from connector
Returns: JSON that represents the pre-subscription data in the .resultfieldReturn type: asyncResult
-
getResourceSubscription(ep, res)¶ Get list of all subscriptions for a resource
reson an endpointepParameters: Returns: successful
.status_code/.is_done. Check the.errorReturn type:
-
getResourceValue(ep, res, cbfn='', noResp=False, cacheOnly=False)¶ Get value of a specific resource on a specific endpoint.
Parameters: Returns: value of the resource, usually a string
Return type:
-
getResources(ep, noResp=False, cacheOnly=False)¶ Get list of resources on an endpoint.
Parameters: Returns: list of resources
Return type:
-
handler(data)¶ Function to handle notification data as part of Callback URL handler.
Parameters: data (str) – data posted to Callback URL by connector. Returns: nothing
-
postResource(ep, res, data='', cbfn='')¶ POST data to a resource on an endpoint.
Parameters: Returns: successful
.status_code/.is_done. Check the.errorReturn type:
-
putCallback(url, headers='')¶ Set the callback URL. To be used in place of LongPolling when deploying a webapp.
note: make sure you set up a callback URL in your web app
Parameters: Returns: successful
.status_code/.is_done. Check the.errorReturn type:
-
putPreSubscription(JSONdata)¶ Set pre-subscription rules for all endpoints / resources on the domain. This can be useful for all current and future endpoints/resources.
Parameters: JSONdata (json) – data to use as pre-subscription data. Wildcards are permitted Returns: successful .status_code/.is_done. Check the.errorReturn type: asyncResult
-
putResourceSubscription(ep, res, cbfn='')¶ Subscribe to changes in a specific resource
reson an endpointepParameters: Returns: successful
.status_code/.is_done. Check the.errorReturn type:
-
putResourceValue(ep, res, data, cbfn='')¶ Put a value to a resource on an endpoint
Parameters: Returns: successful
.status_code/.is_done. Check the.errorReturn type:
-
setHandler(handler, cbfn)¶ Register a handler for a particular notification type. These are the types of notifications that are acceptable.
‘async-responses’‘registrations-expired’‘de-registrations’‘reg-updates’‘registrations’‘notifications’Parameters: - handler (str) – name of the notification type
- cbfn (fnptr) – function to pass the notification channel messages to.
Returns: Nothing.
-
startLongPolling(noWait=False)¶ Start LongPolling Connector for notifications.
Parameters: noWait (bool) – Optional - use the cached values in connector, do not wait for the device to respond Returns: Thread of constantly running LongPoll. To be used to kill the thred if necessary. Return type: pythonThread
-
stopLongPolling()¶ Stop LongPolling thread
Returns: none
-