Example program for simple-mbed-client, connecting a device to mbed Device Connector.
Dependencies: C12832 FXOS8700Q simple-mbed-client
Fork of simple-mbed-client-example by
Diff: source/main.cpp
- Revision:
- 40:6c039d073c0b
- Parent:
- 38:fbbab77b54fb
- Child:
- 44:5a1db9f98f5f
--- a/source/main.cpp Tue Feb 07 13:03:04 2017 +0100 +++ b/source/main.cpp Tue Feb 07 17:22:37 2017 +0100 @@ -61,12 +61,6 @@ connectivityLed = BUILTIN_LED_ON; } -void play_from_cloud(void* args) { - // play is a blocking function, so run this on the events thread instead of the main thread - // (otherwise the device is not accessible while playing) - client.eventQueue()->call(&play, args); -} - int main() { // SimpleClient gives us an event queue which we can use, running on a separate thread (see https://docs.mbed.com/docs/mbed-os-handbook/en/5.1/concepts/events/) EventQueue* eventQueue = client.eventQueue(); @@ -77,8 +71,8 @@ // Toggle the built-in LED every second (until we're connected, see `registered` function) connectivityTicker.attach(eventQueue->event(&toggleConnectivityLed), 1.0f); - // Functions can be executed through mbed Device Connector via POST calls - client.define_function("led/0/play", &play_from_cloud); + // Functions can be executed through mbed Device Connector via POST calls (also defer to the event thread, so we never block) + client.define_function("led/0/play", eventQueue->event(&play)); // Connect to the internet (see mbed_app.json for the connectivity method) NetworkInterface* network = easy_connect(true);