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 .error variable before accessing the .result variable.

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
isDone()
Returns:True / False based on completion of async operation
Return type:bool

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 .error
Return type:asyncResult
deleteCallback()

Delete the Callback URL currently registered with Connector.

Returns:successful .status_code / .is_done. Check the .error
Return 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 .error

Return type:

asyncResult

deleteEndpointSubscriptions(ep)

Delete all subscriptions on specified endpoint ep

Parameters:ep (str) – name of endpoint
Returns:successful .status_code / .is_done. Check the .error
Return type:asyncResult
deleteResourceSubscription(ep, res)

Delete subscription to a resource res on an endpoint ep

Parameters:
  • ep (str) – name of endpoint
  • res (str) – name of resource
Returns:

successful .status_code / .is_done. Check the .error

Return type:

asyncResult

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 .error
Return 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 ep

Parameters:ep (str) – name of endpoint
Returns:successful .status_code / .is_done. Check the .error
Return 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 .result field
Return type:asyncResult
getResourceSubscription(ep, res)

Get list of all subscriptions for a resource res on an endpoint ep

Parameters:
  • ep (str) – name of endpoint
  • res (str) – name of resource
Returns:

successful .status_code / .is_done. Check the .error

Return type:

asyncResult

getResourceValue(ep, res, cbfn='', noResp=False, cacheOnly=False)

Get value of a specific resource on a specific endpoint.

Parameters:
  • ep (str) – name of endpoint
  • res (str) – name of resource
  • cbfn (fnptr) – Optional - callback function to be called on completion
  • noResp (bool) – Optional - specify no response necessary from endpoint
  • cacheOnly (bool) – Optional - get results from cache on connector, do not wake up endpoint
Returns:

value of the resource, usually a string

Return type:

asyncResult

getResources(ep, noResp=False, cacheOnly=False)

Get list of resources on an endpoint.

Parameters:
  • ep (str) – Endpoint to get the resources of
  • noResp (bool) – Optional - specify no response necessary from endpoint
  • cacheOnly (bool) – Optional - get results from cache on connector, do not wake up endpoint
Returns:

list of resources

Return type:

asyncResult

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:
  • ep (str) – name of endpoint
  • res (str) – name of resource
  • data (str) – Optional - data to send via POST
  • cbfn (fnptr) – Optional - callback funtion to call when operation is completed
Returns:

successful .status_code / .is_done. Check the .error

Return type:

asyncResult

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:
  • url (str) – complete url, including port, where the callback url is located
  • headers (str) – Optional - Headers to have Connector send back with all calls
Returns:

successful .status_code / .is_done. Check the .error

Return type:

asyncResult

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 .error
Return type:asyncResult
putResourceSubscription(ep, res, cbfn='')

Subscribe to changes in a specific resource res on an endpoint ep

Parameters:
  • ep (str) – name of endpoint
  • res (str) – name of resource
  • cbfn (fnptr) – Optional - callback funtion to call when operation is completed
Returns:

successful .status_code / .is_done. Check the .error

Return type:

asyncResult

putResourceValue(ep, res, data, cbfn='')

Put a value to a resource on an endpoint

Parameters:
  • ep (str) – name of endpoint
  • res (str) – name of resource
  • data (str) – data to send via PUT
  • cbfn (fnptr) – Optional - callback funtion to call when operation is completed
Returns:

successful .status_code / .is_done. Check the .error

Return type:

asyncResult

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

Error Object