Im thinking that maybe instead of explaining how im doing things, I should explain WHAT im trying to do.Task
-Remote wireless sensor modules take periodic (10 min) measurements, which are send over XBEE radios, eventually going into SQL databases/GUI's etc.
-Transmitted data consists of ints/string/floats of varying sizes. Total payload size is roughly 40-50 bytes (/10 min)
-The base (PC) of the network runs a JAVA program for receiving/decoding the XBEE packets (API mode for those interested, using the XBEE API on both Arduino as well as PC side)Current solution
Current solution is to convert and concat all data to a string, perform getBytes() and fill the XBEE payload (uint8_t) with these bytes.Why use String?
There are a number of reasons for me to use String. Note that although experienced with Arduino, Im no wizard or something
-Easy to add info (in String format) and easy to concat the arrays
-Easy to extract the bytes and populate payload
Because the payload is of type uint8_t type, it can be filled simply by the String.getBytes() method. Manually inserting ints in the array is even pointless, Id have to convert them to individual bytes, and decode/convert everything on the other side again.
-Easy to send and decode the float measurements.
In my JAVA programming experience, I've had the "pleasure" of reading out sensor registers which stored floats in their original 4 bytes, and had to decode them manually. This was quite frustrating, with the endian and signed/unsigned nature of the bytes involved. Somehow the built in methods didnt work....
Now with Arduino, instead of adding the four bytes to the payload, I just convert the float to String, sdend over the char, and decoding becomes easy at the JAVA side, or even unnecessary (as SQL querys are String as well).
Additionally, the dtostrf(float,dec,min.width,string);
method gives the opportunity to trim the floats and specify decimals.Alternative?
Im sure there are alternatives, but I wouldnt know them (yet), and as this concerns a prototype, im happy it works the way I want it to. If you guys have any suggestions, you're welcome. Ive learned to program mainly in JAVA (LabView before that
), so quite high level. Although Im confident I can program what I want and need on Arduino, the really lower stuff like malloc...I know what it does and could work with it given some time, but I dont fully understand all the possibilities and limitations.
So lets say that, going by previous comments, I fix the payload array length. Knowing I send over 40-50 bytes only once every 10 minutes, what changes are really worth it, if at all?
I appreciate your thoughts.