Finally another update on my personal blog ;-) I’ve been busy the past year - learning new stuff and improving on existing skills.
So, what did I do? Mostly I’ve been learning Angular, TypeScript, working on some php projects and improving on EAM and requirements engineering.
Today I want to share some of my learnings I had while working with nodejs on raspberry pi. The objective was to create a backup tool which runs on said raspberry, with a lot of restrictions. Backups had to be downloaded via FTP only, also the backup had to start on an interval only if there’s a USB stick present. Maybe use a binary to start everything. Simple, so far.
I started with a lot of research on how to detect the presence of a USB device and on how to mount/manage it. Soon, I came up with a USB detection library that reacts on('add', (device: Device) => {})
and on('remove', (device: Device) => {})
.
Besides, I had to establish some baseline and reliable setup for working with node and creating cli applications. There my Angular experiences came in handy, since all development is done with TypeScript, I opted to do likewise.
To have fancy colors, argument parsing, etc., I added:
With this basic setup, I could build all I need. Long story short: A lot of challenges came up, costing me loads of time to understand and overcome.
- if a device is detected, the os needs some time (~4s) to detect it and provide a device name (e.g. /dev/sda). Before that there is no way, the script can do anything useful …
- mounting devices on Linux systems can be a bit of pain without root access: pmount did the job
- ensuring, mounting and unmounting really succeed when using exec and there are no events you can successfully monitor or subscribe on
- scheduling events is not so easy a if using cronjobs…
Not to forget logging and sending emails on special events like “device capacity below 20%”. Another good example on how projects grow beyond the expected features :-)