Hi,
I am writing a program that will use wifi to get a data string, parse it and set some external LEDs as a result. I'm currently working on the parsing section.
I am attempting to put in a sample string to get my parsing right. It is rather long (1185 chars). This is causing the IDE to crash when compiling. I've tried taking out the single quotes, as the FAQ says strange " ' \ combinations can cause this but to no avail. The IDE also crashes when attempting to auto-format the code.
There is also the ~2kB limit on data in sram, so I've tried using PROGMEM, but it still crashes.
I could get around needing the full string by parsing as it is read from the network but I'm worried about buffer overflow if data is not read fast enough.
I'm using a Wifi shield, Mega 2560 and V1.0.3 of the IDE (so it is compatible with wifi).
If anyone has any suggestions or relevant experience I'd appreciate them.
The code
#include <avr/pgmspace.h>
/*
String substring()
Examples of how to use substring in a String
created 27 July 2010,
modified 2 Apr 2012
by Zach Eveland
http://arduino.cc/en/Tutorial/StringSubstring
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// send an intro:
Serial.println("\n\nString substring():");
Serial.println();
}
void loop() {
// Set up a String:
//PROGMEM is a derective to put strin in to flash mem
PROGMEM String string = "<td >WIND %</td><td style='background-color: rgb(36, 184, 36)'>24%</td><td style='background-color: rgb(36, 184, 36)'>24%</td><td style='background-color: rgb(36, 184, 36)'>25%</td><td style='background-color: rgb(36, 184, 36)'>25%</td><td style='background-color: rgb(36, 184, 36)'>26%</td><td style='background-color: rgb(36, 184, 36)'>26%</td><td style='background-color: rgb(36, 184, 36)'>23%</td><td style='background-color: #FFCC32'>18%</td><td style='background-color: #FFCC32'>14%</td><td style='background-color: #FFCC32'>13%</td><td style='background-color: #FFCC32'>13%</td><td style='background-color: #FFCC32'>13%</td><td style='background-color: #FFCC32'>14%</td><td style='background-color: #FFCC32'>15%</td><td style='background-color: #FFCC32'>15%</td><td style='background-color: #FFCC32'>15%</td><td style='background-color: #FFCC32'>15%</td><td style='background-color: #FFCC32'>14%</td><td style='background-color: #FFCC32'>13%</td><td style='background-color: #FFCC32'>12%</td><td style='background-color: #FFCC32'>11%</td><td style='background-color: #FFCC32'>11%</td><td style='background-color: #FFCC32'>13%</td><td style='background-color: #FFCC32'>12%</td>";
Serial.println(string);
int one=0,two=0;
boolean runLoop=true;
//read first to seed loop
one=string.indexOf(">",string.indexOf("</td>")+5);//get the time's start (end tag of colour)
if(one<0||two<0)
{
runLoop=false;
}
one=one+1;//move to start of number
two=string.indexOf("</td>",one);//get the time's end tag
if(one<0||two<0)
{
runLoop=false;
}
while(runLoop)
{//while percents left
String time=string.substring(one,two);
Serial.println(time);
one=string.indexOf(">",two+5);//get the time's start (end tag of colour)
if(one<0||two<0)
{
runLoop=false;
}
one=one+1;//move to start of number
two=string.indexOf("</td>",one);//get the time's end tag
if(one<0||two<0)
{
runLoop=false;
}
//Serial.print(one);
//Serial.println(" = one");
//Serial.print(two);
//Serial.println(" = two");
}
// do nothing while true:
while(true);
}