One thing to consider with your approach is writing your data to a log file (append) with each measurement rather than writing data from memory all at once. This would reduce data loss and would allow you to asynchronously download your data file whenever you like.
You can use the GPIO to provide a limited interface for you to trigger the data copy to a USB drive. You will need to mount, copy the file, and unmount your USB to assure reliable data transfer. You could implement this using interrupts to initiate a script and use a light emitting diode (LED) to indicate that the script executed and that it is safe to remove the USB drive. You can use different color LEDs to indicate script execution status.
Here is an article on interrupts that will get you started. A broader search on interrupts on the Raspberry Pi will find other references.
https://www.raspberrypi.org/forums/viewtopic.php?t=107771
Here's a use case for how your system could work.
- Weather logger records data and writes to a log file. This happens asynchronously with respect to data transfer.
To copy log file data:
- Plug USB drive into Raspberry Pi.
- Press a button (debounced switch).
- LED (yellow) illuminates to indicate script execution start.
- Script mounts USB drive.
- Script copies log file to USB drive.
- Script unmounts USB drive.
- LED (green) illuminates to indicate success. (Or, LED (red) illuminates on error.)
- Remove USB drive.
Good luck.
sync
to force writes to the USB. You will need to know when its dismounted and safe to remove (not the same time as sync if the USB has cache) - maybe a flashing light? Look atps
andkill
to end the program and rsync to copy the data :-). The RPF have a book on command line scripting store.rpipress.cc/collections/getting-started/products/… that would help (though the free PDF seems to have gone from the new site).