Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
588 stars 739 forks source link

Cross Compiling Azure IOT C SDK #175

Closed narayanankrish1981 closed 7 years ago

narayanankrish1981 commented 7 years ago

Hello,

I've cross compiled azure-iot-sdk-c for ARM. (i.MX6 device). I made the set up as required and was able to compile the SDK without any issue.

After cross compilation, the sample binaries were created.

I tried running the following samples on the device (after making necessary changes in the .c files):

simplesample_mqtt simplesample_amqp simplesample_http remote_monitoring

When I ran simplesample_http, I was able to view the message on iothub-explorer. But I'm facing problem when I run simplesample_mqtt, simplesample_amqp & remote_monitoring.

When I run ./simplesample_mqtt, I'm getting the following O/P:

./simplesample_mqtt Info: IoT Hub SDK for C, version 1.1.18 IoTHubClient accepted the message for delivery Error: Time:Thu Jul 6 10:40:38 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:1850 mqtt_client timed out waiting for CONNACK Error: Time:Thu Jul 6 10:40:38 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/c-utility/src/tlsio_openssl.c Func:tlsio_openssl_send Line:1261 Invalid tlsio_state. Expected state is TLSIO_STATE_OPEN. Error: Time:Thu Jul 6 10:40:38 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:sendPacketItem Line:323 1262: Failure sending control packet data Error: Time:Thu Jul 6 10:40:38 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:mqtt_client_disconnect Line:1094 Error: mqtt_client_disconnect send failed Info: Evaluated delay time 0 sec. Retry attempt count 1

When I run ./simplesample_amqp, I'm getting the following O/P: ./simplesample_amqp Info: IoT Hub SDK for C, version 1.1.18 Info: Retry policy set (5, timeout = 0) Info: Transport state changed from AMQP_TRANSPORT_STATE_NOT_CONNECTED to AMQP_TRANSPORT_STATE_CONNECTING Info: Transport state changed from AMQP_TRANSPORT_STATE_CONNECTING to AMQP_TRANSPORT_STATE_CONNECTED IoTHubClient accepted the message for delivery Error: Time:Thu Jul 6 10:38:24 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Device_DoWork Line:996 Failed performing DoWork for device 'imx6device' (device reported state 5; number of previous failures: 0) Error: Time:Thu Jul 6 10:38:54 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Device_DoWork Line:996 Failed performing DoWork for device 'imx6device' (device reported state 5; number of previous failures: 1) Error: Time:Thu Jul 6 10:39:24 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Device_DoWork Line:996 Failed performing DoWork for device 'imx6device' (device reported state 5; number of previous failures: 2) Error: Time:Thu Jul 6 10:39:54 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Device_DoWork Line:996 Failed performing DoWork for device 'imx6device' (device reported state 5; number of previous failures: 3) Error: Time:Thu Jul 6 10:40:24 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Device_DoWork Line:996 Failed performing DoWork for device 'imx6device' (device reported state 5; number of previous failures: 4)

When I run remote_monitoring, I get the following O/P:

IoTHubClient accepted the message for delivery Sending sensor value Temperature = 50, Humidity = 50 IoTHubClient accepted the message for delivery Sending sensor value Temperature = 50, Humidity = 50 IoTHubClient accepted the message for delivery Sending sensor value Temperature = 50, Humidity = 50 IoTHubClient accepted the message for delivery Sending sensor value Temperature = 50, Humidity = 50 IoTHubClient accepted the message for delivery Sending sensor value Temperature = 50, Humidity = 50 IoTHubClient accepted the message for delivery Sending sensor value Temperature = 50, Humidity = 50 IoTHubClient accepted the message for delivery Sending sensor value Temperature = 50, Humidity = 50 IoTHubClient accepted the message for delivery Error: Time:Thu Jul 6 10:53:25 2017 File:/home/appsbuild/Narayanan_AWSIOTSDK/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Device_DoWork Line:996 Failed performing DoWork for device 'imx6device' (device reported state 5; number of previous failures: 0)

The above samples works fine on my host PC (Ubuntu 16.04).

