Hardware Reference
In-Depth Information
server operations. On line 6, an instance of the YunServer is created. This will
be used later.
setup()
is declared on line 11. First, the serial port is initialized, and then
the Bridge and i lesystem subsystems are initialized. Finally, the server starts.
loop()
is declared on line 23, but before describing its functionality, let's look
at the two other functions it calls. One is used to write data to the SD card, and
the other retrieves the timestamp from Linux.
getTimeStamp()
is declared on line 74. When it runs, it creates an instance
of the Process class. It also creates a variable called
result
; this is the variable
that holds the result of a Linux command. This command runs inside a process
called
time
. The function that it calls is named
date
; when executing the
date
command, it returns something like this:
jlangbridge@desknux:~$ date
Fri 29 Aug 15:01:00 UTC 2014
This contains a little bit too much information, you need only a short date
and time. This is achieved by adding some parameters to the instruction:
jlangbridge@desknux:~$ date +%D-%T
08/29/14-15:01:00
To c a l l
date
, the sketch calls
time.begin()
on line 78 using
date
as an argu-
ment. To add parameters,
addParameter()
is used on line 79. The command
is run on line 80. The next few lines wait for a fraction of a second and then
read the output of the command. This data is placed in a
String
, which is then
returned to the
loop()
.
The second function is called
logResults()
, and it is declared on line 60.
This function takes a
String
and places that data onto an SD card. It begins by
attempting to open a i le on the SD card in the
FILE_APPEND
mode. On line 64 a
verii cation is made to see if the i le were opened. If it were opened, the data is
written, and the i le is closed before returning
true
. If the i le weren't opened,
the function returns
false
.
Back to
loop()
. A variable called
dataString
is declared and then a YunClient
object is created. The
dataString
variable holds the date, time, and light sensor
reading. On line 28, the date and time is added from the return value of
get-
TimeStamp()
. Next, the analog value on pin A3 is read, converted to a
String
,
and added to
dataString
. On line 36, the variable
iteration
is incremented. If
the value equals 20, then the value is written to the data card. Finally, on line 50,
the sketch checks to see if a client is connected. If it is, the
dataString
displays,
and the connection is closed before returning the
iteration
value to zero.
Search WWH ::
Custom Search