title: Porting Azure IoT sdk-c to yocto system
body: <p>we are looking at porting the sdk-c for Azure Hub to a device running yocto, we have compiled it with the target end toolchain and we are now testing the results from the target.
  The intention is to use it with MQTT over mbedtls and we currently get errors for the socketio (socketio_berkley.c) and tlsio_mbedtls.c</p>
  <p>azure-c-shared-utility/adapters/socketio_berkeley.c Func:initiate_socket_connection Line:353 Failure opening connection to endpoint
  azure-c-shared-utility/adapters/socketio_berkeley.c Func:socketio_open Line:829 lookup_address_and_connect_socket failed
  azure-umqtt-c/src/mqtt_client.c Func:onOpenComplete Line:454 Error: failure opening connection to endpoint</p>
  <p>The device client has been disconnected^M</p>
  <p>azure-c-shared-utility/adapters/tlsio_mbedtls.c Func:tlsio_mbedtls_open Line:649 Underlying IO open failed
  azure-umqtt-c/src/mqtt_client.c Func:mqtt_client_connect Line:1093 Error: io_open failed^M
  azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:SendMqttConnectMsg Line:2530 Failure connecting to address MYHUBNAME.azure-devices.net</p>
  <pre><code>This is the code I am using:
  /* Legato Framework */
  #include &quot;legato.h&quot;
  #include &quot;interfaces.h&quot;
  #include &quot;le_basics.h&quot;
  #include &quot;json.h&quot;
  
  
  // Copyright (c) Microsoft. All rights reserved.
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  
  // CAVEAT: This sample is to demonstrate azure IoT client concepts only and is not a guide design principles or style
  // Checking of return codes and error values shall be omitted for brevity.  Please practice sound engineering practices
  // when writing production code.
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #include &quot;iothub.h&quot;
  #include &quot;iothub_device_client_ll.h&quot;
  #include &quot;iothub_client_options.h&quot;
  #include &quot;iothub_message.h&quot;
  #include &quot;azure_c_shared_utility/threadapi.h&quot; //need to find this
  #include &quot;azure_c_shared_utility/crt_abstractions.h&quot;  //need to find this
  #include &quot;azure_c_shared_utility/shared_util_options.h&quot;  //need to find this
  #include &quot;internal/iothub_internal_consts.h&quot;
  
  #ifdef SET_TRUSTED_CERT_IN_SAMPLES
  #include &quot;certs.h&quot;
  #endif // SET_TRUSTED_CERT_IN_SAMPLES
  
  /* This sample uses the _LL APIs of iothub_client for example purposes.
  Simply changing the using the convenience layer (functions not having _LL)
  and removing calls to _DoWork will yield the same results. */
  
  // The protocol you wish to use should be uncommented
  //
  #define SAMPLE_MQTT
  //#define SAMPLE_MQTT_OVER_WEBSOCKETS
  //#define SAMPLE_AMQP
  //#define SAMPLE_AMQP_OVER_WEBSOCKETS
  //#define SAMPLE_HTTP
  
  #define USE_MBEDTLS
  
  #ifdef SAMPLE_MQTT
      #include &quot;iothubtransportmqtt.h&quot;
  #endif // SAMPLE_MQTT
  /*
  #ifdef SAMPLE_MQTT_OVER_WEBSOCKETS
      #include &quot;iothubtransportmqtt_websockets.h&quot;
  #endif // SAMPLE_MQTT_OVER_WEBSOCKETS
  #ifdef SAMPLE_AMQP
      #include &quot;iothubtransportamqp.h&quot;
  #endif // SAMPLE_AMQP
  #ifdef SAMPLE_AMQP_OVER_WEBSOCKETS
      #include &quot;iothubtransportamqp_websockets.h&quot;
  #endif // SAMPLE_AMQP_OVER_WEBSOCKETS
  #ifdef SAMPLE_HTTP
      #include &quot;iothubtransporthttp.h&quot;
  #endif // SAMPLE_HTTP
  */
  
  /* Paste in the your iothub connection string  */
  static const char* connectionString = &quot;****MY-CONNECTION-STRING****&quot;;
  #define MESSAGE_COUNT        5
  static bool g_continueRunning = true;
  static size_t g_message_count_send_confirmations = 0;
  
  static void send_confirm_callback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback)
  {
      (void)userContextCallback;
      // When a message is sent this callback will get envoked
      g_message_count_send_confirmations++;
      (void)printf(&quot;Confirmation callback received for message %lu with result %s\r\n&quot;, (unsigned long)g_message_count_send_confirmations, MU_ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result));
  }
  
  static void connection_status_callback(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* user_context)
  {
      (void)reason;
      (void)user_context;
      // This sample DOES NOT take into consideration network outages.
      if (result == IOTHUB_CLIENT_CONNECTION_AUTHENTICATED)
      {
          (void)printf(&quot;The device client is connected to iothub\r\n&quot;);
      }
      else
      {
          (void)printf(&quot;The device client has been disconnected\r\n&quot;);
      }
  }
  
  
  main
  {
      IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol = MQTT_Protocol;
      IOTHUB_MESSAGE_HANDLE message_handle;
      size_t messages_sent = 0;
      const char* telemetry_msg = &quot;test_message&quot;;
  
      // Used to initialize IoTHub SDK subsystem
      (void)IoTHub_Init();
  
      IOTHUB_DEVICE_CLIENT_LL_HANDLE device_ll_handle;
  
      (void)printf(&quot;Creating IoTHub Device handle\r\n&quot;);
      // Create the iothub handle here
      device_ll_handle = IoTHubDeviceClient_LL_CreateFromConnectionString(connectionString, protocol);
      if (device_ll_handle == NULL)
      {
          (void)printf(&quot;Failure creating IotHub device. Hint: Check your connection string.\r\n&quot;);
      }
      else
      {
          // Set any option that are neccessary.
          // For available options please see the iothub_sdk_options.md documentation
      /*
      #ifndef SAMPLE_HTTP
              // Can not set this options in HTTP
              bool traceOn = true;
              IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_LOG_TRACE, &amp;traceOn);
      #endif
  
      #ifdef SET_TRUSTED_CERT_IN_SAMPLES
              // Setting the Trusted Certificate. This is only necessary on systems without
              // built in certificate stores.
                  IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_TRUSTED_CERT, certificates);
      #endif // SET_TRUSTED_CERT_IN_SAMPLES
      */
  
      #if defined SAMPLE_MQTT || defined SAMPLE_MQTT_OVER_WEBSOCKETS
              //Setting the auto URL Encoder (recommended for MQTT). Please use this option unless
              //you are URL Encoding inputs yourself.
              //ONLY valid for use with MQTT
              bool urlEncodeOn = true;
              (void)IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_AUTO_URL_ENCODE_DECODE, &amp;urlEncodeOn);
      #endif
      
          // Setting connection status callback to get indication of connection to iothub
          (void)IoTHubDeviceClient_LL_SetConnectionStatusCallback(device_ll_handle, connection_status_callback, NULL);
  
          do
          {
              if (messages_sent &lt; MESSAGE_COUNT)
              {
                  // Construct the iothub message from a string or a byte array
                  message_handle = IoTHubMessage_CreateFromString(telemetry_msg);
                  //message_handle = IoTHubMessage_CreateFromByteArray((const unsigned char*)msgText, strlen(msgText)));
  
                  // Set Message property
                  
                  (void)IoTHubMessage_SetMessageId(message_handle, &quot;MSG_ID&quot;);
                  (void)IoTHubMessage_SetCorrelationId(message_handle, &quot;CORE_ID&quot;);
                  (void)IoTHubMessage_SetContentTypeSystemProperty(message_handle, &quot;application%2fjson&quot;);
                  (void)IoTHubMessage_SetContentEncodingSystemProperty(message_handle, &quot;utf-8&quot;);
                  (void)IoTHubMessage_SetMessageCreationTimeUtcSystemProperty(message_handle, &quot;2020-07-01T01:00:00.346Z&quot;);
                  
  
  
                  // Add custom properties to message
                  (void)IoTHubMessage_SetProperty(message_handle, &quot;property_key&quot;, &quot;property_value&quot;);
  
                  (void)printf(&quot;Sending message %d to IoTHub\r\n&quot;, (int)(messages_sent + 1));
                  IoTHubDeviceClient_LL_SendEventAsync(device_ll_handle, message_handle, send_confirm_callback, NULL);
  
                  // The message is copied to the sdk so the we can destroy it
                  IoTHubMessage_Destroy(message_handle);
  
                  messages_sent++;
              }
              else if (g_message_count_send_confirmations &gt;= MESSAGE_COUNT)
              {
                  // After all messages are all received stop running
                  g_continueRunning = false;
              }
  
              IoTHubDeviceClient_LL_DoWork(device_ll_handle);
              ThreadAPI_Sleep(1);
  
          } while (g_continueRunning);
  
          // Clean up the iothub sdk handle
          IoTHubDeviceClient_LL_Destroy(device_ll_handle);
      }
      // Free all the sdk subsystem
      IoTHub_Deinit();
  
      printf(&quot;Press any key to continue, this is a test.&quot;);
      (void)getchar();
  
      return;
  }
  </code></pre>
  <p>where I have just selected the MQTT_Protocol, but is the connection string enough for connecting to the backend or I also need to have certificates in place?</p>