BG96 MQTT ThreadX Demo Application connection issues

Hello,

I am using the BG96 module and the SDK v 4.3.6. I am trying to run the example threadx MQTT application using an open source mqtt server(test.mosquitto.org), however, I am running into issues in connecting to the server. Below are pictures of the error debug messages and the
parameters that I have set in the code, respectively.

error

mqtt_config1

config2

PLEASE NOTE that I am able to open, connect, publish, and subscribe using the AT commands to the mosquitto test server so I am unsure why the same parameters given into the demo application are not working as intended.

A quick update of the error logs that I am receiving on BG96 dev kit when running ThreadX MQTT demo application (example_mqtt.c). SDK version is 4.3.6. We are attempting to connect to Microsoft Azure IoT Hub server. An image of the server parameters/credentials is also included below.

20:28:21.605 -> MQTT Task Start…
20:28:21.605 ->
20:28:21.605 -> Initializes the DSS netctrl library
20:28:21.605 ->
20:28:21.638 -> DSS netctrl library has been initialized.
20:28:21.638 ->
20:28:21.638 -> Registering Callback tcp_dss_handle
20:28:21.638 ->
20:28:21.638 -> tcp_dss_handle 299675089, status 0
20:28:21.638 ->
20:28:21.672 -> Registed tcp_dss_handler success
20:28:21.672 ->
20:28:21.672 -> Setting tech to Automatic
20:28:21.672 ->
20:28:21.672 -> Setting APN - hologram
20:28:21.672 ->
20:28:21.672 -> Setting family to IPv4
20:28:21.672 ->
20:28:21.708 -> qapi_DSS_Start_Data_Call start!!!.
20:28:21.708 ->
20:28:21.708 -> Start Data service success.
20:28:21.708 ->
20:28:22.942 -> Data test event callback, event: 1
20:28:22.942 ->
20:28:22.942 -> Data Call Connected.
20:28:22.942 ->
20:28:22.982 -> <— static IP address information —>
20:28:22.982 ->
20:28:22.982 -> static IP: 10.170.111.97
20:28:22.982 ->
20:28:22.982 -> Gateway IP: 10.170.111.98
20:28:22.982 ->
20:28:22.982 -> Primary DNS IP: 212.9.0.135
20:28:22.982 ->
20:28:23.026 -> Second DNS IP: 212.9.0.136
20:28:23.026 ->
20:28:23.026 -> <— End of system info —>
20:28:23.026 ->
20:28:23.026 -> SIGNAL EVENT IS [4]
20:28:23.026 ->
20:28:23.026 -> DSS_SIG_EVT_CONN_E 2 Signal
20:28:23.026 ->
20:28:23.074 -> conn_mqtt entry
20:28:23.074 ->
20:28:23.074 -> port:45858
20:28:23.074 ->
20:28:23.074 -> MQTT server name
20:28:23.074 ->
20:28:23.074 -> @@@j = 1
20:28:23.074 ->
20:28:23.113 -> Primary DNS IP: 212.9.0.135
20:28:23.113 ->
20:28:23.113 -> Second DNS IP: 212.9.0.136
20:28:23.113 ->
20:28:23.113 -> Start DNSc…device_name: rmnet_data0
20:28:23.113 ->
20:28:23.132 -> hostname: 5G-IoT-System-For-Emergency-Responders.azure-devices.net is resoling in interface: rmnet_data0
20:28:23.132 ->
20:28:23.696 -> reshost ret: 0
20:28:23.696 ->
20:28:23.734 ->
20:28:23.734 ->
20:28:23.734 -> 5G-IoT-System-For-Emergency-Responders.azure-devices.net --> 40.78.22.17
20:28:23.734 ->
20:28:23.734 -> sin_addr:40.78.22.17
20:28:23.734 ->
20:28:23.734 -> client_len=12, client_str=Quectel-BG96
20:28:23.734 ->
20:28:23.769 -> username_len=93, username_str=5G-IoT-System-For-Emergency-Responders.azure-devices.net/Quectel-BG96/?api-version=2018-06-30
20:28:23.769 ->
20:28:23.769 -> pwd_len=175
20:28:23.769 ->
20:28:23.807 -> pwd_str=SharedAccessSignature sr=5G-IoT-System-For-Emergency-Responders.azure-devices.net%2Fdevices%2FQuectel-BG96&sig=qD0hlc7XT4pNIjRnC9FhKhRa%2Bsth9Fu%2BtmnaCPQKv0Q%3D&se=1603103447
20:28:23.807 ->
20:28:23.807 -> mqtt_cli_connect entry
20:28:23.807 -> Mqtt Context created success, ctx=0x8096
20:28:23.807 -> 1:0
20:28:23.807 ->
20:28:23.807 -> 2:0
20:28:23.807 ->
20:28:23.807 -> 3:0
20:28:23.807 ->
20:28:23.840 -> 4:0
20:28:23.840 ->
20:28:23.840 -> 5:0
20:28:23.840 ->
20:28:23.840 -> local sin_addr:0.0.0.0
20:28:23.840 ->
20:28:23.876 -> remote sin_addr:40.78.22.17
20:28:23.876 ->
20:28:23.876 -> Connecting…
20:28:23.876 ->
20:28:24.464 -> MQTT Connect Failed, Error type -20044
20:28:24.464 ->
20:28:24.464 -> connected Signal
20:28:24.464 ->
20:28:24.464 -> subscribing…
20:28:24.464 ->
20:28:24.464 -> MQTT Subscribe Failed, Error type -1
20:28:24.464 ->
20:28:24.464 -> Published trying…
20:28:24.464 ->
20:28:24.464 -> MQTT Publish Failed, Error type -1
20:28:24.464 ->
20:28:32.434 -> Disconnecting…
20:28:32.474 ->
20:28:32.474 -> MQTT Disconnect Failed, Error type -1
20:28:32.474 ->

