question

KarimWalidAbdelazimElhammady-6623 avatar image
0 Votes"
KarimWalidAbdelazimElhammady-6623 asked ricardosolisvillegas-4678 commented

Connection Reset when using iot_hub_client (IoT Plug and Play)

Hello,

I am using the SAMV71Q19B board to connect to the IoT hub using the iot_hub_client (https://github.com/azure-rtos/netxduo/blob/master/addons/azure_iot/docs/azure_rtos_iot_hub_client.md). I am connecting to the hub through an IoT edge device. I am sending some telemetry messages to the hub. The device connects to the hub without any issues and start sending telemetry messages. However, after an hour I receive a FIN ACK from the server , then the board send an encrypted alert followed by a FIN ACK, which reset the connection.

The board never reconnect again. Does anyone know the reason for this behavior?

One other thing, this issue happens almost at the same timestamp in wireshark in each trial.

I have attached below a screenshot of the wireshark capture.

Thanks,
Karim

194058-microsoftteams-image.png


azure-iot-hubazure-iot-edgeazure-rtosazure-iot-pnp
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @KarimWalidAbdelazimElhammady-6623 ,

I would like to understand better your environment. You referenced Azure RTOS netxduo as your iot_hub_client . And then you mentioned that this device is connecting through an IoT Edge device - Is the IoTEdge Device acting as a transparent gateway?

Assuming SAMV71Q19B is a child device of your IoT Edge Transparent Gateway, when you receive the FIN ACK from the server, did you check the IoT Edge device for any errors? If you restart IoTEdge, is the connection reestablished? See Troubleshoot your IoT Edge device for more steps to check.

I would suggest you also try connecting SAMV71Q19B directly to IoTHub, so we can confirm if the issue is in IoTEdge or not.

Thanks!


0 Votes 0 ·

after checking the error logs on IoTHub:

This is the error: 401003 IoTHubUnauthorized , seems it is related to SAS token generation after expiry.

I found the error description here:
https://docs.microsoft.com/en-us/azure/iot-hub/troubleshoot-error-codes#401003-iothubunauthorized

1 Vote 1 ·
asergaz avatar image asergaz KarimWalidAbdelazimElhammady-6623 ·

@KarimWalidAbdelazimElhammady-6623 thanks for trying connecting it directly to IoTHub. The error you are receiving helps us understand better what may be hapenning.

Are you setting the connection status callback function like this?

 UINT nx_azure_iot_hub_client_connection_status_callback_set(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr,
                                                             VOID (*connection_status_cb)(
                                                                  struct NX_AZURE_IOT_HUB_CLIENT_STRUCT
                                                                  *hub_client_ptr, UINT status));


This routine sets the connection status callback. This callback function is invoked when the IoT Hub status is changed. For example following status will be returned on disconnection: NXD_MQTT_ERROR_NOT_AUTHORIZED or NX_AZURE_IOT_SAS_TOKEN_EXPIRED . If you have the callback function enabled can you confirm you receive a status change and which one?

As a next step can you as well please open a new issue in the netxduo repo? I don't have the device to reproduce myself and I will call the attention of the Product Team once you share the issue link here.

Thank you so much!


0 Votes 0 ·

Hello @asergaz ,

yes, I am using the edge as a transparent gateway. I haven't checked the errors or tried restarting the IoTEdge, maybe I will check that. I will try to directly connect to the IoTHub and let you know.


Thanks,
Karim


0 Votes 0 ·
KarimWalidAbdelazimElhammady-6623 avatar image KarimWalidAbdelazimElhammady-6623 KarimWalidAbdelazimElhammady-6623 ·

Hello @asergaz,

I tested by connecting directly to the IoThub. I still get the FIN ACK from the server in the same amount of time. Also, I disabled the telemetry messages being sent by the device so it is not related to the issue. seems like it is not a problem with the IoT edge that I were using as well.

still trying to investigate the error logs on the hub. Please let me know your thoughts and if there is any other thing that I should try.

Thanks,
Karim


0 Votes 0 ·
Show more comments

1 Answer

BoChen-0401 avatar image
1 Vote"
BoChen-0401 answered

Hi @KarimWalidAbdelazimElhammady-6623 Yes, the timeout for connection is 1 hour by default here. You may redefine NX_AZURE_IOT_HUB_CLIENT_TOKEN_CONNECTION_TIMEOUT to extend the connection timeout. Thanks.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.