Migrating MQTT Sample to a Custom Board

Hi,

I have successfully built and ran the MQTT sample (/opt/nordic/ncs/v2.7.0/nrf/samples/net/mqtt) on the nRF9160-DK. I did have a few problems with SIM coverage and firmware versions which was sorted in this ticket.

 MQTT Sample Not Connecting on nRF9160 Board 

I would now like to move this code onto my own board.

When I run this code on my own board, I see this error.

*** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
*** Using Zephyr OS v3.6.99-100befc70c74 ***
[00:00:00.431,610] <inf> network: Bringing network interface up and connecting to the network
[00:00:00.658,813] <inf> nrf_modem_lib_trace: Trace thread ready
[00:00:00.666,107] <inf> nrf_modem_lib_trace: Trace level override: 2
[00:00:00.667,724] <err> lte_lc: Could not send AT command, error: 65536
[00:00:00.667,755] <err> lte_lc: Failed to set system mode and mode preference, err -14
+CEREG: 2
+CEREG: 4
+CEREG: 2,"B984","00542616",9
+CSCON: 1
+CEREG: 2,"B984","00542616",9,0,11
+CSCON: 0
 

My overlay file is shown below.

&pinctrl {
        uart0_default: uart0_default {
                group1 {
                        psels = <NRF_PSEL(UART_TX, 0, 6)>, <NRF_PSEL(UART_RX, 0, 7)>;
                };
        };

        uart0_sleep: uart0_sleep {
                group1 {
                        psels = <NRF_PSEL(UART_TX, 0, 6)>, <NRF_PSEL(UART_RX, 0, 7)>;
                        low-power-enable;
                };
        };
};

&uart0 {
        status = "okay";
        current-speed = < 115200 >;
        /delete-property/ rts-pin;
        /delete-property/ cts-pin;
};

/* Enable uart1 for tracing. */

&uart1 {
   status = "okay";
   current-speed = <1000000>;
   pinctrl-0 = <&uart1_default>;
   pinctrl-1 = <&uart1_sleep>;
   pinctrl-names = "default", "sleep";
};

/ {
   chosen {
      nordic,modem-trace-uart = &uart1;
   };
};

I use UART0 for my serial terminal.

Would appreciate your pointers on this,

Thanks,

Rod 

