Hello all,
I am trying to make Yún do what I want, but I am not a linux person, so it takes time. For a datalogger project I would like to get the files named after the date like "ddmmyy.txt". I tried to tweak the getTimeStamp routine and build a namestring, but the compiler does not like it:
Dataloggeryun.ino: In function 'void loop()':
Dataloggeryun.ino:90: error: no matching function for call to 'FileSystemClass::open(String&, int)'
C:\Users\Sebastian\Documents\Importe ab 0605\arduino-1.5.6-r2\libraries\Bridge\src/FileIO.h:81: note: candidates are: File FileSystemClass::open(const char*, uint8_t)
probably because I do not really understand what the rearranged code does and requires in terms of variables and all (again, I am not a linux person and I already understand that one cannot treat the code that way (obviously)). My getDayStamp seems to be ok; but that is not the point here, I think.
I would be very happy if someone could provide some code to achive a day-stamped filename (and therefore a new file after midnight every day). Thank you very much in advance, have a nice weekend
cheers
Sebastian
no matching function for call to 'FileSystemClass::open(String&, int)'
note: candidates are: File FileSystemClass::open(const char*, uint8_t)
The first line I've shown in the quoted error report shows you have a 1'st parameter of type 'String'. The 2'nd line of the error report is the compiler telling you it could only find an function with a 1'st parameter of type char*.
Hi wildpalms,
thanks for the suggestion. Last night I wildly tried some stuff, including the char filename [] thing.
I tried your entire code snippet, but unfortunately I got
Dataloggeryun.ino: In function 'void loop()':
Dataloggeryun.ino:85: error: storage size of 'filename' isn't known
But I think there must be a way, especially because we know the length of the filename quite exactly, do we not?!
Cheers
Sebastian
String getDateStamp() {
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("+%m%d%G"); // parameters: D for the complete date mmddyyyy
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;
}
/*
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card mounted on the Arduino Yún using the Bridge library.
The circuit:
* analog sensors on analog pins 0, 1 and 2
* SD card attached to SD card slot of the Arduino Yún
Prepare your SD card creating an empty folder in the SD root
named "arduino". This will ensure that the Yún will create a link
to the SD to the "/mnt/sd" path.
You can remove the SD card while the Linux and the
sketch are running but be careful not to remove it while
the system is writing to it.
created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe
adapted to the Yún Bridge library 20 Jun 2013
by Federico Vanzati
modified 21 Jun 2013
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/YunDatalogger
*/
#include <FileIO.h>
void setup() {
// Initialize the Bridge and the Serial
Bridge.begin();
Serial.begin(9600);
FileSystem.begin();
while (!Serial); // wait for Serial port to connect.
Serial.println("Filesystem datalogger\n");
}
void loop () {
// make a string that start with a timestamp for assembling the data to log:
String dataString;
dataString += getTimeStamp();
dataString += " = ";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ","; // separate the values with a comma
}
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// The FileSystem card is mounted at the following "/mnt/FileSystema1"
String logpath;
logpath = "/mnt/sda1/" + getDateStamp() + ".log";
// Length (with one extra character for the null terminator)
int str_len = logpath.length() + 1;
char char_array[str_len];
logpath.toCharArray(char_array, str_len);
File dataFile = FileSystem.open(char_array, FILE_APPEND);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
delay(15000);
}
// This function return a string with the time stamp
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;
}
String getDateStamp() {
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("+%m%d%G"); // parameters: D for the complete date mmddyyyy
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;
}
Hey sonnyyu,
awesome, it works! It compiles in IDE 1.5.6.r2 but not in 1.5.7 for whatever reason, but who cares?! Thank you so much!
Have a nice weekend
Sebastian