How to control character set used by Particle.publish?


I’m trying to propagate information via webhook. This information will be mostly read by applications that will interpret it to make it readable by users. As the plateform I’m using is the Electron, each byte cost money. So rather than sending characters, I would prefer sending row bytes (i.e. transferring one int such as timestamps, requires 4 bytes… but up to 10 characters).

But I face two issues:

The first one is that webhook only accept char as data. Therefore, I cannot transfer the value 0. But for this I found a solution (just remove zeros have replace them with their position value)

The second one, THE ONE FOR WHICH I’M WRITING THIS POST, is that Particle.publish allow only ASCII characters until code 7E.

Unfortunately, I’ve so far I failed to find a solution to force Particle.publish to use ASCII extended code.

I’m aware that I’m pushing a bit the limit of the Particle.publish function. But any help would be welcome.

Thanks in advance for any help received.

AFAIK, that’s not actually a problem with Particle.publish() but rather the transport layer, which Particle can’t do a lot about (it’s “hardwired” in the internet).
But you could use some sort of standard translation like Base64 encoding.

Thank you Scruff,

That’s were my knowledge of technology become a bit more fuzzy.

I’ve investigated Base64 encoding from a high level. And did discarded it first because it seems to be contreproductive in term of data transfer optimization. I’ll nevertheless have a second deeper look.

My other option is of course to implement my own client/server over a TCP connection.

But that is something I would really like to avoid. Particle have done a fantastic job at providing reliable cloud service. And I’m not that good to implement such service.

Best regards.

You can also look into less common encoding schemes like Base85 or Base96.
Or even your own propriatory encoding that’s tailor made for your range of values.

e.g. with timestamps, cut out the date information (adding the current date back on the receiving end) and reduce the precission down to minutes, you’ll fit the minute of a day into 11bit - with quater hours, you’ll only need one 7bit and using a constant offset to remove the ‘\0’-issue.

Thank you ScruffR,

I will look into Base85 that look well covered in term of programming libraries.

You are right for timestamp improvement. I’m just worried about usecases I’ve not in mind yet that will cause problem later on.

Best regards

1 Like

As a little feedback, I did add Base85 support to my application and after a few twicking (i.e do not use characters such as < or > or & that are modified during the transmission through webhook) the system work like a charm.

Thank again ScruffR.