LowPowerLab Forum

Hardware support => General topics => Topic started by: jarrods on May 11, 2015, 02:39:53 PM

Title: Message Formating
Post by: jarrods on May 11, 2015, 02:39:53 PM
Hello fellow Moteino"ians",

I have been working on a project for a while, and although I can't publish the project yet, I wanted to share a discovery that has helped significant cut down on message sizes and allows for maintaining types. One issue I had once I started adding lots of sensors and many nodes was how long messages were (having to do 2 or 3 sends to get all the data out) and how much traffic this resulted in. One way this is solved with wireless devices like Android is called serialization. 2 popular ones are Protocol Buffers and Capt Proto. Also I know there was a Discussion about MDTT a whiel back but in my opinion all these were to heavy to run well on a Moteino..

In steps Tiny Packs: https://github.com/francc/tinypacks  (https://github.com/francc/tinypacks) This nice little  library helps serialize data on 8bit and 16bit MCUs. It is very light weight and does not have a Fixed structure (like the Struct examples). The guy even has examples on how to unpack the data in Python and turn it into JSON.

Check it out.

- Jarrod
Title: Re: Message Formating
Post by: Felix on May 11, 2015, 04:02:11 PM
Nice stuff, but i wonder how much RAM is used with all the luxury you get with such a library.
Title: Re: Message Formating
Post by: jarrods on May 12, 2015, 12:19:13 AM
Well I had been using Strings and Chars to send data back and was getting warnings about memory usage and flash size. Now that I am using this I have dropped back down into the "safe" memory usage range. I did not take any actual measurements though. If you used a Struct it will be smaller but then everyone has to have the same description for the Struct. If later you want to add an element it can be a challenge.

Also this Library does not have float support, so I am what I have been doing is turning the data into Ints (f * 100)
Title: Re: Message Formating
Post by: TomWS on May 12, 2015, 07:51:59 AM
Quote from: jarrods on May 12, 2015, 12:19:13 AM
Well I had been using Strings and Chars to send data back and was getting warnings about memory usage and flash size. <snip>
If you use the 'F' macro for character constants, which moves the constants to program memory, you can save a lot of room in RAM.  Example:


Serial.print("This takes up space in RAM");
Serial.print( F("This does NOT take up space in RAM") );
sprintf(buf, F("Unfortunately, this does not work!!!  :-(") );

Tom