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

  • Airtel says that the SIMs they've sent are NB-IoT SIMs.
    But this confirms that there is no Airtel signal right? Is there any other ways of pin pointing the issue?
    I'm not able to fine LTE Link Monitor app on nRF Connect. Any idea why? I'm using Linux and the latest appimage.

    mosh:~$ > at AT%COPS=?
    at AT%COPS=?
    %COPS: (1,"","","405861",9)
    OK
    
    Network registration status: searching
    LTE cell changed: ID: -1, Tracking area: -1
    Currently active system mode: NB-IoT
    LTE cell changed: ID: 2894737, Tracking area: 49173
    mosh:~$ > at AT%COPS=?
    at AT%COPS=?
    Currently active system mode: None
    %COPS: (1,"","","405861",9)
    OK
    
    LTE cell changed: ID: -1, Tracking area: -1
    RRC mode: Connected
    Currently active system mode: NB-IoT
    LTE cell changed: ID: 6032786, Tracking area: 49173
    RRC mode: Idle
    Modem domain event: Search done
    mosh:~$ > at AT%COPS=?
    at AT%COPS=?
    Currently active system mode: None
    %COPS: (3,"","","405861",9)
    OK
    
    LTE cell changed: ID: -1, Tracking area: -1

  • Yes, only JIO network is found by your device according to AT%COPS=? feedback.

    MCC MNC PLMN Region Country ISO Operator Brand TADIG Bands
    405 861 405861 Asia and the Middle East India IN Karnataka Jio INDJ9 LTE 850 / LTE 1800 / TD-LTE 2300
  • I was able to get Jio SIMs and I'm able to connect to the network. But my MQTT program still doesn't work. It works only for brokers without username & password. The broker I want to connect to has username, password & port (My program is in the body of this post).

    Also the network is getting connected on the nRF9160DK but not my custom board. What could be the reason?

  • 1) For the original sample  docs.nordicsemi.com/.../description.html, if you want to use username & password to connect with MQTT broker, you need to add username & password parameters here:

    https://github.com/nrfconnect/sdk-nrf/blob/2bae3437305bc8f5eb29260ca545fb8033b2b80b/samples/net/mqtt/src/modules/transport/transport.c#L187

    struct mqtt_helper_conn_params {
    /* The hostname must be null-terminated. */
    struct mqtt_helper_buf hostname;
    struct mqtt_helper_buf device_id;
    struct mqtt_helper_buf user_name;
    struct mqtt_helper_buf password;
    };

    2) For your custom board connection issue, can you attach the log and modem trace?

  • How do I get modem trace through RTT? My custom board does not have free UART ports for logging.

Reply Children
No Data
Related