Giter Club home page Giter Club logo

garage-door-monitor's Introduction

Cloud-enabled Garage Door Monitor

Problem

I always forget to close my garage door and leave it opened overnight, exposing the contents of my garage such as my prized wine collection to the bad guys on the street.

Solution

This problem calls for a fancy solution and that is why I've built this Cloud-enabled Garage Door Monitor (you can actually use it on any door, or windows, or anything that opens and closes).

Architecture Overview

What I used

  1. Magnetic contact switch (door sensor)
  2. Raspberry Pi Zero W
  3. Case for the Raspberry Pi Zero W
  4. Raspberry Pi Offical Power Supply

Development with virtualenvwrapper

  1. Make python virtualenv for this project

    1. > mkvirtualenv garage-door-monitor (if garage-door-monitor environment doesn't exist)
    2. > workon garage-door-monitor (if garage-door-monitor environment already exists)
    3. > pip install -r dev-requirements.txt
  2. Run the script
    > python src/garage-door-monitor.py

  3. When finished
    > deactivate

  4. To remove virtualenv for this project
    rmvirtualenv garage-door-monitor

Development with SAM local

Installing SAM local

> mkvirtualenv garage-door-monitor or workon garage-door-monitor
> pip install aws-sam-cli (https://github.com/awslabs/aws-sam-cli#installation)

Starting localstack

> scripts/start_localstack.sh

Invoking Lambda function

> sam local invoke AlarmSNSToIFTTTNotification -e test/data/sns_event.json --template deployer/garage_door_monitor.yaml --env-vars ${env_vars_json}

Deploy Stack

> ./deployer/sam_package_upload.py -p <profile> --s3-bucket <artefact-bucket> --s3-prefix <artefact-prefix> --stack-name garage-door-monitor -d

Create an IoT Thing for Garage Door Monitor (ensure it belongs to DoorMonitor Thing Type)

> python deployer/create_door_,monitor_iot_thing.py --name ${door_monitor_thing_name}

Setup on Raspberry Pi

  1. Install Docker
    > curl -sSL https://get.docker.com | sh
    > sudo systemctl enable docker
    > sudo systemctl start docker
    > sudo usermod -aG docker pi
    > docker --version

  2. Install bootstrap.sh
    > cd ${HOME}
    > wget https://raw.githubusercontent.com/hingyeung/garage-door-monitor/master/deployer/bootstrap.sh > chmod +x bootstrap.sh

  3. Install systemd script
    > cd /etc/systemd/system
    > wget https://raw.githubusercontent.com/hingyeung/garage-door-monitor/master/deployer/garage-door-monitor.service

  4. Modify garage-door-monitor.service to replace placeholders: <IoT_endpoint>, <AWS_root_cert_file>, <IoT_cert_file>, <IoT_cert_private_key_file>, <certs_dir> additional_mqtt_server_host, additional_mqtt_server_port and additional_mqtt_topic_prefix.

  5. Start the Garage Door Monitor service
    > sudo systemctl start garage-door-monitor.service

Delete AWS stack

This script makes sure all previous versions of the Iot policy created by the specified stack are deleted first, then detach the IoT policy from all IoT certificates, before deleting the stack.
> python deployer/delete_stack.py --stack-name ${stack_name}

Attributions

Icons made by Freepik from www.flaticon.com.

garage-door-monitor's People

Contributors

hingyeung avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.