My LoRaWAN Signal Mapping MSc summer project. This is a copy of the actual repository with personal information removed.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

#include <Arduino.h>
#include <SdFat.h>
// #include <ArduinoFiles.h>
#include "settings.h"
#include "gps.h"
// FUTURE: We might be able to trim it down if we disable long filenames with #define
SdFat store_init() {
SdFat card;
if(!card.begin(PIN_SPI_CS_SD)) {
Serial.println("Error: MicroSD card init failed");
while(true) delay(100);
return card;
void store_reading(uint32_t id, GPSLocation location) {
// Port the rest of this to SdFat from SD
SdFat card = store_init();
// Open the file to write the data to. If it doesn't exist it will be created.
// Unlike elsewhere, FILE_WRITE opens the file with the cursor starting at the end, so it's basically actually equivalent to FILE_APPEND that we use in other environments. Confusing, I know.
File handle =, O_APPEND | O_CREAT | O_WRONLY);
uint8_t places = 6;
handle.printField(id, '\t');
handle.printField(, '\t', places);
handle.printField(location.lng, '\n', places);
handle.close(); // Syncs implicitly
void store_debug(char* buffer, int size) {
SdFat card = store_init();
File handle =, O_APPEND | O_CREAT | O_WRONLY);
handle.write(buffer, size);
void store_end() {
// Apparently we'ree fine so long as we don't have any open file handles - there's no end() method on the SdFat class
// card->end();
delete card;
card = nullptr;