Skip to content

ChrisTracy/gate-opener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi Gate Opener

This project comes as a pre-built docker image that enables you to uitilze a relay and raspberry pi to open a gate or garage door via API call. You will need to create a table in AirTable with 5 fields:

  • user (single line of text)
  • auth (single line of text)
  • enabled (checkbox)
  • admin (checkbox)
  • invite (single line of text)

You will also need to generate a token from the Airtable Dev Portal. Grant read and write scopes to the base.

Hardware

This is the hardware I am using. You can certainly do this with less. A pi0, jumper wires, and any relay will work.

Wiring

Raspberry Pi 3 Wiring

Installation

  1. Install Docker (I prefer the apt method):
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Set up Docker's Apt repository:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/raspbian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Install Docker Compose:
sudo apt-get update
sudo apt-get install docker-compose-plugin
  1. Add the current user to the docker group to avoid using sudo. You must lougout and back in after doing this, otherwise you will need to sudo the rest of the commands!:
sudo usermod -aG docker ${USER}
  1. Create a docker-compose.yml file:
nano docker-compose.yml
  1. Add this to the YAML file with your own parameters:
version: "3"

services:
  gate_opener:
    image: christracy/gate-opener
    restart: unless-stopped
    privileged: true
    environment:
      FRIENDLY_NAME: "My garage door" #Name of the device you're controlling
      AT_API_KEY: "<AirTable_Token>" #Airtable token (generate in the airtable dev portal and grant it access to the table)
      JWT_SECRET_KEY: "<JWT_Secret_Key>" #This can be anything but it must be long, random and kept secret
      JWT_EXPIRATION_DAYS: "365" #Number of days before a clients JWT token will expire
      BASE_ID: "<AirTable_Base_ID>" #Airtable Base ID (found in the URL)
      TABLE_NAME: "users" #Airtable table name
      GPIO_PIN: "16" #GPIO PIN
      REGISTER_PSK: "<random key>" #Create a random pre-shared key that you will share when clients register. THIS IS NOT SECURE UNLESS YOU ARE BEHIND A PROXY WITH A VALID CERT
      APPROVAL_PSK: "<random key>" #Create a random pre-shared key that you will use to approve/reject users. THIS IS NOT SECURE UNLESS YOU ARE BEHIND A PROXY WITH A VALID CERT
      TOKEN_INTERVAL: "5400" #how long in seconds before pulling in new tokens. (Free version has a limit of 1000 calls a month)

      #these are only required if you want to receive approval emails for new devices
      #PROXY_URL: "https://gate.example.com" #Proxy URL for your server. Where it can be reached
      #SENDER_EMAIL: "[someoneaccount]@gmail.com" #Sender email adress. Typically some account you created for this. If you are not using gmail you will need the additional variables below
      #SMTP_PASSWORD: "<email password>"  #SMTP password for the SENDER_EMAIL account. If you are using gmail you must generate an app password
      #RECEIVER_EMAIL: "[youremail]@gmail.com" #The email where you want to recieve approval emails. Typically your personal email

      #these are only required if you want to send email from a provider other than gmail
      #SMTP_SERVER: "smtp.outlook.com" #defaults to smtp.gmail.com
      #SMTP_PORT: 25 #defaults to 587
      #SMTP_USERNAME: <your_mail_username> #defaults to SENDER_EMAIL

      #these are only required if you want a pushover notification when the trigger route is called
      #PUSHOVER_USER: <your_pushover_user_token> #you can get this on the main pushover page
      #PUSHOVER_TOKEN: <your_pushover_app_token> #create a new app and it will generate this token
      

    ports:
      - "5151:5151"
  1. Bring up your stack by running:
docker compose up -d

Updating

docker-compose pull
docker-compose up -d

API

These are the api endpoints for the server:

Method URL Description Auth Params
GET /api/v1/hello Sends an authorized request to the server to test access ✔️
POST /api/v1/user/register Registers a new device/key to the Airtable. Admin approval is required in Airtable after this is completed device, psk
POST /api/v1/trigger Triggers the relay ✔️
POST /api/v1/refreshtokens Refreshes the tokens from Airtable ✔️
GET /api/v1/user/enable Enables users using the invite token invite, psk
GET /api/v1/user/reject Rejects/removes users using the invite token invite, psk

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published