Anyone know how to modify Particle.function() to support binary payload?

how to modify Particle.function() to support binary payload and a larger payload?

The Particle.function payload is limited to 63 bytes of UTF-8 characters. It must be text, it can’t be binary data, and you can’t make it any longer as the limit is enforced by both system firmware and the cloud.

In order to send binary data you typically need to use a binary-to-text encoding such as Base64 or Base85.

Using Base64, 3 8-bit bytes in binary are converted to 4 ASCII characters, so the payload would be reduced to 45 bytes of binary data.

This is my Base64 library for Particle devices:

Thanks,Actually I am trying to use Google Protocol Buffer

There is a nanopb project on github that makes a simplified protocol buffer work for Arduino. I would start there. You are likely to quick run out of code space on your device trying to compile the Google PBs for Particle.

I have tried nanopd on Photon,It works.

1 Like

You will integrate nanopd to Particle system firmware lib?

I guess @bko meant, if he was in your position he would do it.
However he isn’t but you are I’d say he’s suggesting you’d do that :wink:

But it will definetly not be integrated into the system firmware.

1 Like

I have try nanopb,It can work on Photon.
What I need it is binary payload support.
I there any information about Particle.function()?

@ming, have you looked at the documentation?

Particle.function() DOES NOT support binary payloads and cannot be adapted to do so since the Particle Cloud does not support it either. Your ONLY options are to encode the binary data as suggested earlier or use nanopb. Or, use raw TCP/UDP to create your own protocol and payloads.

1 Like

Hi @ming

In my post above I was warning you that regular Google PB was not going to work on Particle devices since it is too big. Nanopb is a good option, but I have not personally tried it.

For larger binary payloads to Particle.function, and from Particle.variable and Particle.publish, I think you should investigate using base-64 or base-85 encoding. Those are the common techniques, but I have not used them myself on Particle devices.

1 Like

Are you sure nanopb+Particle.function can work without binary payload feature support?