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 Dejan,

    I started again with a clean build, refreshed modem firmware etc. I also enabled the RTS/CTS signals on the trace port and am now seeing some traces.

    6811.test.pcapng

    Regards,

    Rod

  • Hi Rod,

    Do you still get the same error in the application log (shown below)?

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

    If there is any difference, please provide new application log.

    Best regards,
    Dejan

  • Hi Dejan,

    Yes, still getting the same error.

    *** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
    *** Using ZK OS v3.6.99-100befc70c74 ***
    [00:00:00.404,541] <ifrݽɭ: Bringing network interface up and connecting to the Sݽɭm[0m
    [00:00:00.405,151] <dbg> mqtt_helper: mqtt_stae5: State transition: MQTT_STATE_UNINIT --> MQTT_STATE_DISCONECTED
    [00:00:00.435,607] <dbg> mqtt_helper: mqtt_helper_poll_loop:aiting for connection_poll_sem
    [00:00:00.633,056] <i> nrf_modem_lib_trace: Trace thread ready
    [00:00:00.640,3NW<inf> nrf_modem_lib_trace: Trace level override: 2
    A҂҂r41,937] <err> lte_lc: Could not send AT command, error: 65536
    [00:00:00.641,967] <err> lte_lc: Failed to set system mode and mode preference, err -14

    Regards, Rod

  • Hi Rod,

    What is your current modem firmware version?

    When I compare your trace file with the trace file for nrf9160-dk, there seem to be no connection procedure or attachment attempt in your log. Can you take a longer modem trace which would potentially show that?

    Best regards,
    Dejan

Reply Children
  • 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

Related