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

  • 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

  • Hi any update on this? I've not been able to get network connection. I'm using Airtel IoT SIM card

  • The firmware support both networks so it is not a problem. Converting the modem trace to pcapng file with Cellular Monitor and open with Wireshark.

    I found the devic is rejected by the network with EMM cause 11.

    Cause #11 – PLMN not allowed

          This EMM cause is sent to the UE if it requests service, or if the network initiates a detach request, in a PLMN where the UE, by subscription or due to operator determined barring, is not allowed to operate.

    Please double check with your network operator if you have a valid subscription, and you have correct PDN if it needs to be set.

    Best regards,

    Charlie 

    modemtracee.pcapng

Reply
  • The firmware support both networks so it is not a problem. Converting the modem trace to pcapng file with Cellular Monitor and open with Wireshark.

    I found the devic is rejected by the network with EMM cause 11.

    Cause #11 – PLMN not allowed

          This EMM cause is sent to the UE if it requests service, or if the network initiates a detach request, in a PLMN where the UE, by subscription or due to operator determined barring, is not allowed to operate.

    Please double check with your network operator if you have a valid subscription, and you have correct PDN if it needs to be set.

    Best regards,

    Charlie 

    modemtracee.pcapng

Children
  • I'm trying to figure out why it's not connecting to the network, the ISP says the SIMs are fine. When I try using Modem Shell to connect manually, I'm getting few errors. It would be great if you can help me connect to the network. Please check if the way I'm adding APN details are correct. I have attached the trace file of the Modem Shell, hope that helps.

    mosh:~$ > link connect --apn "airteliot.com" -f 'ipv4v6' -A 0 -U "" -P ""
    link connect --apn "airteliot.com" -f 'ipv4v6' -A 0 -U "" -P ""
    pdn_activate() failed, err -8 esm 0 <unknown>

    [00:01:03.817,352] <wrn> pdn: Failed to activate PDN for CID 1, err 65536
    mosh:~$ > link funmode -1
    link funmode -1
    Release 14 features enable AT-command error, type 1 err 0
    lte_lc_system_mode_set returned error -14
    Functional mode set successfully: normal
    [00:01:14.231,323] <err> lte_lc: Could not send AT command, error: 65536
    mosh:~$ > link sysmode -n --pref_nbiot
    link sysmode -n --pref_nbiot
    Cannot set system mode to modem: -14
    Requested mode couldn't set to modem. Not in flighmode nor in pwroff?
    sysmode 2 saved successfully to settings
    LTE preference 2 saved successfully to settings
    [00:01:21.959,320] <err> lte_lc: Could not send AT command, error: 65536
    mosh:~$ > link connect --apn "airteliot.com" -f 'ipv4v6' -A 0 -U "" -P ""
    link connect --apn "airteliot.com" -f 'ipv4v6' -A 0 -U "" -P ""
    pdn_activate() failed, err -8 esm 0 <unknown>

    [00:01:27.975,372] <wrn> pdn: Failed to activate PDN for CID 1, err 65536
    Modem domain event: Search done
    Network registration status: searching
    LTE cell changed: ID: -1, Tracking area: -1
    mosh:~$ > link funmode --normal_no_rel14
    link funmode --normal_no_rel14
    Release 14 features disable AT-command error, type 1 err 0
    lte_lc_system_mode_set returned error -14
    Functional mode set successfully: normal
    [00:02:51.416,839] <err> lte_lc: Could not send AT command, error: 65536
    Network registration status: unknown
    Network registration status: searching

    trace-2024-09-13T09-38-29.062Z.mtrace

  • 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?

Related