diff --git a/examples/openthread/main.c b/examples/openthread/main.c index facd03fb61..a4bd1341fb 100644 --- a/examples/openthread/main.c +++ b/examples/openthread/main.c @@ -16,15 +16,37 @@ #include #include "ot.h" +#include "openthread/thread.h" + +static void _panid_handler(event_t *event); + +static event_t event_panid = { + .handler = _panid_handler +}; + +static void _panid_handler(event_t *event) +{ + (void) event; + + /* It's safe here to call any OpenThread specific API, since this code runs + * in the same thread as the OpenThread tasklet handler */ + + /* Get PanID from OpenThread API */ + uint16_t panid = otLinkGetPanId(openthread_get_instance()); + printf("Current panid: 0x%x\n", panid); +} int main(void) { - puts("This a test for OpenThread"); /* Example of how to call OpenThread stack functions */ - puts("Get PANID "); - uint16_t panid = 0; - uint8_t res = ot_call_command("panid", NULL, (void*)&panid); - printf("Current panid: 0x%x (res:%x)\n", panid, res); + puts("This is an OpenThread example"); + + /** OpenThread needs to synchronize otApi calls + * with its tasklet scheduler. This + * synchronization is handled by RIOT using an + * event queue (accessible via openthread_get_evq()) + */ + event_post(openthread_get_evq(), &event_panid); return 0; }