Need help connecting to MQTT using nRF9160

I can't figure out what I'm missing. I'm not able to send messages using MQTT.

Here's the link to my code: https://github.com/pranav-ether/test/tree/main/mqtt_pub

This are the logs:

[00:02:58.031,768] <inf> LTE: Network registration status: Connected - home network
[00:02:58.031,890] <inf> LTE: Connected to LTE network
[00:02:58.031,921] <inf> LTE: ====== Cell Network Info ======
[00:02:58.033,477] <inf> LTE: Signal strength: 42
[00:02:58.034,210] <inf> LTE: Current LTE band: 8
[00:02:58.034,912] <inf> LTE: Supported LTE bands: (1,2,3,4,5,8,12,13,17,19,20,25,26,28,66)
[00:02:58.035,705] <inf> LTE: Tracking area code: 8CA1
[00:02:58.036,468] <inf> LTE: Current mode: 0
[00:02:58.037,200] <inf> LTE: Current operator name: 65501
[00:02:58.038,146] <inf> LTE: Cell ID of the device: 0E446D21
[00:02:58.039,337] <inf> LTE: IP address of the device: 100.67.202.179
[00:02:58.039,886] <inf> LTE: Modem firmware version: mfw_nrf9160_1.3.5
[00:02:58.040,618] <inf> LTE: LTE-M support mode: 0
[00:02:58.041,259] <inf> LTE: NB-IoT support mode: 1
[00:02:58.041,900] <inf> LTE: GPS support mode: 0
[00:02:58.042,633] <inf> LTE: Mobile network time and date: 24/08/13,06:33:37+08
[00:02:58.042,633] <inf> LTE: ===============================
[00:02:58.043,121] <inf> MQTT: Connection to broker using mqtt_init
[00:04:23.972,839] <err> mqtt_helper: Cloud MQTT keepalive ping failed: -128

Parents
  • Did you make original NCS MQTT sample works MQTT (nordicsemi.com)? Which NCS version are you based on?

  • The mqtt sample did not work for me. I'm using v2.6.1
    Here are the logs for the mqtt sample:

    [00:00:00.295,349] <inf> network: Bringing network interface up and connecting to the network
    [00:00:00.528,198] <inf> nrf_modem_lib_trace: Trace thread ready
    [00:00:00.535,827] <inf> nrf_modem_lib_trace: Trace level override: 2
    +CEREG: 2,"8CA1","0E241F17",9
    +CSCON: 1
    +CSCON: 0
    +CSCON: 1
    +CGEV: ME PDN ACT 0,0
    +CNEC_ESM: 50,0
    +CEREG: 1,"8CA1","0E241F17",9,,,"11100000","00000110"
    [00:01:47.830,474] <inf> network: Network connectivity established
    [00:03:30.036,132] <err> mqtt_helper: Cloud MQTT keepalive ping failed: -128
    [00:03:30.036,376] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:03:30.036,407] <err> transport: Failed connecting to MQTT, error code: -95
    [00:04:30.037,017] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:04:30.037,048] <err> transport: Failed connecting to MQTT, error code: -95
    +CSCON: 0
    [00:05:30.046,081] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:05:30.046,112] <err> transport: Failed connecting to MQTT, error code: -95
    +CSCON: 1
    [00:06:30.046,875] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:06:30.046,905] <err> transport: Failed connecting to MQTT, error code: -95
    +CSCON: 0
    [00:07:30.055,938] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:07:30.055,969] <err> transport: Failed connecting to MQTT, error code: -95
    [00:08:30.065,032] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:08:30.065,063] <err> transport: Failed connecting to MQTT, error code: -95
    *** Booting nRF Connect SDK 3758bcbfa5cd ***
    [00:00:00.300,537] <inf> network: Bringing network interface up and connecting to the network
    [00:00:00.533,386] <inf> nrf_modem_lib_trace: Trace thread ready
    [00:00:00.541,015] <inf> nrf_modem_lib_trace: Trace level override: 2
    +CEREG: 2,"8CA1","0E241F17",9
    +CSCON: 1
    +CSCON: 0
    +CSCON: 1
    +CGEV: ME PDN ACT 0,0
    +CNEC_ESM: 50,0
    +CEREG: 1,"8CA1","0E241F17",9,,,"11100000","00000110"
    [00:01:49.906,158] <inf> network: Network connectivity established
    [00:03:32.047,851] <err> mqtt_helper: Cloud MQTT keepalive ping failed: -128
    [00:03:32.048,095] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:03:32.048,095] <err> transport: Failed connecting to MQTT, error code: -95
    [00:04:32.048,706] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:04:32.048,736] <err> transport: Failed connecting to MQTT, error code: -95
    +CSCON: 0
    [00:05:32.057,800] <err> mqtt_helper: Library is in the wrong state (MQTT_STATE_CONNECTING), MQTT_STATE_DISCONNECTED required
    [00:05:32.057,830] <err> transport: Failed connecting to MQTT, error code: -95

  • Ok, I suggest you try to make the official sample work first.

    How do you build the sample? Do you use TLS? Do you still have data with your SIM card?

    I see you have enabled modem trace, you can share it here for further check.

  • MQTT sample was built using nrf-connect on VS Code with v2.6.0 toolchain & v2.6.1 SDK. I built the sample without any changes.
    Regarding modem trace, what exactly needs to be shared? Wireshark logs?

  • ncs261_mqtt_nrf9160dk.hex

    Looks everything is correct, and only the server has no response to your MQTT client connection request.

    Could you test with the firmware attached to double confirm? You can also verify with MQTT client on your PC, but this may only happen on cellular network.

  • Hi, sorry for the delayed response. I have flashed the hex file & according to the Cellular Monitor's Preferred Bearer field is LTE-M. My network only has NB-IoT. So I don't think it's connecting.trace-2024-08-29T10-44-52.471Z.mtrace

Reply Children
No Data
Related