PelionIoT / mbed-connector-api-python

python library for using connector.mbed.com
Apache License 2.0
2 stars 2 forks source link

Need example of how to use web app + long polling #13

Closed janjongboom closed 8 years ago

janjongboom commented 8 years ago

I have the following code and half the time my requests to Connector don't work with it...

if __name__ == "__main__":
    connector.startLongPolling()
    connector.setHandler('notifications', notificationHandler) # send 'notifications' to the notificationHandler FN
    bla = connector.putResourceSubscription('38e7a161-1932-4da1-a76e-39e9999ad258', KNOCK_RESOURCE)
    while not bla.isDone():
        None
    if bla.error:
        raise Error(bla.error)
    app = web.application(urls, globals())
    app.run()

This all goes fine, but when I do a request to Connector it never completes.

Then I restart and suddenly it works (and vice-versa).

Using connector via:

        e = connector.getResourceValue(id, KNOCK_RESOURCE)
        while not e.isDone():
            None
        if e.error:
            raise Error(e.error)
        pprint.pprint(e.raw_data)
janjongboom commented 8 years ago

Let's take this in #14

BlackstoneEngineering commented 8 years ago

In the docs there is an example of how to use long polling. more robust examples are coming soon.