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


#1

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


#2

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:


#3

Thanks,Actually I am trying to use Google Protocol Buffer


#4

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.


#5

I have tried nanopd on Photon,It works.


#6

You will integrate nanopd to Particle system firmware lib?


#7

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.


#8

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


#9

@ming, have you looked at the documentation?

https://docs.particle.io/reference/firmware/electron/#particle-function-

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.


#10

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.


#11

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