Parents
  • Hi Rod,

    Did you manage to collect a modem trace through either uart1 or RTT terminal?

    I see you also play with link monitor before. If this is a new custom board, are you able to see it can successfully connect with network when you check with link monitor after programming Serial LTE modem (nordicsemi.com)?

    Best regards,

    Charlie

  • Hi Charlie,

    No, I didn't manage to get the trace to work.

    I tried the serial LTE example,

    / {
    	chosen {
    		ncs,slm-uart = &uart1;
    	};
    };
    
    &uart0 {
    	status = "okay";
    	hw-flow-control;
    };
    
    &uart1 {
    	compatible = "nordic,nrf-uarte";
    	current-speed = <115200>;
    	status = "okay";
    
    	pinctrl-0 = <&uart1_default_alt>;
    	pinctrl-1 = <&uart1_sleep_alt>;
    	pinctrl-names = "default", "sleep";
    };
    
    
    
    &i2c2 {
    	status = "disabled";
    };
    
    &pinctrl {
    	uart1_default_alt: uart1_default_alt {
    		group1 {
    			psels = <NRF_PSEL(UART_RX, 0, 7)>;
    			bias-pull-up;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_TX, 0, 6)>;
    		};
    	};
    
    	uart1_sleep_alt: uart1_sleep_alt {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 6)>,
    				<NRF_PSEL(UART_RX, 0, 7)>;
    			low-power-enable;
    		};
    	};
    };
    

    I am using my own overlay file, above to redirect the serial. terminal.

    Im getting this as an output

    All pins have been configured as non-secure
    [Sec Thread] Secure image initializing!
    TF-M Float ABI: Hard
    Lazy stacking enabled
    Booting TF-M v2.0.0-ncs2
    Ready

    Rod

  • Hi Rod,

    I will look into this during next week.
    I expect to get back to you by the end of next week.

    Best regards,
    Dejan

  • Hi Rod,

    AT%XSYSTEMMODE command is allowed only before activating the modem using AT+CFUN=1. Before changing the system mode, you could try to put the modem in a required state using AT+CFUN=0 (or AT+CFUN=4).

    Best regards,
    Dejan 

  • Hi Dejan,

    I am running the "standard mqtt sample", (nrf/samples/net/mqtt) unmodified; so have not touched the code. It runs fine on the nRF9160DK board. 

    I tried another one of my boards and it seems to work, although I cant see any traces on the UART on the second board. This is what I see on the serial terminal.

    [00:00:00.721,435] <inf> nrf_modem_lib_trace: Trace thread ready
    [00:00:00.722,595] <inf> nrf_modem_lib_trace: Trace level override: 2
    [00:00:00.724,426] <err> lte_lc: Could not send AT command, error: 65536
    [00:00:00.724,456] <err> lte_lc: Failed to set system mode and mode preference, err -14
    [00:00:02.118,682] <wrn> nrf_modem_lib_netif: lte_lc_modem_events_enable, error: -14
    +CEREG: 2,"01B0","0928D982",7,0,0,"11100000","11100000"
    [00:00:16.853,210] <wrn> lte_lc: Registration rejected, EMM cause: 0, Cell ID: 153672066, Tracking area: 432, LTE mode: 7
    +CSCON: 1
    +CGEV: ME PDN ACT 0,0
    +CNEC_ESM: 50,0
    +CEREG: 1,"01B0","0928D982",7,,,"11100000","11100000"
    [00:00:19.289,672] <inf> network: Network connectivity established
    +CSCON: 0
    +CSCON: 1
    +CSCON: 0
    +CSCON: 1
    [00:00:45.602,630] <inf> transport: Connected to MQTT broker
    [00:00:45.602,691] <inf> transport: Hostname: test.mosquitto.org
    [00:00:45.602,722] <inf> transport: Client ID: 352656100493439
    [00:00:45.602,722] <inf> transport: Port: 8883
    [00:00:45.602,752] <inf> transport: TLS: Yes
    [00:00:45.602,813] <inf> transport: Subscribing to: 352656100493439/my/subscribe/topic
    [00:00:46.262,634] <inf> transport: Subscribed to topic 352656100493439/my/subscribe/topic
    [00:00:46.606,658] <inf> transport: Published message: "Hello MQTT! Current uptime is: 46605" on topic: "352656100493439/my/publish/topic"
    [00:00:46.627,716] <inf> transport: Published message: "Hello MQTT! Current uptime is: 46626" on topic: "352656100493439/my/publish/topic"
    [00:00:46.640,441] <inf> transport: Published message: "Hello MQTT! Current uptime is: 46639" on topic: "352656100493439/my/publish/topic"
    [00:00:46.653,015] <inf> transport: Published message: "Hello MQTT! Current uptime is: 46651" on topic: "352656100493439/my/publish/topic"
    [00:00:46.664,398] <inf> transport: Published message: "Hello MQTT! Current uptime is: 46663" on topic: "352656100493439/my/publish/topic"

    So, summarise.

    When i run the code on one of my boards, i get a trace on UART0 but the board does not connect to the network.

    When i run the same code on another board, (exact same hardware, same code, same SIM card etc). It does connect but I do not see a trace. 

    I have flashed both boards with the latest modem firmware. 

    Apart from the possibility of a hardware fault, is there anything else i am missing?

    Thanks,

    Rod

  • Hi Rod,

    Is provided log from working board?

    I have tested unmodified MQTT sample in NCS v2.8.0 on the nrf9160-dk without additional overlay files and I got the log shown below.

    *** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
    *** Using Zephyr OS v3.7.99-0bc3393fb112 ***
    [00:00:00.293,273] <inf> network: Bringing network interface up and connecting to the network
    [00:00:00.529,693] <inf> nrf_modem_lib_trace: Trace thread ready
    [00:00:00.537,322] <inf> nrf_modem_lib_trace: Trace level override: 2
    +CEREG: 2,"816C","03138801",7
    +CSCON: 1
    +CGEV: ME PDN ACT 0
    %MDMEV: SEARCH STATUS 2
    +CEREG: 1,"816C","03138801",7,,,"00001010","11000001"
    [00:00:02.594,238] <inf> network: Network connectivity established
    +CGEV: IPV6 0
    [00:00:08.326,416] <inf> transport: Connected to MQTT broker
    [00:00:08.326,477] <inf> transport: Hostname: test.mosquitto.org
    [00:00:08.326,507] <inf> transport: Client ID: 351358811129656
    [00:00:08.326,538] <inf> transport: Port: 1883
    [00:00:08.326,568] <inf> transport: TLS: No
    [00:00:08.326,599] <inf> transport: Subscribing to: 351358811129656/my/subscribe/topic
    [00:00:08.593,536] <inf> transport: Subscribed to topic 351358811129656/my/subscribe/topic
    +CSCON: 0
    [00:01:00.303,436] <inf> transport: Published message: "Hello MQTT! Current uptime is: 60294" on topic: "351358811129656/my/publish/topic"
    %MDMEV: SEARCH STATUS 2
    +CSCON: 1
    +CSCON: 0
    [00:02:00.303,680] <inf> transport: Published message: "Hello MQTT! Current uptime is: 120294" on topic: "351358811129656/my/publish/topic"
    %MDMEV: SEARCH STATUS 2
    +CSCON: 1
    +CSCON: 0
    


    There is a difference in our logs regarding TLS. Your log shows "<inf> transport: TLS: Yes". Which NCS version did you use for the latest testing and how did you build the sample?

    RodWatt said:
    I have flashed both boards with the latest modem firmware.

    You mentioned previously that you used modem firmware v1.3.6. However, the most recent version is v1.3.7. Are your boards flashed with modem firmware v1.3.6 or v1.3.7?

    Best regards,
    Dejan

