MQTT Sample Not Connecting on nRF9160 Board

Hi,

Sorry, i am new to MQTT so may be asking a stupid question, please bear with me. 

I am trying to run the MQTT sample (nrf\samples\net\mqtt) and get the following output

*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
[00:00:00.312,896] <inf> network: Bringing network interface up and connecting to the network
[00:00:00.505,187] <inf> nrf_modem_lib_trace: Trace thread ready
[00:00:00.506,500] <inf> nrf_modem_lib_trace: Trace level override: 2
[00:00:00.508,270] <err> lte_lc: Could not send AT command, error: 65536
[00:00:00.508,270] <err> lte_lc: Failed to set system mode and mode preference, err -14
+CEREG: 2,"01B0","081A1682",7,0,0,"11100000","11100000"
+CSCON: 1
+CSCON: 0
+CSCON: 1
+CGEV: ME PDN ACT 0,0
+CNEC_ESM: 50,0
+CEREG: 1,"01B0","081A1682",7,,,"00011110","00011011"
[00:00:15.113,403] <inf> network: Network connectivity established
+CSCON: 0
+CSCON: 1
+CSCON: 0
+CSCON: 1
+CSCON: 0
+CSCON: 1
+CSCON: 0
+CSCON: 1
[00:00:43.618,835] <err> mqtt_helper: mqtt_connect, error: -116
[00:00:43.618,865] <err> transport: Failed connecting to MQTT, error code: -116
+CSCON: 0

Looking at the cellular monitor, it suggests I am connecting?

Any pointers would be appreciated

Rod

Parents
  • Hello Rod, 

    What MQTT broker are you trying to connect? And with what SIM card? 

    From the start of the log, the LTE Link Controller reports the following

    [00:00:00.508,270] <err> lte_lc: Could not send AT command, error: 65536
    [00:00:00.508,270] <err> lte_lc: Failed to set system mode and mode preference, err -14

    #define NRF_EFAULT 14           /**< Bad address */
    #define NRF_ETIMEDOUT 116       /**< Connection timed out */
    Here is my output after building the default MQTT sample (with nRF Connect SDK v2.6.0)
    +CSCON: 1
    +CGEV: ME PDN ACT 0,0
    +CNEC_ESM: 50,0
    +CEREG: 5,"8173","01165700",7,,,"11100000","11100000"
    [00:00:09.843,292] <inf> network: Network connectivity established
    [00:00:15.231,231] <inf> transport: Connected to MQTT broker
    [00:00:15.231,262] <inf> transport: Hostname: test.mosquitto.org
    [00:00:15.231,323] <inf> transport: Client ID: 350457791991456
    [00:00:15.231,323] <inf> transport: Port: 1883
    [00:00:15.231,353] <inf> transport: TLS: No
    [00:00:15.231,414] <inf> transport: Subscribing to: 350457791991456/my/subscribe/topic
    [00:00:15.303,253] <inf> transport: Subscribed to topic 350457791991456/my/subscribe/topic
    +CSCON: 0
    [00:01:00.324,523] <inf> transport: Published message: "Hello MQTT! Current uptime is: 60315" on topic: "350457791991456/my/publish/topic"
    +CSCON: 1
    +CSCON: 0
    [00:02:00.324,707] <inf> transport: Published message: "Hello MQTT! Current uptime is: 120315" on topic: "350457791991456/my/publish/topic"
    +CSCON: 1
    +CSCON: 0
    KInd regards,
    Øyvind
  • Hi Øyvind,

    I have not changed the code so am trying to connect to the default of test.mosquitto.org. I am using a Tesco PAYG SIM currently but have tried SIMS from EE and Vodafone. Can you recommend one? I am based in the UK.

    Cheers,

    Rod

  • Hi Øyvind,

    I updated the firmware to the latest version.

    However, this seems to have introduced more errors. The trace-sim-lte connection-ppm status is stuck at Trace.

    There is also an error around the database.

    Do i need to change something else to use the latest firmware?

    Rod

  • I moved to 1.3.5 and saw the same error but when i moved to 1.3.4, it seems to be working better.

    Its still not connecting 

    Here is the trace file

    trace-2024-06-21T15-21-04.370Z.mtrace

    Any suggestions?

    Rod

  • Thanks Rod! 

    The device is timing out during the connection. My initial thought is that your connection is poor, i.e. bad signal strength. 

    At what location are you testing?

    Kind regards,
    Øyvind

  • Hi Øyvind,

    I just outside Cambridge, in CB23 postcode. I have put the SIM card in a mobile phone and and seeing "4 bars" so I think Im getting a strong signal. Maybe I am using an incompatible SIM card. Can you recommend one for this area?

    Does the MQTT demo use LTE-M or NBIOT?

    Rod

  • From the initial post your device was connected to LTE-M (digit 7) on home network, i.e. the SIM providers network:
    +CEREG: 1,"01B0","081A1682",7,,,"00011110","00011011"

    More information on the CEREG command can be found here.

    RodWatt said:
    am using a Tesco PAYG SIM currently but have tried SIMS from EE and Vodafone. Can you recommend one?

    For the UK there are two operators listed in the GSMA IoT Deployment map:

    Telefonica for LTE-M

    Vodafone for NB-IoT

    Could you provide logs from your device using the Vodafone SIM? Most importantly the SIM need to support LTE-M and/or NB-IoT. You could have a go with Wireless Logic's roaming SIM'

    Kind regards,
    Øyvind

