MQTT simple example code (api based)

Hi Team,

We are using nRF9160 MQTT sample code 'mqtt_simple'. 

1. What is the maximum payload we can send in one single PUBLISH?

2. I want to send 4KB of data in single PUBLISH, is this possible? if not, what is the way to send 4KB in single PUBLISH?

3. Is the nRF9160 supports secure boot?

4. Is the nRF9160 has boot ROM? If yes, is this boot ROM available for us to add some piece of code in the boot ROM?

Regards,

Sravan Rikka

  • Hi Sravan,

    sravan.rikka said:
    1. In our application we will store 5000 records and each record of size 1429, hence total bytes=5000 *      1429=7145000. Hence, we are planning to transfer 7.145MB in single MQTT publish. It is possible right?

    Have you checked if there are any limitations on the broker side?

    sravan.rikka said:

    2. When I am copying float value into buf using sprintf I am not seeing any value in the buffer, why? whereas %d is working but %f is not working. Am I missing anything, please advice.

    float ambientTemperature = 24.5;
    len = snprintf(buf, sizeof(buf), "ambientTemperature=%f", ambientTemperature);
    printk(buf);

    I have used the following sample which correctly displays ambientTemperature value from the buffer buf.

    #include <stdio.h>
    
    char buf[200];
    int len;
    
    int main(void)
    {
        float ambientTemperature = 24.5;
        len = snprintf(buf, sizeof(buf), "ambientTemperature=%f", ambientTemperature);
        printf("buffer value is %s", buf);
    }

    Best regards,
    Dejan

  • Hi Dejan,

    1. Not yet, I will check broker side limitations.

    2. For me it is not working, I am using 'mqtt simple' example code. Please suggest me how to resolve this. Below are the header files in the main file. Do we need to add any other header file?

    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <string.h>
    #include <random/rand32.h>
    #include <net/mqtt.h>
    #include <net/socket.h>
    #include <modem/at_cmd.h>
    #include <modem/lte_lc.h>
    #include <logging/log.h>
    #if defined(CONFIG_MODEM_KEY_MGMT)
    #include <modem/modem_key_mgmt.h>
    #endif
    #if defined(CONFIG_LWM2M_CARRIER)
    #include <lwm2m_carrier.h>
    #endif
    #include <dk_buttons_and_leds.h>

    #include "certificates.h"

    Regards,

    Sravan Rikka

  • Hi Sravan,

    You can try to add this header file

    #include <zephyr/sys/printk.h>

    and these Kconfig options 
    CONFIG_PICOLIBC=y
    CONFIG_PICOLIBC_IO_FLOAT=y
    

    Best regards,
    Dejan

  • Hi Dejan,

    I have added #include <zephyr/sys/printk.h> but got compilation error as "zephyr/sys/printk.h: No such file or directory". then searched for printk.h and found that it was added like #include <sys/printk.h> and added same and no compilation error but still not seeing float values in snprintf buffer.

    Tried adding CONFIG_PICOLIBC=y and CONFIG_PICOLIBC_IO_FLOAT=y in .prj but code is not loading after adding these configuration, after removing able to load code. So, unable to add these to config, is there any other way to add it? please guide and help to resolve this issue.

    Regards,

    Sravan Rikka

  • Hi Sravan,

    I have tested in NCS v3.0.2, not in NCS v1.7.0. I am sorry that I forgot to mention this. In your case, it should be correct to use #include <sys/printk.h> instead of 
    #include <zephyr/sys/printk.h>.
    You could try to use Newlib. You can look at types of Newlib and its formatted output.

    Best regards,
    Dejan

Related