Reply
  • Hi Rod,

    Is provided log from working board?

    I have tested unmodified MQTT sample in NCS v2.8.0 on the nrf9160-dk without additional overlay files and I got the log shown below.

    *** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
    *** Using Zephyr OS v3.7.99-0bc3393fb112 ***
    [00:00:00.293,273] <inf> network: Bringing network interface up and connecting to the network
    [00:00:00.529,693] <inf> nrf_modem_lib_trace: Trace thread ready
    [00:00:00.537,322] <inf> nrf_modem_lib_trace: Trace level override: 2
    +CEREG: 2,"816C","03138801",7
    +CSCON: 1
    +CGEV: ME PDN ACT 0
    %MDMEV: SEARCH STATUS 2
    +CEREG: 1,"816C","03138801",7,,,"00001010","11000001"
    [00:00:02.594,238] <inf> network: Network connectivity established
    +CGEV: IPV6 0
    [00:00:08.326,416] <inf> transport: Connected to MQTT broker
    [00:00:08.326,477] <inf> transport: Hostname: test.mosquitto.org
    [00:00:08.326,507] <inf> transport: Client ID: 351358811129656
    [00:00:08.326,538] <inf> transport: Port: 1883
    [00:00:08.326,568] <inf> transport: TLS: No
    [00:00:08.326,599] <inf> transport: Subscribing to: 351358811129656/my/subscribe/topic
    [00:00:08.593,536] <inf> transport: Subscribed to topic 351358811129656/my/subscribe/topic
    +CSCON: 0
    [00:01:00.303,436] <inf> transport: Published message: "Hello MQTT! Current uptime is: 60294" on topic: "351358811129656/my/publish/topic"
    %MDMEV: SEARCH STATUS 2
    +CSCON: 1
    +CSCON: 0
    [00:02:00.303,680] <inf> transport: Published message: "Hello MQTT! Current uptime is: 120294" on topic: "351358811129656/my/publish/topic"
    %MDMEV: SEARCH STATUS 2
    +CSCON: 1
    +CSCON: 0
    


    There is a difference in our logs regarding TLS. Your log shows "<inf> transport: TLS: Yes". Which NCS version did you use for the latest testing and how did you build the sample?

    RodWatt said:
    I have flashed both boards with the latest modem firmware.

    You mentioned previously that you used modem firmware v1.3.6. However, the most recent version is v1.3.7. Are your boards flashed with modem firmware v1.3.6 or v1.3.7?

    Best regards,
    Dejan

Children
  • Hi Dejan,

    I have tried building with and without TLS

    I have tried this

    west build --pristine -b nrf9160dk_nrf9160_ns -- -DEXTRA_CONF_FILE=overlay-tls-nrf91.conf -DDTC_OVERLAY_FILE=./boards/my_board.overlay

    and this

    west build --pristine -b nrf9160dk_nrf9160_ns -- -DDTC_OVERLAY_FILE=./boards/my_board.overlay

    I am using vs2.8.0 and have tried both version 1.3.6 and 1.3.7 firmware.

    I have gone back to 1.3.6 and rebuilt. and it appears to be working! Here is my trace file.

    Test-26_11_24.pcapng

    Rod

Related