Spark - arduino serial communication with dictionnary

Hi guys,
I was wondering if any of you know how to do a serial communication with the arduino using a dictionnary (hashmap) ? This need to be able to support a lot of variables (100).

Thanks !

@tchinou1, what exactly are you trying to achieve. Understanding the goal would help us better guide you. :smile:

The Spark receive a lot of variable from a MySQL database, it filters what it receive to check which variables have changed and it send the ones that have change to the arduino. The dictionary would be use to tell the arduino which variables it is receiving.
Hope I’m clear enough…

@tchinou1, do you need a hash table for this or could you simply use a one byte index for up to 255 variables? How are the variables referenced in the Core to begin with?

No, I don’t think I need a hash table maybe just a byte index would do the job. I just need the arduino to know what is the variable that the Spark is sending. For the moments, the variables, in the Spark, are in an array.

@tchinou1, make the array index your variable index as well. Then, you could duplicate the array in the Arduino and index directly into the target variable to update it. I assume all variables are the same size so your array is “homogeneous”?

@peekay123, The arduino is running a Vu meter, so the goal of the dictionary was to not needing to transfert the whole array every time there is a little change. The array is an made of value int (max 255).

@tchinou1, makes sense. The array to array via the common index is the easiest way to go. Sounds like a cool project. Why the Arduino versus all on the Core?

Can you tell me more about the array index, I never did that before and I can’t find anything useful on the web.
The Arduino is for 2 reason (tell me if you see an alternative), first I need to controle many RGB leds, so I use shift register ( http://www.elcojacobs.com/shiftpwm ) and this is not compatible with the core, second I use on the Spark this library: https://github.com/nmattisson/HttpClient to communicate with my database and the query take a couple of second to run (which can’t be used with a Vu meter)

@tchinou1, what I mean by the array index is the pointer into your array of values. I assume the Core keeps the same array of values as the Arduino and only sends the changes to the Arduino. So, if you have an array of unsigned 16 bit values for example:

uint16_t array[100];

Then the array index points to a specific value by using array[index]. So say array values 5, 14 and 77 change then you send the index number and the value at that array index to the Arduino:

5, array[5], 14, array[14], 77, array[77]

Then the Arduino parses the first byte and uses it as an index into its stored array and then parses the uint16_t and stores it there:

array[parsed index] = parsed uint16_t;

I hope that makes sense! :stuck_out_tongue: