Author Topic: Send multidimensional array  (Read 691 times)

hakunin

  • Newbie
  • *
  • Posts: 10
Send multidimensional array
« on: March 08, 2018, 01:57:16 PM »
Hi,
what's the best solution to send a multidimensional array using the RFM69 library?
I have an array like these:
{10,5;
   3,8;
   34,5;
....}

int arrayData[120][2]

Should I send every single element using a for loop or create a long string of about 30byte like this "10,5;3,8;34,5" and then send it?
Thanks in advance for your help
Sincerely
« Last Edit: March 08, 2018, 01:59:48 PM by hakunin »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5996
  • Country: us
    • LowPowerLab
Re: Send multidimensional array
« Reply #1 on: March 08, 2018, 02:38:00 PM »
It all comes down to how you'd like to package/encode your array on the sending side, and unpackage/decode it on the other end.
Is your array already in C code? Or is it something like JSON?

hakunin

  • Newbie
  • *
  • Posts: 10
Re: Send multidimensional array
« Reply #2 on: March 08, 2018, 04:56:10 PM »
Hi Felix,
thanks for the quick reply.
At the moment I have a Moteiono sending a message containing different sensor data like this: "-15,100,10,252,z"
Code: [Select]
   sprintf(sendBuf, "%s,%s,%s,%s,z", tempStr, humStr, uvStr, capStr);
   sendLen = strlen(sendBuf);
if (radio.sendWithRetry(INT_NODEID, sendBuf, sendLen))
and on the receiving node:
Code: [Select]
 for (byte i = 0; i < radio.DATALEN; i++){
     
   
        char ch = radio.DATA[i];
Now I want to add an other sender to the network. I haven't written the code yet, but the idea is to read every few seconds from a INA219, accumulate the data in the two dim array (current,  voltage), send this data every 15 min. So the array would be in C, no JSON. I can keep similar code for receving the data, or change it, no problem.


Uncle Buzz

  • Full Member
  • ***
  • Posts: 100
  • Country: fr
Re: Send multidimensional array
« Reply #3 on: March 09, 2018, 03:26:07 AM »
Your array is quite big, it contains 240 values to send.

To reduce amount of bytes to send, maybe can you send raw value from INA219 (bytes and not decimal which would probably be send as chars) and build decimal values on receiver ?
INA219 has 12 bit resolution on current (shunt voltage) and voltage, so at least 24 bits = 3 bytes for each couple.

Even with this way, your array needs many transmissions to be sent, why filling your array during 15 minutes then send all this data and not sending them at higher frequency with smaller array ?

ChemE

  • Sr. Member
  • ****
  • Posts: 402
  • Country: us
Re: Send multidimensional array
« Reply #4 on: March 09, 2018, 08:59:25 AM »
I agree with Uncle_Buzz that you will need to send more frequently since the RFM69 library limits your payload to 61 bytes or 15 actual integer values.  I noticed you are declaring an array of integers but packing it with bytes based on your sample data.  That wastes 50% of the space so make sure you are not transmitting those empty bytes.  Beyond that, if you data lends itself to it, you can actually pack it into bytes.  The classic example is 8 boolean values.  You can pack those into a single byte where each bit represents a true/false.  Similarly, if you have data that ranges from 0-32 that only takes 4 bits not 8 (byte) or 16 (integer).

For instance your sample data:

 like this "10,5;3,8;34,5" and then send it?

10 needs 5 bits, 5 needs 3 bits so you can pack those into a single byte.  That only works if those values are both bounded from 0-16.  The next two values 3 and 8 can both be stuffed into a single byte.  Only the last pair takes 9 bits to represent.
« Last Edit: March 09, 2018, 01:40:21 PM by Felix »

hakunin

  • Newbie
  • *
  • Posts: 10
Re: Send multidimensional array
« Reply #5 on: March 09, 2018, 04:45:22 PM »
Thank you all for your suggestions. I'll try them and see what works best.
I transmit the data every 15 minutes to save energy, but I can try to reduce the interval.
Thank you
Sincerely

Uncle Buzz

  • Full Member
  • ***
  • Posts: 100
  • Country: fr
Re: Send multidimensional array
« Reply #6 on: March 09, 2018, 05:44:40 PM »
Sending RF message is consuming energy, but sending 1 message each minutes will cost about the same energy than sending 15 messages each 15 minutes, so you could determine how much data you can send in 1 transmission, and set your frequency of transmission to send your data as soon as they fullfill the max payload you can send.