MySQL for the Internet of Things

(Steven Felgate) #1
ChApTEr 3 ■ how IoT DATA Is sTorED

StOrING Date aND tIMe WIth SaMpLeS


The Arduino does not have a real-time clock (rTC) on board. If you want to store your data locally, you
have to either store the data with an approximate date and time stamp or use an rTC module to read an
accurate date/time value. Fortunately, there are rTC modules for use with an Arduino.

Listing 3-3. Log File Example (Arduino)


/**
Example Arduino SD card log file.


This project demonstrates how to save data to a
microSD card as a log file and read it.
*/
#include <SPI.h>
#include <SD.h>
#include <String.h>


// Pin assignment for Arduino Ethernet shield
#define SD_PIN 4
// Pin assignment for Sparkfun microSD shield
//#define SD_PIN 8
// Pin assignment for Adafruit Data Logging shield
//#define SD_PIN 10


File log_file;


void setup() {
char c = ' ';
char number[4];
int i = 0;
int value = 0;
String text_string;


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


Serial.print("Initializing SD card...");


if (!SD.begin(SD_PIN)) {
Serial.println("ERROR!");
return;
}
Serial.println("done.");

Free download pdf