Can you please let me know where I'm going wrong w.r.t mqtt and amqp protocols ?

--Nara

markrad commented 7 years ago

Hi @narayanankrish1981,

Since you are able to run the HTTPS sample from your device but not the MQTT or AMQP samples the first thing you should look for is a firewall that is potentially blocking your requests. You will need to be able to connect to Azure using port 5671 for AMQP and port 8883 for MQTT.

Mark Radbourne MSFT

ghost commented 7 years ago

Almost the same problem here:

Basis: azure-iot-sdk-c 2017-06-30 I took the iothub_client_sample_http (with the IoTHubClient_LL_xxx API) and modified the CMakeLists.txt to link against uamqp and mqtt libs. Then a changed the IoTHubClient_LL_CreateFromConnectionString() to test all 5 protocol variants and added a IoTHubClient_LL_SetConnectionStatusCallback. I did the same tests on our ARM target (Yocto Linux) and on Ubuntu 16.04 x86-64. I used the same connection string and both devices are connected to the same network.

Protocol ARM x86-64
HTTPS OK OK
AMQP FAIL [0] OK
AMQP WS FAIL [0] OK
MQTT FAIL [1] FAIL [1]
MQTT WS FAIL OK

[0]

iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Device_DoWork Line:996 Failed performing DoWork for device 'yyyyyyy' (device reported state 5; number of previous failures: 0)
ConnectionStatusCallback: result: IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, reason: IOTHUB_CLIENT_CONNECTION_OK

[1]

socketio_berkeley.c Func:socketio_open Line:676 Failure: select failure.
ConnectionStatusCallback: result: IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, reason: IOTHUB_CLIENT_CONNECTION_NO_NETWORK
tlsio_openssl.c Func:tlsio_openssl_close Line:1220 Invalid tlsio_state. Expected state is TLSIO_STATE_NOT_OPEN or TLSIO_STATE_CLOSING.
tlsio_openssl.c Func:on_underlying_io_open_complete Line:683 Invalid tlsio_state. Expected state is TLSIO_STATE_OPENING_UNDERLYING_IO.
tlsio_openssl.c Func:tlsio_openssl_open Line:1189 Failed opening the underlying I/O.
mqtt_client.c Func:mqtt_client_connect Line:895 Error: io_open failed
iothubtransport_mqtt_common.c Func:SendMqttConnectMsg Line:1776 failure connecting to address xxxxxxxxxxxxx.
Info: Evaluated delay time 0 sec.  Retry attempt count 2
markrad commented 7 years ago

Hi @davidbuechi,

If you are running a Yocto build then you will almost certainly need to use the TrustedCerts option to pass in the root certificate otherwise server certificate validation will fail. Granted, this does not explain why HTTPS works.

Mark Radbourne MSFT

ghost commented 7 years ago

Hi Mark I'll check this. However I don't think this should be a problem. We have configured OpenSSL to know the corresponding certificates and this used to work for about a year.

narayanankrish1981 commented 7 years ago

Hi Mark, Thanks for the reply. As per your advice, I'll check if firewall could be blocking.

Thanks, Nara

ghost commented 7 years ago

@markrad the plain MQTT problem was simply a firewall issue at our site (apparently never used MQTT without websockets before). The other issues with the websockets variants could be solved by using IoTHubClient_LL_SetOption(... "TrustedCerts"...). So it seems that our previous solution with configuring OpenSSL stopped working recently. Thanks a lot for your support!

narayanankrish1981 commented 7 years ago

Hi Mark,

I was able to resolve the issue by including IoTHubClient_LL_SetOption(... "TrustedCerts"...) in MQTT & AMQP samples. Now it works and able to monitor the data in iothub-explorer. Thank you for your support. Since it is working fine, I'm closing this raised issue.

Thanks, Nara

Yadav-Azure commented 7 years ago

@narayanankrish1981 @markrad

I need some help with cross compilation, can you have a look at https://github.com/Azure/azure-iot-sdk-c/issues/243?

Regards Anil Yadav