Reply Children
  • Thanks for providing this trace. 

    There seems to be an issue with the Vodafone SIM as it gets rejected from the network with message:

    Roaming not allowed in this tracking area (13)

    I would reach out to Vodafone and ask them about the coverage in your area. I reached out to our sales team in the UK yesterday regarding your case, and they informed me that O2 is the only one doing LTE-M in the UK, but there seems to be an issue with the SIM you were using. Best to try a O2 SIM to test with LTE-M. 

    Kind regards,
    Øyvind

  • Thanks Øyvind,

    I talked to O2 and they told me that the Tesco SIM I have uses their network so it will act the same as an O2 SIM.

    It seems to be connecting but I dont think the signal is strong enough.

    trace-2024-06-25T09-53-38.262Z.mtrace

    Rod

  • Yes, correct, the signal seems to be the issue here. From the modem trace I see that your connection times out. If O2 confirms that Tesco SIM should be fully supported, and your device is registered to home network (as it states), then I would suggest testing at other locations.

    Could there be equipment close to your board/location causing interreference with the LTE signal?

  • Hi Øyvind,

    I have managed to update my toolchain to v2.7.0-rc3. (I had previously tried to update to rc2 and rc1 but it kept flagging an error, so i was running v.2.6.1)

    Updating to rc3 also enabled me to also update to the latest firmware.

    Anyway, this has allowed me to connect correctly. I have not changed my location, I am still physically in the same place, still using a SIM from Tescos.

    +CEREG: 2,"01B0","07C2B478",7
    +CSCON: 1
    +CGEV: ME PDN ACT 0,0
    +CNEC_ESM: 50,0
    +CEREG: 1,"01B0","07C2B478",7,,,"11100000","11100000"
    [00:00:03.503,845] <inf> network: Network connectivity established
    +CSCON: 0
    +CSCON: 1
    [00:00:13.781,951] <inf> transport: Connected to MQTT broker
    [00:00:13.781,982] <inf> transport: Hostname: test.mosquitto.org
    [00:00:13.782,043] <inf> transport: Client ID: 352656106650388
    [00:00:13.782,043] <inf> transport: Port: 8883
    [00:00:13.782,073] <inf> transport: TLS: Yes
    [00:00:13.782,135] <inf> transport: Subscribing to: 352656106650388/my/subscribe/topic
    [00:00:13.894,958] <inf> transport: Subscribed to topic 352656106650388/my/subscribe/topic
    +CSCON: 0
    +CSCON: 1
    +CSCON: 0
    [00:01:00.413,665] <inf> transport: Published message: "Hello MQTT! Current uptime is: 60404" on topic: "352656106650388/my/publish/topic"
    +CSCON: 1
    +CSCON: 0
    +CSCON: 1
    +CSCON: 0
    [00:02:00.413,940] <inf> transport: Published message: "Hello MQTT! Current uptime is: 120404" on topic: "352656106650388/my/publish/topic"
    +CSCON: 1
    +CSCON: 0
    +CSCON: 1
    +CSCON: 0
    +CEREG: 1,"01B0","081A1682",7,,,"11100000","11100000"
    [00:03:00.414,215] <inf> transport: Published message: "Hello MQTT! Current uptime is: 180404" on topic: "352656106650388/my/publish/topic"
    +CSCON: 1
    +CSCON: 0

    So, thanks for your help.


    Regards,
    Rod

    PS my next step is to update the broker address, user name and password to allow me to connect to a different server but i will close this ticket and open a new one if required.

Related