As I see in firmware repo, Device OS is using Protobuf via nanopb library. I want send Protobuf messages via Particle.publish(), as payload of event. This will be used by external system. How to include nanopb functionality to code? Because when I tried to add headers related to nanopb, I received undefined reference to function.
The system firmware or Device OS is built in a modular way that it can be replaced separately from the user code. This all happens through a hardware adaptation layer (HAL) that defines all the possible entry points into the system firmware. The problem you are having is that the nanopb library is not exposed in the HAL layer.
Your best bet is to copy the library and add it to your project as you would for any other third-party library. I think it would be difficult to convince Particle to add the nanopb stuff to the HAL since it has limited use cases, but you could file a github issue on the Particle firmware repo and ask.
You will eventually have to serialize your data for Particle.publish as a limited set of ASCII characters using base-64 or base-85 encoding.
I asked a similar question in the past.
The ability to use a binary publish() payload encoding will help those of us with cellular uplink bills.
Do you mean using Particle.publish() with the payload encoded using CBOR?
Correct. CBOR, Protobuf, whatever. Some option to use a binary encoded publish() instead of text.
Yes, okay I agree, but nanopb is part of Device OS (looked at Github repo Device OS), so it should be available, maybe there is option in linker which should set up?
If you compile locally with gcc and in monolithic form (one large binary) then you can access the symbols for nanopb. You would give up on over-the-air updates and a few other nice things, but it would work fine.
If you want to use the any of the non-local compile methods and/or over-the-air update, you need to copy the library.