Problem setting up TLS link

RouseA
Posts: 3
Joined: Tue Oct 08, 2024 2:01 pm

Problem setting up TLS link

Postby RouseA » Mon Nov 11, 2024 12:51 am

I want to set up a link between two devices via a HiveMQ Cloud Serverless cluster, using TLS encryption. Each device uses our custom hardware (programmed in C) and an ESP32-C3-WROOM-02 module programmed with ESP-AT firmware. Our system includes diagnostics so I can monitor the data exchange with the ESP module. The initiation sequence is as follows:

Code: Select all

10/11/24 23:55:21.227 COM1}: ATE0
10/11/24 23:55:27.389 COM1{: ready
10/11/24 23:55:27.390 COM1{:
10/11/24 23:55:27.393 COM1}: AT+CWMODE=1
10/11/24 23:55:27.445 COM1{: AT+CWMODE=1
10/11/24 23:55:27.446 COM1{: OK
10/11/24 23:55:27.447 COM1{:
10/11/24 23:55:27.450 COM1}: AT+CWLAPOPT=1,31
10/11/24 23:55:27.503 COM1{: AT+CWLAPOPT=1,31
10/11/24 23:55:27.504 COM1{: OK
10/11/24 23:55:27.504 COM1{:
10/11/24 23:55:27.509 COM1}: AT+CWJAP="Virgin2.4","<Password>"
10/11/24 23:55:27.566 COM1{: AT+CWJAP="Virgin2.4","<Password>"
10/11/24 23:55:27.640 COM1{: WIFI CONNECTED
10/11/24 23:55:27.645 COM1{: WIFI GOT IP
10/11/24 23:55:27.646 COM1{: OK
10/11/24 23:55:27.646 COM1{:
10/11/24 23:55:27.651 COM1}: AT+CIPSNTPCFG=1,0,"0.uk.pool.ntp.org","1.uk.pool.ntp.org","2.uk.pool.ntp.org"
10/11/24 23:55:27.715 COM1{: AT+CIPSNTPCFG=1,0,"0.uk.pool.ntp.org","1.uk.pool.ntp.org","2.uk.pool.ntp.org"
10/11/24 23:55:27.716 COM1{: OK
10/11/24 23:55:27.716 COM1{:
10/11/24 23:55:27.209 COM1{: No Response
10/11/24 23:55:27.210 COM1}: AT+CIPSNTPTIME?
10/11/24 23:55:27.274 COM1{: +CIPSNTPTIME:Thu Jan  1 00:00:02 1970
10/11/24 23:55:27.275 COM1{: OK
10/11/24 23:55:27.276 COM1{: +TIME_UPDATED
10/11/24 23:55:27.277 COM1{:
10/11/24 23:55:27.340 COM1{: MQTTCLEAN=0
10/11/24 23:55:27.341 COM1{:
10/11/24 23:55:27.370 COM1}: AT+MQTTUSERCFG=0,2,"0","XCnet","<Password>",0,0,""
10/11/24 23:55:27.430 COM1{: AT+MQTTUSERCFG=0,2,"0","XCnet","<Password>",0,0,""
10/11/24 23:55:27.430 COM1{: OK
10/11/24 23:55:27.431 COM1{:
10/11/24 23:55:27.437 COM1}: AT+MQTTCONN=0,"<User Address>.s1.eu.hivemq.cloud",8883,1
10/11/24 23:55:27.500 COM1{: AT+MQTTCONN=0,"<User Address>.s1.eu.hivemq.cloud",8883,1
10/11/24 23:55:27.319 COM1{: +MQTTCONNECTED:0,2,"<User Address>.s1.eu.hivemq.cloud","8883","",1
10/11/24 23:55:27.320 COM1{: OK
10/11/24 23:55:27.320 COM1{:
10/11/24 23:55:27.325 COM1}: AT+MQTTSUB=0,"XCCOMMS_BS",2
10/11/24 23:55:27.384 COM1{: AT+MQTTSUB=0,"XCCOMMS_BS",2
10/11/24 23:55:27.385 COM1{: OK
Following this one end (the Basestation) periodically sends messages while the other end (the Outstation) waits to receive them. However, the commands from the other end. The Basestation log is as follows (ignore the timestamps - the clocks in our hardware aren't synchronised):

Code: Select all

3/11/24 14:36:48.305 COM1}: AT+MQTTPUBRAW=0,"XCCOMMS_BS",68,0,0
13/11/24 14:36:50.329 COM1{: OK
13/11/24 14:36:50.330 COM1{:
13/11/24 14:36:50.330 COM1{: >
13/11/24 14:36:50.333 COM1>: 01 1F 39 00 00 00 0A C2 00 9B 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 58 2F
13/11/24 14:36:50.389 COM1<: +MQTTPUB:OK
13/11/24 14:36:50.439 COM1<: +MQTTSUBRECV:0,"XCCOMMS_BS",68,01 1F 39 00 00 00 0A C2 00 9B 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 58 2F 0D 0A
13/11/24 14:36:51.188 COM1<: +MQTTDISCONNECTED:0
13/11/24 14:37:03.447 COM1<: +MQTTCONNECTED:0,2,"5287e5dda6864af6b07136e43414884f.s1.eu.hivemq.cloud","8883","",1
13/11/24 14:37:10.045 COM1}: AT+MQTTPUBRAW=0,"XCCOMMS_BS",68,0,0
13/11/24 14:37:10.100 COM1{: OK
13/11/24 14:37:10.101 COM1{:
13/11/24 14:37:10.101 COM1{: >
13/11/24 14:37:10.104 COM1>: 01 1F 39 00 00 00 0A 42 00 AF 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 81 44
13/11/24 14:37:10.160 COM1<: +MQTTPUB:OK
13/11/24 14:37:10.209 COM1<: +MQTTSUBRECV:0,"XCCOMMS_BS",68,01 1F 39 00 00 00 0A 42 00 AF 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 81 44 0D 0A
13/11/24 14:37:11.783 COM1}: AT+MQTTPUBRAW=0,"XCCOMMS_BS",68,0,0
13/11/24 14:37:11.838 COM1{: OK
13/11/24 14:37:11.839 COM1{:
13/11/24 14:37:11.839 COM1{: >
13/11/24 14:37:11.842 COM1>: 01 1F 39 00 00 00 0A 42 00 B0 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 96 D6
13/11/24 14:37:11.898 COM1<: +MQTTPUB:OK
13/11/24 14:37:11.947 COM1<: +MQTTSUBRECV:0,"XCCOMMS_BS",68,01 1F 39 00 00 00 0A 42 00 B0 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 96 D6 0D 0A
13/11/24 14:37:13.510 COM1}: AT+MQTTPUBRAW=0,"XCCOMMS_BS",68,0,0
13/11/24 14:37:13.565 COM1{: OK
13/11/24 14:37:13.566 COM1{:
13/11/24 14:37:13.566 COM1{: >
13/11/24 14:37:13.569 COM1>: 01 1F 39 00 00 00 0A 42 00 B2 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 23 75
13/11/24 14:37:13.625 COM1<: +MQTTPUB:OK
13/11/24 14:37:13.673 COM1<: MQTTSUBRECV:0,"XCCOMMS_BS",68,01 1F 39 00 00 00 0A 42 00 B2 4A 31 67 7D 00 00 42 53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 23 75 0D 0A
13/11/24 14:37:14.332 COM1<: +MQTTDISCONNECTED:0
13/11/24 14:37:15.237 COM1}: AT+MQTTPUBRAW=0,"XCCOMMS_BS",68,0,0
13/11/24 14:37:15.292 COM1{: ERROR
13/11/24 14:37:15.293 COM1{:
You will see that as the PUB and SUB both use the same topic the Basestation receives a copy of the message it sent. This is the action I expect. It is repeated every 2 seconds. However it disconnects and reconnects about every 20 seconds. If an attempt is made to publish while disconnected it fails.

The Outstation diagnostics just shows the following:

Code: Select all

10/11/24 23:55:36.704 COM1<: +MQTTDISCONNECTED:0
10/11/24 23:55:47.508 COM1<: +MQTTCONNECTED:0,2,"5287e5dda6864af6b07136e43414884f.s1.eu.hivemq.cloud","8883","",1
10/11/24 23:55:56.259 COM1<: +MQTTDISCONNECTED:0
10/11/24 23:56:07.488 COM1<: +MQTTCONNECTED:0,2,"5287e5dda6864af6b07136e43414884f.s1.eu.hivemq.cloud","8883","",1
10/11/24 23:56:16.227 COM1<: +MQTTDISCONNECTED:0
It is also disconnecting and reconnecting about every 20 seconds, but it doesn't receive any messages. I have tried modifying the Basestation to subscribe to a different topic (in case the action of it receiving the message deleted it from the system so it isn't delivered to the Outstation) but that makes no difference.

There are two problems:
  • Why do both ends periodically disconnect? This seems to be linked to the <scheme> set in MQTTUSERCFG. I set it to 2: MQTT over TLS (no certificate verify) in the hope that would configure TLS encryption. If I try any other number then MQTTCONN fails. What am I doing wrong? (
  • Why doesn't the Outstation receive messages? It is configured the same as the Basestation, which does see messages echoed back
I would be very grateful for any help

Who is online

Users browsing this forum: No registered users and 29 guests