I have some problem for my project. I know that Yun Board is not supported by RTC. However, we can use bridge to access the time from the network (using AR933), while the Yun is connected to Internet.
Well, I've found the basic code to access the timestamp from the bridge. Here's the code (I add little code to act as data)
#include <FileIO.h> //Untuk komunikasi dengan SD card
void setup() {
//Bridge
Bridge.begin();
}
String getTimeStamp() {
String result;
Process time;
// date is a command line utility to get the date and the time
// in different formats depending on the additional parameter
time.begin("date");
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
// T for the time hh:mm:ss
time.run(); // run the command
// read the output of the command
while(time.available()>0) {
char c = time.read();
if(c != '\n')
result += c;
}
return result;
}
void loop() {
String Data;
Data += getTimeStamp();
Data += ",";
Data += "korewa-korewa";
Serial.println(Data);
delay(1000);
}
And from that code the serial monitor shows the timestamp and the additional data.
06/06/15-17:34:50,korewa-korewa
06/06/15-17:34:51,korewa-korewa
06/06/15-17:34:52,korewa-korewa
06/06/15-17:34:53,korewa-korewa
06/06/15-17:34:54,korewa-korewa
06/06/15-17:34:56,korewa-korewa
06/06/15-17:34:57,korewa-korewa
06/06/15-17:34:58,korewa-korewa
06/06/15-17:34:59,korewa-korewa
06/06/15-17:35:00,korewa-korewa
06/06/15-17:35:01,korewa-korewa
06/06/15-17:35:02,korewa-korewa
Just like what I want.
Here is the problem. I want to keep those data in the SD Card by using the following code
#include <FileIO.h>
void setup() {
//Inisialisasi Bridge
Bridge.begin();
//Inisialisasi komunikasi dengan file sistem OpenWrt-Yun
FileSystem.begin();
}
String getTimeStamp() {
String result;
Process time;
// date is a command line utility to get the date and the time
// in different formats depending on the additional parameter
time.begin("date");
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
// T for the time hh:mm:ss
time.run(); // run the command
// read the output of the command
while(time.available()>0) {
char c = time.read();
if(c != '\n')
result += c;
}
return result;
}
void loop() {
delay(1000);
String Data;
Data += getTimeStamp();
Data += ",";
Data += "korewa-korewa";
Serial.print(Data);
Serial.println(" - Before writing data to SD Card");
File dataFile = FileSystem.open("/mnt/sd/timetest1.txt", FILE_APPEND);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(Data);
dataFile.close();
// print to the serial port too:
Serial.print(Data);
Serial.println(" - After writing data to SD Card");
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
delay(1000);
}
However the result in the serial monitor and the .txt file (in sd card) is shown below
06/06/15-17:41:34,korewa-korewa - Before writing data to SD Card
06/06/15-17:41:34,korewa-korewa - After writing data to SD Card
,korewa-korewa - Before writing data to SD Card
,korewa-korewa - After writing data to SD Card
,korewa-korewa - Before writing data to SD Card
,korewa-korewa - After writing data to SD Card
,korewa-korewa - Before writing data to SD Card
,korewa-korewa - After writing data to SD Card
,korewa-korewa - Before writing data to SD Card
,korewa-korewa - After writing data to SD Card
as you can see for the first data the timestamp is recorded, but after that the timestamps for the next data are not recorded.
Could you guys help me ? What's wrong with my code ?
Note : Actually my project is to record the data from several sensors and data logging it to sd card. Those string data in my code above just a little representation of my sensors reading.
Thanks for the help.