This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Convert int64_t to string

I'm using NCS 1.8.0 and nRF9160 DK, and I need to convert unix_time from int64_t to string, my problem is exactly what is reported in these cases:

devzone.nordicsemi.com/.../snprintf-int64_t-not-working
https://devzone.nordicsemi.com/f/nordic-q-a/83967/long-long-int-value-sprintf

My conversion attempts can be seen below, but in all of them I don't get the number in value_buf_time, but I get lu.

snprintf(value_buf_time, sizeof(value_buf_time), "%"PRIu64, unix_time_ms);
printk("Publicando o time: %s ",value_buf_time);
or
snprintf(value_buf_timesizeof(value_buf_time), "%ld"unix_time_ms);
printk("Publicando o time: %s ",value_buf_time);
or
snprintf(value_buf_timesizeof(value_buf_time), "%lld"unix_time_ms);
printk("Publicando o time: %s ",value_buf_time);
The output of all printk is:
 
Publicando o time: lu
 
In other cases the solution was to insert CONFIG_NEWLIB_LIBC_NANO=n. But I can't insert this because when I have LIBC_NANO=n I end up getting a HARD_FAULT in the lte_lc_init_and_connect() function call. Is there another solution to make this conversion work?
Thank you.
  • Ainda não consigo reproduzir a falha grave.

    Did you add the settings below to prj.conf and no errors occurred?

    CONFIG_DATE_TIME=y

    CONFIG_DATE_TIME_MODEM=y

    CONFIG_NEWLIB_LIBC_NANO=n

    I'm using NCS 1.8.0 and just add these lines to the sample for the error to occur! If you did this and the errors did not occur, could you send me your sample?

    In the mqtt_simple sample I have the stack size configured like this:

    CONFIG_MAIN_STACK_SIZE=4096

    CONFIG_HEAP_MEM_POOL_SIZE=2048

    Even if I put the settings below the error still appears!
    CONFIG_MAIN_STACK_SIZE=16384
    CONFIG_HEAP_MEM_POOL_SIZE=16384
  • Hello Gabriel,

    Thabet said:
    Did you add the settings below to prj.conf and no errors occurred?

    Yes.

    Thabet said:
    If you did this and the errors did not occur, could you send me your sample?

    Attached you find the modified mqtt_simple application. Note that it is based on NCS v1.9.1, so not sure it will compile in NCS v1.8.0.



    Regards,

    Markus

  • Hello Markus,

    This download link has problems (Page Not Found).

    I will update the NCS and see if this error persists!

  • Thabet said:
    This download link has problems (Page Not Found).

    My apologies for that! This hopefully works better now :-)



    Regards,

    Markus

  • Hello Markus,

    Now I understand why you couldn't reproduce the error, probably this bug was resolved in NCS 1.9.1.

    For anyone encountering int64 to string conversion issues, getting errors when disabling NEWLIB_LIBC_NANO, please know that this has been fixed in NCS 1.9.1!

    I updated to NCS 1.9.1 and now my firmware works without errors, I can disable LIBC_NANO and perform the int64 to string conversion as expected.

    Thank you very much Markus for reporting that you couldn't find my error in NCS 1.9.1.

Related