Power outage detector made with ♥ by a dag.
This is an IoT project that uses 'dags' to monitor the power whilst you are away from home. You can read the motivation on my blog.
The 'dags' (RaspberryPi-Zero + a small UPS) report status updates to a serverless application hosted on AWS. Status updates are communicated to end-users via email, or may be checked asynchronously at detectordag.tk.
Broadly the system divides in two:
An edge device is a RaspberryPi-Zero device paired with the UPS-Lite uninterruptable power supply and an LTE dongle for connectivity. Software is deployed via BalenaCloud, along with other fleet management tasks.
The cloud sub-system is a collection of serverless entities on AWS: including IoT Core, Lambda, API gateway, SQS. The Cloudformation designer, when supplied this project's template.yml gives this spaghetti mess:
The following list gives an overview of the subdirectories of this project:
This project uses a few different tools:
The project generally uses mage for project build commands, which retrospectively was a pain-in-the-arse, but oh well...
go get -u -d github.com/magefile/mage
go run bootstrap.go
# Install the general AWS CLI
brew install awscli
# Install the SAM CLI
brew tap aws/tap
brew install aws-sam-cli
You will need to download credentials and save them to ~/.aws/credentials
to interact with AWS.
Most AWS resources are provisioned using the CloudFormation template.yml
.
# Build the lambda functions
sam build
# Deploy to AWS
sam deploy
New devices need to be provisioned on a device-by-device basis. A handy mage command is provided in order to provision a 'thing' on AWS matching a device on BalenaCloud, obtaining a build image ready to be flashed to an SD card.
# Provision a device
env DDAG_DEVICE_ID=3cf9f9b7-b7d2-46db-9e6b-5f80fdfe8aa0 \
DDAG_DEVICE_NAME=second \
DAG_ACCOUNT_ID=aac45d02-c97d-442c-8431-336d578fdcf7 \
mage -v provisionDevice
Some notes: