Simple Beer Service is a cloud-connected kegerator that sends sensor data (beer flow, temperature, humidity, sound levels and proximity) to AWS. Simple Beer Service kegerators publish sensor data collected by an IoT device to an AWS IoT Device Gateway. The AWS IoT Rule Engine is used to invoke downstream actions in AWS, such as publishing to an Amazon Kinesis Firehose or an Amazon DynamoDB table.
The data visualizations are delivered through a static web application dashboard that opens a web socket connection to the same AWS IoT Topic, providing a near real-time display of the sensor data. The web application is stored in Amazon S3 and delivered through Amazon’s content delivery network, Amazon CloudFront.
For a more step-by-step instruction guide through the AWS console, see the bootcamp branch of this repository.
You can select the components that you feel would be best for your unit. However, the three major components you will need are:
Click here for the full bill of materials.
The 3D printable .STL files are available in the stl folder of this repository. You can print these at your favourite 3D printing studio. 3Dhubs.com is a great place to submit your order and find a local printer.
There is also a slot in the front of the head unit for a clear face plate. Ponoko.com is a great place to get a face plate designed and laser etched. Here is the material that we recommend:
Once you get the prints back, you will need a few screws to tie everything together.
Note: This instruction guide will focus on the Intel Edison, however, Johnny-Five supports many platforms. If you are using another platform, simply change the
io: new Edison()
option when instantiating a board object in the sbs.js device code.
ssh [email protected]<IP_ADDRESS>
npm install -g forever
mkdir /opt/sbs/
Before moving forward, finish the software / AWS environment setup and come back. This will enable you to create your certificates and customize the application before copying the files and setting up auto-start.
cd device
scp -r ./ [email protected]<IP_ADDRESS>:/opt/sbs/
cd /opt/sbs/
npm install
nano /etc/init.d/startsbs.sh
<OPEN NANO EDITOR>
#!/bin/bash
forever start -a -l /dev/null /opt/sbs/sbs.js
<CONTROL O | write the changes>
<CONTROL X | exit>
chmod +x /etc/init.d/startsbs.sh
update-rc.d startsbs.sh defaults
ln –s /etc/init.d/startsbs.sh /etc/rc3.d/S99startsbs.sh
Install the Serverless Framework, Yeoman, Bower and Gulp. You can do this all with a single command:
npm install -g [email protected] yo bower gulp
Note: You may need to run "sudo" to install these as an administrator.
aws iot create-thing --thing-name <YOUR_UNIT_ID>
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Connect"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Publish"
],
"Resource": [
"arn:aws:iot:<REGION>:<ACCOUNT_NUMBER>:topic/<TOPIC_NAME>"
]
}
]
}
aws iot create-policy --policy-name <POLICY_NAME> --policy-document file://iotpolicy.json
mkdir device/cert
aws iot create-keys-and-certificate --set-as-active --certificate-pem-outfile device/cert/certificate.pem.crt --public-key-outfile device/cert/public.pem.key --private-key-outfile device/cert/private.pem.key
You will also need one more file, the VeriSign root certificate. Download that certificate here and save it to the same cert directory. Name it root.pem.crt.
aws iot attach-principal-policy --policy-name <POLICY_NAME> --principal arn:aws:iot:<REGION>:<ACCOUNT>:cert/<CERTID>
aws iot attach-thing-principal --thing-name <THING_NAME> --principal arn:aws:iot:<REGION>:<ACCOUNT>:cert/<CERTID>
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Connect",
"iot:Receive"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "iot:GetThingShadow",
"Resource": [
"arn:aws:iot:<REGION>:<REPLACE_WITH_ACCOUNT_NUMBER>:thing/<SBS_THING_NAME>"
]
},
{
"Effect": "Allow",
"Action": "iot:Subscribe",
"Resource": [
"arn:aws:iot:<REGION>:<REPLACE_WITH_ACCOUNT_NUMBER>:topicfilter/<TOPIC_NAME>/*"
]
}
]
}
This application uses the Serverless Framework. You can initialize your project with the following command:
Important!! Simple Beer Service app assumes that you have a domain to use with your project. If you do not have a hosted zone setup, create one now.
aws route53 create-hosted-zone --name <domainname.com>
cd simplebeerservice
npm install
sls variables set
name: domain
value: <YOUR_DOMAIN>
type: Common
sls project init
This will create a new set of resources for your SBS application.
Note: you will need to have the CLI installed with a valid AWS profile to start using Serverless.
For this section, we will be working out of the client directory. This is where all of the files we need to build out the static web application. First, run this command to change the directory and install the required libraries.
cd client
npm install
bower install
Before we get going, here is a quick intro to a tool called Gulp. Gulp is a task manager for Node.js applications. It enables us to wire up commands that will perform common tasks. Here are a few we will use today. Go ahead and try them out!
gulp serve
This command will run a local webserver that is listening for any changes to your app directory. If there are an file changes, it will reload the local running web application. This is great for development, as you can see changes live as you update the code.
gulp build
This command will package up all of the files you need for your static site and write them into your /dist/ folder. This is the folder that serverless is using when it publishes your S3 static files.
gulp test
This command will run the unit tests defined in the /test/ folder. For this project, we have not defined any unit test.
Awesome. Now you know how to work with Gulp! Next, let's open up app/scripts/main.js in Atom and copy and paste your identity pool ID from Cognito. You can get this from the Cognito console.
gulp build
sls client deploy
The following command will create a CloudFormation stack with a Kinesis stream that will receive beer consumption data, and update the IoT Shadow accordingly. You may wish to edit the default values supplied in stack.json
(in particular, the IotEndpoint
if deploying in a region other than us-west-2
).
# Run from the root of the repo.
STACK_NAME=sbs-kinesis \
TEMPLATE=kinesis \
PARAMS=stack.json \
OP=create-stack; \
aws cloudformation $OP --capabilities CAPABILITY_IAM --stack-name $STACK_NAME --template-body file://cfn/$TEMPLATE/template.yaml --parameters file://cfn/$TEMPLATE/parameters/$PARAMS
It is necessary to create an IoT rule to send events from the device into this stream of the form:
SELECT * FROM 'topic_name/thing_name'
The following command will create a CloudFormation stack with an API Gateway and backing Lambda function; the purpose of this API is to reset the beer consumption amount back to zero.
# Run from the root of the repo.
STACK_NAME=sbs-api \
TEMPLATE=reset-api \
PARAMS=stack.json \
OP=create-stack; \
aws cloudformation $OP --capabilities CAPABILITY_IAM --stack-name $STACK_NAME --template-body file://cfn/$TEMPLATE/template.yaml --parameters file://cfn/$TEMPLATE/parameters/$PARAMS
To actually perform a reset once the API is live:
curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST \
-d '{"sbs_thing_name": "thingname", "keg_capacity_liters":20, "beer_name":"Blanche de Chambly", "beer_brewery": "Unibroue", "beer_description": "Glorious.", "beer_logo_url": "http://site.com/logo.png"}' \
https://CFN_PREFIX.execute-api.us-west-2.amazonaws.com/LATEST/sbs-keg-reset --verbose
Optionally, this can be set to require an API Key.