This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Sending MQTT messages using the data_publish function from the mqtt_simple sample

I am having some trouble with sending messages using MQTT on nRF9160DK. What I ultimately want to to is read UART and send whatever I receive to an MQTT broker. When running the mqtt_simple sample it is working as described at the fw-nrfconnect-nrf github repository, but when attempting to call data_publish() outside the mqtt_evt_handler() function it either does not send any data or the nRF9160 stops execution without any error messages. More specifically I am attepting to call data_publish() inside of the uart_cb() function from this example code.

I am using the PCA10090 0.8.2 version of the devkit with firmware version v1.0.0, NCS version v0.4.0 and v4.16 of SEGGER. I have also tried with firmware version v0.7.0.

Any and all help is greatly appreciated

Edit: Modified the original question slightly to reflect the actual problem I was having.

  • Hello, 

    First, please update to the latest version of NCS v1.0.0. This should work better with modem FW v1.0.0.

    What kind of output do you get via LTE Link Monitor in nRF Connect for Desktop?

    Kind regards,
    Øyvind

  • I updated NCS to v1.0.0 following Martin Lesund's instructions here. After building the mqtt_simple sample and downloading the merged.hex file I launched nRF Connect v3.0.0 and the LTE Link Monitor v1.0.0. When connecting the device and pressing the reset button on the devboard it gives this output. 

    I've tried rebuilding and downloading again, both with using the Programmer app v1.2.0 to clear the memory and without it. I have also tried doing this with the at_client sample.

    I have tried using the v1.0.0 tag previously, but it has given me some problems when building the solutions in SEGGER.

  • Should not give that output unless you have not updated the modem FW. Did you follow all the steps in Martins instructions? Have you ensured that SW5 is set to nRF91?

    Please try to delete all build folders in the at_client folder. When programming the device, can you please describe the steps you have used?


    Using a command line, can you please first issue:

    nrfjprog -e

    Then, still in the command line, find the folder where you have v1.0.0 of at_client e.g. nrf\samples\nrf9160\at_client\build\zephyr

    Standing in that folder, run the following (given that you have merged.hex file):

    nrfjprog --program merged.hex -f nrf91 --sectorerase -r --verify

  • I followed Martins instructions as he wrote them in the link from my original post, using the Programmer v1.2.0 application and the firmware 'mfw_nrf9160_1.0.0.zip'. I went through the same steps again now. In the Programmer app i clicked "Update modem" after clearing the memory with "Erase all". After selecting the firmware and clicking "Write":

    The PROG/DEBUG switch is set to nRF91, I don't think I've ever touched it.

    Before programming the device I made sure all build folders were deleted, the at-client sample folder looked like in the following picture: 

    When building the project in SEGGER I go to "File" and chose "Open nRF Connect SDK Project..." and enter the following:

    After loading the project:

    When first building the project it quite often fails, providing an output (this is just the end of the build log):

    Building ‘spm/zephyr/linker_pass_final.cmd’ from solution ‘build’ in configuration ‘Common’
    1> Combining ‘spm/zephyr/linker_pass_final.cmd’
    Building ‘spm/zephyr/CMakeFiles/spm_linker_pass_final_script_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘spm/zephyr/spm_linker_pass_final_script_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘spm/zephyr/isr_tables.c’ from solution ‘build’ in configuration ‘Common’
    1> Combining ‘spm/zephyr/isr_tables.c’
    Building ‘cmake_object_order_depends_target_spm_zephyr_final’ from solution ‘build’ in configuration ‘Common’
    Building ‘libspmsecureentries.a’ from solution ‘build’ in configuration ‘Common’
    1> Compiling ‘empty_file.c’
    2> Compiling ‘isr_tables.c’
    Building ‘spm/zephyr/zephyr.elf’ from solution ‘build’ in configuration ‘Common’
    1> Linking ‘libspmsecureentries.a’
    1> Post-link command 
    1> C:\gnuarmemb\bin\arm-none-eabi-objcopy.exe: 'zephyr.elf': No such file
    Build failed

    The build succeeded after I tried to "Build zephyr/zephyr.elf" before "Build Solution" again. I am assuming that I am doing something slightly wrong here or that I have some wrong settings. Nonetheless, I now have a merged.hex file. Normally I download this to the nRF9160 by connecting to it with J-link in SEGGER and chose the following before navigating to the corresponding build folder and selecting the merged.hex file:

    This time, however, I tried doing it like you suggested with the command line. I downloaded the latest nRF Command Line Tool here and followed your instructions. 

    PS C:\ncs\nrf\samples\nrf9160\at_client\build_nrf9160_pca10090ns\zephyr> nrfjprog -e
    Erasing user available code and UICR flash areas.
    Applying system reset.
    PS C:\ncs\nrf\samples\nrf9160\at_client\build_nrf9160_pca10090ns\zephyr> nrfjprog --program merged.hex -f nrf91 --sectorerase -r --verify
    Parsing hex file.
    Erasing page at address 0x0.
    Erasing page at address 0x1000.
    Erasing page at address 0x2000.
    Erasing page at address 0x3000.
    Erasing page at address 0x4000.
    Erasing page at address 0x5000.
    Erasing page at address 0x6000.
    Erasing page at address 0x7000.
    Erasing page at address 0xC000.
    Erasing page at address 0xD000.
    Erasing page at address 0xE000.
    Erasing page at address 0xF000.
    Erasing page at address 0x10000.
    Erasing page at address 0x11000.
    Erasing page at address 0x12000.
    Erasing page at address 0x13000.
    Erasing page at address 0x14000.
    Erasing page at address 0x15000.
    Erasing page at address 0x16000.
    Erasing page at address 0x17000.
    Erasing page at address 0x18000.
    Erasing page at address 0x19000.
    Erasing page at address 0x1A000.
    Erasing page at address 0x1B000.
    Erasing page at address 0x1C000.
    Erasing page at address 0x1D000.
    Erasing page at address 0x1E000.
    Erasing page at address 0x1F000.
    Erasing page at address 0x20000.
    Erasing page at address 0x21000.
    Erasing page at address 0x22000.
    Erasing page at address 0x23000.
    Erasing page at address 0x24000.
    Erasing page at address 0x25000.
    Erasing page at address 0x26000.
    Applying system reset.
    Checking that the area to write is not protected.
    Programming device.
    Verifying programming.
    Verified OK.
    Applying system reset.
    Run.
    PS C:\ncs\nrf\samples\nrf9160\at_client\build_nrf9160_pca10090ns\zephyr>

    After power cycling and connecting to the LTE Link Monitor and pressing reset again:

  • hfj said:
    I am assuming that I am doing something slightly wrong here or that I have some wrong settings.

    Yes, I think the issue lies in what project was built in the solution of SES. In SES you have Project 'zephyr/zephyr.elf' as Active when it should be Project 'zephyr/merged.hex'. Can you please Right-click on that project, and click "Set as Active project". This should be handled automatically. 

Related