I have build a weather station using an arduino and an ethernetshield as webserver. With my processing sketch (client) I can log in the arduino and get it's life sensor data printed on my processing window when I send any keystroke.
I have also let somebody 500km away from me succesfully read out my sensor data using my home IP address.
I am also logging the data every hour on an SD-card. Via processing, I can send any keystroke to the arduino. The keystrokes gets printed on the serial monitor.
if I hit the 'a' key the arduino also turns on a led and prints "YOLO" on the serial monitor, and if I hit the 'u' key, the led goes off and "SWAG" (was tired of hello world ;)? gets printed on the serial monitor.
If I hit the 'd' key, I order the arduino to dump it's datalog over the LAN to my processing window, this works fine. code:
void dumpData()
{
File dataFile = SD.open("logboek.txt", FILE_READ);
while (dataFile.available()) {
client.write(dataFile.read());
}
dataFile.close();
client.write("\r\n");
}
I post a screenshot with the serial monitor and the proccesing window so you can see how it functions.
For now, the end goal is to request the data of the last 24 hours on command and transform this data into 6 coloured lines in a processing graph. Including time stamps, a ds1307 RTC on the arduino is tracking the time.
The datalog grows every hour but I am only interested in the last 24 hours.
I was wondering what the best way would be to separate the requested bytes from the rest.
I figured that it would be easier to tackle this problem in the arduino than in processing.
When the datalog gets dumped, every last character get's ran through the arduino code.
I figured that it would be wise to let the arduino process the datalog file, before sending anything to processing, and look for a matching time/date stamp to compare it with the current time of the RTC minus 1 day.
So when I give the command for a datadump at 23:40 14-08-15. The arduino runs through the datalog until it finds (data gets logged at the hour so minutes must be 00) 23:00 13-08-15
I am now thinking to use a switch-case statement to look for the right time/date stamp. As of now I only devised this:
byte check = 0;
while (dataFile.available()) {
char c = dataFile.read();
// this is code to look for 23:00 13-08-15 this would be stored as 231308 on the SD card (minutes are always 0, thus irrelevant and I dont care about the year for now)
// so we are looking for the character sequence
// 231308
switch (check) { // (2)
case 0: if(c == (char)hour_tenth) check++; // so if c matches the 2 of 23:00 hours go to the next case
break;
// (3)
case 1: if(c == (char)hour_unit) check++; // if c matches the 3 of 23:00 hours go to the next case
else check = 0; break; // if c doesnt match the 3, we have the wrong time, back to case 0
// (1)
case 2: if(c == (char)day_tenth) check++;
else check = 0; break;
// (3)
case 3: if(c == (char)day_unit) check++;
else check = 0; break;
// (0)
case 4: if(c == (char)month_tenth) check++;
else check = 0; break;
// (8)
case 5: if(c == (char)day_unit) check++;
else check = 0; break;
//
case 6: send_remaining_data_to_processing_function(); // and this will send the remaining data of the SD overthe LAN to processing window
check = 0; break; // reset check to 0 after the last data has been send
}
}
This was about the only thing I could come up with.
Is this a viable approach? (if so, is it smart to do?), or are there other/better solutions or functions I dont know about?