Err code 20044 means that ,it is a ssl connection fail , it related with your certificate

try “mqtt.eclipse.org” @ 8883

certificate:

1 Like

Hello @WizIO,

Thank you for the response! As you suggested, I have attempted to connect to mqtt.eclipse.org @ port 8883 and used the CA certificate you have provided, however, we are now encountering another issue. When the application goes through the SSL checks and attempts to convert and store to mqtt_cert.bin(MQTT_CERT_BIN), BG96 crashes, and restarts the application repeatedly. Images of our configurations, Logs, and the line where the application crashes are provided below.

mqtt_eclipse_org
server name configuration in header file

mqtt_parameters
mqtt parameter configuration in C file

certificates
Full CA certificate NOTE: client key and client cert are kept empty.

upload_files_via_efs
Uploaded certificates to BG96 via QEFS


Log screenshot

As seen in the log screenshot, the CA cert, Client, cert, and Client key are able to be read hence API returning 0, however, when the app gets to qapi_Net_SSL_Cert_Convert_And_Store(&cert_info, MQTT_CERT_BIN); (as seen in image below)
it will crash BG96 and restart the application.

Is this an issue with the certificates? I am not sure why qapi_Net_SSL_Cert_And_Store() API is fine with MQTT_CALIST_BIN but not MQTT_CERT_BIN as 2nd parameter. Perhaps it is because client cert and client key are kept empty? CA cert is the only thing that contains a certificate.

@stephen.li Is it possible to authenticate with SAS token only and without any certificates? I have done so successfully using AT commands to my Azure IoT Hub. Can this be done with ThreadX?

use (convert & store ) only ca_root certificate
btw: Azure is the same and SAS to mqtt user&password … tested

Okay, we are now running only convert and store on the CA root certificate and the board doesn’t crash anymore! :slight_smile:
We are still getting error -20044 however, which is SSL connection error. Not sure why this is as the CA cert successfully converts and stores with the api returning 0 on success.

We have also tried SAS with username and password and ssl disabled, however, we still get error -20044. Is there a special format for how username and password should be? We followed the format found on microsoft azure site: connect to azure iot hub directly as device

On a side note: I have re-tried connecting to port 1883(mqtt.eclipse.org and test.mosquitto.org) and it works. I had to remove username and password for the configuration as keeping it empty is considered a bad parameter. which yields error -20026 = bad parameter on API call.

#define AZURE_PORT          8883
#define AZURE_HOST          "<YOUR-HUB>.azure-devices.net"
#define AZURE_DEVICE_ID     "<YOUR-DEVICE-NAME>"
#define AZURE_CLIENT_ID     AZURE_DEVICE_ID
#define AZURE_USER_NAME     AZURE_HOST "/" AZURE_DEVICE_ID
#define AZURE_PRIVATE_KEY   "<YOUR-PRIVATE-KEY>"

mqtt.connect(AZURE_CLIENT_ID, AZURE_USER_NAME, sas.get())

I am entering all the required fields for SAS connection but I am still getting error -20044(SSL connection error). I have triple checked to make sure all fields are correct with no typos.

user name muxt be
AZURE_HOST / AZURE_DEVICE_ID

pass:
SharedAccessSignature sr=AZURE_HOST&sig=CALCULATED_KEY&se=EXPIRED_TIME

for generate SAS use DeviceExplorer.exe and test connection

here is simple python example for test connection

full doc is here

Ahh thank you for the examples! I’ll take a look at these.

Ahh so I was able to connect and publish to my server using your python script with my server credentials :slight_smile: But I am not sure why it is not working on BG96…

still getting error 20044 on bg96 with all server credentials entered exactly the same.

if python work - print & get parameters … client-ID, user-name, password and paste to BG96/95/77
debug print parameters from module and check

there is nothing special about Azure connection…

Okay I will try this and check debug prints for any discrepancies.

test without and with ca_root… if here is the problem - ask Quectel support
sorry my azure account expire and in HomeOffice I not have BG9x module

Yeah I will check with a ca_root and with quectel support. All parameter debug prints look correct.
No worries! You have helped us quite a lot! :smiley: We appreciate all the help!

http://naver.me/GI7p2MgL
I tested for Azure iot hub today. refer~~

Hello @Maker_i

Thank you for the reference, however, I am trying to connect to Azure IoT Hub using the sample threadx applications provided by Quectel. In Your reference, you are using AT commands which I have been successful in using to connect to Azure IoT Hub.