AWS Core IoT connection problems but only if more than 1 device is publishing

I have an application which makes a MQTT publish every 10 seconds. I’m using mbedtls and the cellular library in combination with the SARA-R4 modem.
After establishing a new MQTT connection I can publish 4 to 5 times on average before I get the error:
Failed to read data: mbedTLSError= SSL - The peer notified us that the connection is going to be closed :
I do not know where to start looking for resolving this problem. Is it a problem in the AWS service, in the cellular connection or in my application?

Anyone here familiar with this error?

--------------------section of the log with the occurence---------------------------------

[INFO] [OTADemo] [OtaOverMqttDemoExample.c:2005] Received: 0 Queued: 0 Processed: 0 Dropped: 0
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:2005] Received: 0 Queued: 0 Processed: 0 Dropped: 0
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:2005] Received: 0 Queued: 0 Processed: 0 Dropped: 0
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:2005] Received: 0 Queued: 0 Processed: 0 Dropped: 0
[ERROR] [TlsTransport] [using_mbedtls.c:798] Failed to read data: mbedTLSError= SSL - The peer notified us that the connection is going to be closed : .
[ERROR] [MQTT] [core_mqtt_serializer.c:2405] A single byte was not read from the transport: transportStatus=-30848.
[ERROR] [MQTT] [core_mqtt.c:1328] Receiving incoming packet length failed. Status=MQTTRecvFailed
[ERROR] [MQTT] [core_mqtt.c:2200] Exiting process loop due to failure: ErrorStatus=MQTTRecvFailed
[ERROR] [MQTT] [core_mqtt_agent.c:1022] MQTT operation failed with status MQTTRecvFailed

Already found the problem. I was simultaneously posting to the same MQTT topic with two different devices. Apparently AWS Core IoT does not like that and then closes the connection frequently, for both devices. When I switch one of the two devices off, the connection on the other does not drop anymore. This is unexpected behavior for me.
Now I’ll test what happens if each device gets its own topic.
This complicates things though, as each device will then need its own rule to forward the data to a server, instead of having one rule for all… New territory for me, not sure what would be the best approach.

Not been able to resolve the problem yet. I changed my code such that the devices each post to a device specific subtopic iot/{uniquedeviceid}, so they are independent. Yet when both devices are posting I get very frequent connection problems, while if I turn of one of the devices it works flawlessly.
This is not a FreeRTOS problem, but rather a AWS problem I recon. Since there are quite a few AWS members on this forum, I’m posting it here, or is there a better place to ask this question?

Your devices get their IP addresses by DHCP and/or are different per device ?
Just to be sure :wink:

Yeah, both devices get their unique IP from the cellular network, and both post to a unique topic. Each device individually works perfect without the other turned on. When both are turned on, both get very frequent unexpected connection closures… I’m totally lost as to why this is happening…

The issue is not about the same topic but about the same client ID. Client ID must be unique per client (you can use device serial number or some other information which is unique to the device). If another client connects with the same client ID, the previously connected client is disconnected.

1 Like

What a facepalm moment, can’t believe I forgot about that. Many thanks, I made the clientID dynamically load a unique ID and this resolved the issue!