I am using an ArduinoBoardEthernet for an application that accepts arbitrary length data over an http POST.
the data is an arbitrary number of 'alarm=minute,hour,dayofweek,day,month,pin,on,duration&...'
where minute (etc) are numbers in their normal range or an X to designate 'any' .
the code I am using parses each alarm (from the post string) fine.
where I am struggling is parsing the comma delimited inner alarm string into its components (which must then be translated in single byte length - the duration is always 120 or below - and then written to EEPROM).
I have tried using sscanf but get garbage. likewise strtok, and even manual iteration.
the latest iteration of the code I am using follows (for completeness I am posting the complete segment)
if ( 0 == strcmp(value, "sched") ){
Serial << "processing sched action" << "\n";
int e = 0;
int j = 0;
char minute, hour, day, month, dayOfWeek, pin, on, duration;
char *result;
char *delim = ",";
do{
repeat = server.readPOSTparam(name, 6, value, 20);
if (0 != strcmp (name, "alarm" )) continue;
Serial << "\nalarm:" << value << "\n";
uint8_t i = 0;
for(int i = 0; i < 8; i++){
char buff[4];
for(j = 0; e<3; e++){
if (',' == value[ (i*8) + j]) break;
buff[e] = value[i];
}
Serial << "\n" << buff << "\n";
switch (i){
case 0: minute = atoi(buff);break;
case 1: hour = atoi(buff); break;
case 2: dayOfWeek = atoi(buff); break;
case 3: day = atoi(buff); break;
case 4: month = atoi(buff); break;
case 5: pin = atoi(buff); break;
case 6: on = atoi(buff); break;
case 7: duration = atoi(buff); break;
}
}
Serial << "\nWriting alarm: " << minute << ":" << hour << ":" <<dayOfWeek << ":" << day << ":" << month << ":" << pin << ":" << on << ":" << duration << "\n";
if(e < 1023){
EEPROM.write(e, minute);
e++;
EEPROM.write(e, hour);
e++;
EEPROM.write(e,dayOfWeek);
e++;
EEPROM.write(e,day);
e++;
EEPROM.write(e,month);
e++;
EEPROM.write(e,pin);
e++;
EEPROM.write(e,on);
e++;
EEPROM.write(e,duration);
e++;
}
}while (repeat && 0 != strcmp(name,"alarm"));
if(e < 1023){
EEPROM.write(e,'|');
}
}
in the serial console I get the following
processing sched action
duration=2&alarm=15%2CX%2CX%2CX%2CX%2C2%2C1%2C2
alarm:15,X,X,X,X,2,1,2
11)8alarm
11)8alarm
,,,8alarm
XXX8alarm
,,,8alarm
XXX8alarm
,,,8alarm
XXX8alarm
Writing alarm: :::::::
and using this variant (just posting the relevant bits)
sscanf(value, "%d,%d,%d,%d,%d,%d,%d,%d", &minute, &hour, &dayOfWeek, &day, &month, &pin, &on, &duration);
Serial << "\nWriting alarm: " << minute << ":" << hour << ":" <<dayOfWeek << ":" << day << ":" << month << ":" << pin << ":" << on << ":" << duration << "\n";
I get the following output
processing sched action
duration=2&alarm=15%2CX%2CX%2CX%2CX%2C2%2C1%2C2
alarm:15,X,X,X,X,2,1,2
Writing alarm: :::½::::5
so in both cases it seems that the webduino code is capturing the alarm properly and decoding it properly. the alarm: ... line is exactly the representation that I want.
So I guess where I am going wrong is my approach to parsing this csv into bytes for writing to the EEPROM.
Any help with a solution or better approach would be much appreciated.
thanks
Justin