Skip to content

Instantly share code, notes, and snippets.

@TobleMiner
Last active July 19, 2016 20:17
Show Gist options
  • Save TobleMiner/0dd17e1b0c8957b1e3ec38a96ced6e38 to your computer and use it in GitHub Desktop.
Save TobleMiner/0dd17e1b0c8957b1e3ec38a96ced6e38 to your computer and use it in GitHub Desktop.
Doorlockd prototype
#!/bin/env python3
import socket
import RPi.GPIO as gpio
import time
GPIO = 7
LISTEN_ADDRESS = '127.0.0.1'
LISTEN_PORT = 3214
OPEN_TIME = 5
gpio.setmode(gpio.BOARD)
gpio.setup(GPIO, gpio.OUT)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((LISTEN_ADDRESS, LISTEN_PORT))
while True:
data, addr = sock.recvfrom(1024)
print(data)
if data == b"open":
gpio.output(GPIO, gpio.HIGH)
time.sleep(OPEN_TIME)
gpio.output(GPIO, gpio.LOW)
[Unit]
Description=Doord
[Service]
ExecStart=/usr/local/sbin/doord.py
[Install]
WantedBy=multi-user.target
#!/bin/env python3
import socket
SERVER_ADDRESS = '127.0.0.1'
SERVER_PORT = 3214
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(b'open', (SERVER_ADDRESS, SERVER_PORT))
.
.
.
.
door:x:1002:1003::/home/door:/usr/local/bin/open
#
# /etc/shells
#
/bin/sh
/bin/bash
/usr/local/bin/open
# End of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment