Im importing some numbers daily via wifi to arduino, which i would like to put in an array and compare each value to the mean value of all the numbers in the array.
the imported data is in text format.
like "
Kl 00 - 01
6.53 öre/kWh
Kl 01 - 02
6.48 öre/kWh
"
i first need to sort this data and convert it to a number...
i would like to store the data in an array, so i can call on 6,53 for example via price[0] and 6,48 price [1] and so on...
What have you tried so far? How are you fetching this data? When you retrieve it, do you store it in a 'String' object or char array?
Based on those answers, you will need to search your string to find the portion you want. You can then use atof() to convert that string into a floating point number of put it into your array
bulanspatel:
but there must be an easier way of doing it i presume?
you could use strstr to find the opening td tags and atof to test what comes next, if it's a float, copy it to your array.
for example...
void setup()
{
Serial.begin(115200 );
while(!Serial);
char response[] =
"<tbody>"
"<tr>"
"<td>Kl 00 - 01</td>"
"<td>6.53 öre/kWh</td>"
"</tr>"
"<tr>"
"<td>Kl 01 - 02</td>"
"<td>6.48 öre/kWh</td>"
"</tr>"
"<tr>";
char tag[] = "<td>";
uint8_t offset = strlen( tag );
char* ptr = strstr( response, tag ); // locate the first tag
while( ptr)
{
ptr += offset; // advance the pointer to the first character after the tag
float val = atof( ptr );
if( val !=0 ) Serial.println( val ); // pris[ index ] = val; test / copy etc
ptr = strstr( ptr, tag ); // find next tag
}
}
void loop() {}