My weather station is working but I'm having issues when my internet is down. So I added an SD card to it.
I start by trying to send and if not possible I save the data to a file. When internet is back I flush SD data. It's working fine but when file reaches some size(>20 hours of 1 minute data), it last more than one minute to send one minute of data. My data is 26 bytes each minute and I'm already saving in binary instead ascii data to save space.
The "algorithm" I'm using is to send first line, erase first line(I'm opening a new file, streaming main file to temporary, remove and rename back). I don't know a better way to do this so it's a question: "Is it possible to improve this using sdfatlib beta?"
I'm trying to make additional files using some files like 0001.txt, 0002.txt with 1 hour of data each. But I'm finding a hard way dealing with ls() method. Can you post some example on dealing with this like ls, open first file, close, another file and so on?
I'm using millis() to time things. On first 5 seconds I get, try to send(timeout after 5 seconds) and if not possible, save to SD. The another 55 seconds I try to "flush" SD data. If it detects internet is down it try to send once each minute. Internet is down equals to not receive CHECKSUM from a webservice I made.
So, the Arduino should be able to save 10 minutes worth of data, while uploading the contents of the SD card (that was saved while the internet was not available).
Surely that's enough time to copy the whole file to the server. There would then be no reason to copy/remove/copy/rename just to remove one line from the file.
I'm trying to make additional files using some files like 0001.txt, 0002.txt with 1 hour of data each. But I'm finding a hard way dealing with ls() method. Can you post some example on dealing with this like ls, open first file, close, another file and so on?
Post a link to the library you are using. Post the code that you wrote to test the ls() method.
You could try to open hourly file. If it succeeds, that file already exists. Close it, and try the next number. When you get a failure, that file doesn't exist, so, create it and write to it.
I'm trying to be safe. It's a good idea(I don't think about it before) try to send the whole file and make a simple checksum on file content to be sure the whole file is sent correctly.
It opens all files in the root directory and prints their names. You could check the name and then read the file if the name matches some pattern.
/*
* Open all files in the root dir and print their filename
*/
#include <SdFat.h>
// SD chip select pin
const uint8_t chipSelect = SS_PIN;
// file system object
SdFat sd;
SdFile file;
// define a serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
void setup() {
char name[13];
Serial.begin(9600);
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!sd.init(SPI_HALF_SPEED, chipSelect)) sd.initErrorHalt();
// open next file in root. The volume working directory, vwd, is root
while (file.openNext(sd.vwd(), O_READ)) {
file.getFilename(name);
cout << name << endl;
file.close();
}
cout << "Done" << endl;
}
//------------------------------------------------------------------------------
void loop() {}
Do you know why this code is looping forever if my file only has 256K? I'm supposing that it's not detecting EOF. I'm saving files in binary mode(saving chunks of bytes) though I can't use readline().
int checksum = 0;
byte c;
while ((c = sentFile.read()) >= 0) {
checksum ^= c;
Serial.write(c);
}
As I really don't know why the hell my while does not work
For some reason, I read this as "my wife does not", and I was thinking you have serious communications issues. Which is funny since the whole thread is about communication failures.
PaulS:
For some reason, I read this as "my wife does not", and I was thinking you have serious communications issues. Which is funny since the whole thread is about communication failures.
hahaha that was really funny!
cyclegadget:
Could this be it?
if (i > sentFile.fileSize())
Change to:
if (i >= sentFile.fileSize())
this code is working already... I want it to work without my DIY byte counter. the while loop has to work directly as the example files on library:
while ((c = sentFile.read()) >= 0) {
// do something
}