Azure IoT Hub Sampleの調査メモ
Azure Sphere SDKに含まれている、Azure IoT Hub Sample for MT3620 RDB (Azure Sphere)プロジェクトのコードを調べます。
main()から、Azureに絡む関数のコールツリーはこんな感じ。
main() InitPeripheralsAndHandlers() AzureIoT_Initialize() AzureIoT_SetMessageReceivedCallback(&MessageReceived); AzureIoT_SetDeviceTwinUpdateCallback(&DeviceTwinUpdate); AzureIoT_SetDirectMethodCallback(&DirectMethodCall); AzureIoT_SetConnectionStatusCallback(&IoTHubConnectionStatusChanged); CreateTimerFdAndAddToEpoll(,, &azureIotEventData,); WaitForEventAndCallHandler() ClosePeripheralsAndHandlers() AzureIoT_DestroyClient(); AzureIoT_Deinitialize();
SetXxxCallback()で、コールバック関数を設定している。
あと、タイマーイベントでAzureIotDoWorkHandler()へのコールバックも有り。
static event_data_t azureIotEventData = {.eventHandler = &AzureIotDoWorkHandler};
static void AzureIotDoWorkHandler(event_data_t *eventData) { ... if (AzureIoT_SetupClient()) { AzureIoT_DoPeriodicTasks(); } }
ボタン押したらメッセージ送信している部分はこれ。
static void SendMessageToIotHub(void) { ... AzureIoT_SendMessage("Hello from Azure IoT sample!"); ... }
ざっと見た感じ、AzureIoT_xxxxという関数を呼んでいる。
AzureIoT_xxxxは、ウィザード?が生成したazure_iot_utilities.h/.cで定義されている。
使っている関数の、azure_iot_utilitiesの中を見るとこんな感じ。
AzureIoT_Initialize() IoTHub_Init() AzureIoT_SetupClient() IoTHubDeviceClient_LL_CreateFromConnectionString() IoTHubDeviceClient_LL_SetOption() IoTHubDeviceClient_LL_SetMessageCallback() IoTHubDeviceClient_LL_SetDeviceMethodCallback() IoTHubDeviceClient_LL_SetDeviceTwinCallback() IoTHubDeviceClient_LL_SetConnectionStatusCallback() IoTHubDeviceClient_LL_SetRetryPolicy() AzureIoT_DoPeriodicTasks() IoTHubDeviceClient_LL_DoWork() AzureIoT_SendMessage() IoTHubMessage_CreateFromString() IoTHubDeviceClient_LL_SendEventAsync() IoTHubMessage_Destroy() AzureIoT_DestroyClient() IoTHubDeviceClient_LL_Destroy() AzureIoT_Deinitialize() IoTHub_Deinit()