Mesh.Publish a byte array

Hello everyone,

I am currently developing a solution that involves transmitting data between mesh devices and eventually publishing to the cloud servers via 2G/3G. Being an old school developer I typically convert numerical values into bytes (e.g a short into 2 bytes) before transmission. This reduces the number of bytes being sent in each packet whenever a number is over 99

The problem I am having is with .publish(). This takes a char array and when I try to send the number 0 (A sensor reading for flow) it comes through as 256. I am guessing this is to do with the fact that the number 0 in a short is two bytes of char(0). This is a null char and probably the escape character for the received char string and therefore being chopped off the received char array on the other side.

My question is can I send a byte array of a fixed length through the Mesh.Publish command. It may seem like a small saving but sending a number like β€œ32000” would use 5 bytes of data in a char array but only two bytes as a short. This adds up over time especially when data transfer can cost a premium (2G/3G etc)

Any ideas that might help me solve this?

Kind regards,
Paul

The common solution for that would be base64 or base85 encoding as a compromise between wasting data and the fact that you only can use a subset of the 256 values for a byte in the protocol used for xxxx.publish().

Alternatively you could use UDP for binary transmission - tho’ unencrypted.

2 Likes