how to protocol buffers with ncs

hello Nordic 

we are working with nrf52832 and nrf52840 running with ncs v2.5.0 (waiting for v2.7.0 cause 2.6.0 have some issues with cmsis fft tables that prevent us from upgrading)

anyway,

we are saving some data to external flash using little fs and we need to organise and save the data as a protobuf file.

i know zephyr embed some implementation of protobufs, is there some example on ncs, or some guide how to work with it, how much space of flash and RAM is required, is there some limitation on schema etc. ?

hope to read from you soon

best regards

Ziv

  • Hello,

    In the NRF Connect SDK, there is a simple protocol buffer sample using Nanopb for serialising structured data to platform-independent raw buffers. See the Nanopb sample.

    Kind Regards,

    Abhijith

  • Hi Menon

    tried to follow the sample but i get this error when i build:

    CMakeFiles/app.dir/src/sample.pb.c.obj -MF CMakeFiles/app.dir/src/sample.pb.c.obj.d -o CMakeFiles/app.dir/src/sample.pb.c.obj -c src/sample.pb.c
    src/sample.pb.c:4:10: fatal error: src/sample.pb.h: No such file or directory
        4 | #include "src/sample.pb.h"
          |          ^~~~~~~~~~~~~~~~~

    i added my .proto file same level as main.c, under my_app/src/ .. my cmake addition:

    ...
    set(NANOPB_OPTIONS "-I${CMAKE_SOURCE_DIR}")
    nanopb_generate_cpp(proto_sources proto_headers RELPATH .
        src/sample.proto
    )
    ...
    target_sources(app PRIVATE ${proto_sources} ${app_sources})
    

    the files are generated in the /build/src dir, and both of them are there (the .c file is generated with include path src/sample.pb.h, though the .h file is in the same dir the .c file is so i don't know if that is not the issue, but it is self generated) so i don't understand why i get this error.

    also i wonder if it will be an issue cause we are using the same code base for several boards with different builds and we do not want to have different include path in the code for each board.. any idea how to manage that ?

    hope to read from you soon

    best regards

    Ziv

  • Hey

    so i managed to solve the compilation issue with the addition of this :

    zephyr_include_directories(${CMAKE_CURRENT_BINARY_DIR})
    

    i look at the example and it is very simple case , is there some guide or example how to work with a .proto buf which has several messages with fields and messages as fields of some other messages  ?

    and with streaming of the encoded protobuf in chunks since we can not have all the data of the protobuf available on RAM  ?

    hope you can help with some guidance here 

    best regards

    Ziv

  • Hello,

    I guess this is a much better query for Zephyr Discord. We don't have much documentation or guidance for the protocol buffer. The sample I shared was also from Zephyr.

    Kind Regards,

    Abhijith

  • that was not very helpful unfortunately

    you can close this thread, i don't think i can mark "verify Answer" on that 

Related