Skip to content

Instantly share code, notes, and snippets.

@Morozov-5F
Created August 18, 2017 14:54
Show Gist options
  • Save Morozov-5F/fa6c90f32c73da9c8d7aa840447f8354 to your computer and use it in GitHub Desktop.
Save Morozov-5F/fa6c90f32c73da9c8d7aa840447f8354 to your computer and use it in GitHub Desktop.
Azure SDK initialization
int keep_alive_interval_sec = 60;
uint32_t azure_message_timeout_msec = 60 * 1000;
boolean azure_log_trace = TRUE;
assert(platform_init() == 0);
/* Initialize a low-level client */
azure_ctx->azct_client = IoTHubClient_LL_CreateFromConnectionString(
connection_string, CAT_AZURE_PROTOCOL);
assert(NULL != azure_ctx->azct_client);
/* Enable logging */
iot_hub_ret = IoTHubClient_LL_SetOption(azure_ctx->azct_client,
OPTION_LOG_TRACE,
&azure_log_trace);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
/* Keep the connection alive */
iot_hub_ret = IoTHubClient_LL_SetOption(azure_ctx->azct_client,
OPTION_KEEP_ALIVE,
&keep_alive_interval_sec);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
/* Set message timeout */
iot_hub_ret = IoTHubClient_LL_SetOption(azure_ctx->azct_client,
OPTION_MESSAGE_TIMEOUT,
&azure_message_timeout_msec);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
/* Assign certificates */
iot_hub_ret = IoTHubClient_LL_SetOption(azure_ctx->azct_client,
OPTION_X509_CERT,
certificates);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
/* Assign private key */
iot_hub_ret = IoTHubClient_LL_SetOption(azure_ctx->azct_client,
OPTION_X509_PRIVATE_KEY,
private_key);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
/* Set retry policy */
iot_hub_ret = IoTHubClient_LL_SetRetryPolicy(azure_ctx->azct_client,
IOTHUB_CLIENT_RETRY_INTERVAL,
0);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
/* Setup callbacks */
iot_hub_ret = IoTHubClient_LL_SetMessageCallback(azure_ctx->azct_client,
s_azure_receive_message_cb,
azure_ctx);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
iot_hub_ret = IoTHubClient_LL_SetConnectionStatusCallback(
azure_ctx->azct_client,
s_azure_client_connection_status_cb,
azure_ctx);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
iot_hub_ret = IoTHubClient_LL_SetDeviceMethodCallback(
azure_ctx->azct_client,
s_azure_device_method_cb,
azure_ctx);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
iot_hub_ret = IoTHubClient_LL_SetDeviceTwinCallback(azure_ctx->azct_client,
s_azure_device_twin_cb,
azure_ctx);
assert(IOTHUB_CLIENT_OK == iot_hub_ret);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment