Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: simple-mbed-client
Fork of simple-mbed-client-example by
Diff: source/main.cpp
- Revision:
- 40:6c039d073c0b
- Parent:
- 38:fbbab77b54fb
--- 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);
