MySQL for the Internet of Things

(Steven Felgate) #1
Chapter 4 ■ Data transformation

} else {
if (random(25) >= 5) {
return (float)random(14)/10.00;
} else {
return -(float)random(14)/10.00;
}
}
}


void setup() {
Serial.begin(115200);
while (!Serial);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_PIN)) {
Serial.println("ERROR!");
return;
}
Serial.println("ready.");


if (SD.remove("data_log.txt")) {
Serial.println("file removed");
}


// initiate random seed
randomSeed(analogRead(0));
}


float oldVal = 67.123;
float newVal = 0.00;
float weight = 0.00;


void loop() {
delay(2000);
log_file = SD.open("data_log.txt", FILE_WRITE);
if (log_file) {
strData = String("Blood oxygen: ");
blood_oxygen = read_sensor(2);
strData += blood_oxygen;
strData += ", Calibrated: ";


// calculated column adjusting for calibration
strData += String(blood_oxygen + 0.785, 2);
strData += ", Weight: ";
weight = read_sensor(3);
strData += weight;


// calculated column for number of objects
strData += ", Avg weight: ";
strData += String((weight/4.0), 4);


// Calculating change since last read
strData += ", Volts: ";
newVal = oldVal+read_sensor(4);

Free download pdf