I have a wifly wifi shield that I'm using to grab data from a webserver. It grabs one text file off the webserver that contains 8 data values. Currently my sketch just prints the text file back on into the serial connection, but I actually want to do stuff with it in the arduino.
Can anyone point me in the right direction on the best way to format the data for easy parsing? I have control of how the data is posted on the webserver.
I'm used to dealing with things like XML and JSON where the parsing is taken care of for me, so I'm a little unsure how to proceed in turning this flat file of data into a format that I can actually use in my program. Since the data just arrives serial style, how do I know when I've gotten a full piece of data?
If you have specific instructions, that's great, but pointing me towards a good resource on this stuff is fine too. I can generally figure stuff out.
Since the data just arrives serial style, how do I know when I've gotten a full piece of data?
Add start and end of packet markers to the packet being sent. When the start of packet marker arrives, initialize the array where the data will be stored, and set some flags (started = true; ended = false;).
When characters other than the end of packet marker arrive, add them to the array.
When the end of packet marker arrives, set the ended flag to true.
Only process the data when both flags are true. Search the forum for "started && ended" for sample code.
As for parsing the data in the packet, some delimiter between values is useful - commas and spaces are popular choices.
The strtok function can then extract tokens from the array. The tokens can then be converted to numbers using atoi() for instance.