MySQL for the Internet of Things

(Steven Felgate) #1

ChApTEr 3 ■ how IoT DATA Is sTorED



8, Example row: 9
9, Example row: 10
6, Example row: 7
7, Example row: 8
8, Example row: 9
9, Example row: 10
Initializing SD card...done.
6, Example row: 7
7, Example row: 8
8, Example row: 9
9, Example row: 10
6, Example row: 7
7, Example row: 8
8, Example row: 9
9, Example row: 10
6, Example row: 7
7, Example row: 8
8, Example row: 9
9, Example row: 10



As you can see, the output is similar to the Raspberry Pi example. Clearly, either can be used to
store data locally in files, but the Arduino takes a bit more work. Fortunately, the Arduino IDE includes a
well-designed SD card library.
In fact, there are a number of other functions in the SD card library for dealing with files. For example,
you can list the files on the card, create folders, and even truncate or delete the contents of a file. You may
find this code useful in working with the previous code. The following shows how easy it is to truncate a file.
If you want to use this, place it in the code before the file is opened the first time.


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


■Tip For more information about using sD cards on the Arduino, see the Arduino online reference guide


(http://arduino.cc/en/Reference/SDCardNotes).


Now that you’ve seen some of the options for storing data locally on the data collector nodes, the
following section discusses sending data to data aggregators for either local or remote storage. Remote
storage in this case is typically a database server.


Passing the Buck to Aggregators


Recall that a data aggregator is a special node designed to receive information from multiple sources (data
collectors or sensors) and store the results either locally or remotely. The source data can originate from
multiple sensors on the node itself, but more often the data aggregator receives information from multiple
data collector nodes that are not attached directly to the aggregate node (they may be connected via a low-
power, low-overhead communication protocol such as provided by XBee modules).

Free download pdf