Nasadiya Sukta
Nasadiya Sukta

Reputation: 21

IOTC_CONNECTION_RESET_BY_PEER_ERROR in iot-device-sdk-embedded-c

I am using iot-device-sdk-embedded-c/examples/iot_core_mqtt_client to Google Cloud IoT Core and push data to it.

I am using this SDK on ESP32 platform. So, I have done minor modifications. However the general code looks like the one in the below link :

https://github.com/Nilhcem/esp32-cloud-iot-core-k8s/blob/master/03-esp32_bme280_ciotc_esp-idf/main/main.c

It all worked fine for a while. But lately, I have been receiving this error: IOTC_CONNECTION_RESET_BY_PEER_ERROR (https://googlecloudplatform.github.io/iot-device-sdk-embedded-c/api/html/d4/d7c/iotc__error_8h.html#a31af29ceaf88c8f978117b3be5545932)

When I start the application, the connection succeeds. But within few minutes, this error comes up and my appliation tries reconnecting. Reconnecting also succeeds and the error again comes up right away. After this the application goes into a loop.

I would like to know, under what circustances, the peer, resets the connection. Also, what can be done to prevent the peer from resetting the connection?

I verified if JWT Token has expired. It was not expired. I had set the expiry time as 1 hour. But this error occurs withing minutes.

I increased the keep alive timeout to 60 minutes as well. I increased Connection Timeout also to 60 minutes.

Private Key should still be ok, since connection is still succeeding.

https://github.com/Nilhcem/esp32-cloud-iot-core-k8s/blob/master/03-esp32_bme280_ciotc_esp-idf/main/main.c

Expected Result : The application should connect and continue to stay connected until the JWT expires.

Actual Result : Application connects to IoT Core successfully. Disconnects after couple of minutes. Reconnects again and goes into this loop.

Upvotes: 2

Views: 502

Answers (1)

class
class

Reputation: 8681

A few things to check that can cause the device to disconnect:

  • Is another connection being made with the same device ID? This can be either another device with the same device ID or an additional MQTT connection from the same device.
  • Is your device using the incorrect QoS? We currently only support 0 and 1.
  • Is your device using the incorrect MQTT version? We only support 3.1.1
  • Is your device publishing more than 64kb to a topic? We limit messages to this size
  • Is your device publishing to the correct folder? You can disconnect if you're not publishing to the /devices/DEVICE_ID/events or /devices/DEVICE_ID/state folder.
  • Is your device listening to a folder other than /devices/DEVICE_ID/config or /devices/DEVICE_ID/commands/#?

Upvotes: 1

Related Questions