MySQL for the Internet of Things

(Steven Felgate) #1
ChapTEr 8 ■ DEmonsTraTion of high availabiliTy TEChniquEs

// Write the row to the database
write_data(val, buffer);
}
}
// close the file:
log_file.close();
// Now remove the file
if (SD.remove(LOGFILE)) {
Serial.println("Cache emptied. File removed.");
}
return true;
}
// if the file didn't open, print an error:
Serial.println("ERROR: Cannot open file for reading");
return false;
}


void setup() {


Serial.begin(115200);
while (!Serial); // wait for serial to load


// Turn on the SPI for the SD card (Arduino Ethernet)
// Note: required for Arduino Mega!
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);


// Start the RTC
rtc.begin();
if (!rtc.begin()) {
Serial.println("Couldn't find the RTC module.");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("The RTC module is not working.");
} else {
// Comment out this line after the first run, it is only needed for setting
// the date and time for the first time.
rtc.adjust(DateTime(F(DATE), F(TIME)));
}


// Setup the SD card
Serial.print("Initializing SD card...");
if (!SD.begin(SD_PIN)) {
Serial.println("ERROR: Cannot initialize SD card");
return;
}
Serial.println("SD card is ready.");
// Now remove the file
if (SD.remove(LOGFILE)) {
Serial.println("Cache emptied. File removed.");
}

Free download pdf