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.
Parents Reply
  • 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.

Children
No Data
Related