Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
ba2946706b | |||
80573055d9 | |||
1941698a52 | |||
bd7532a080 | |||
e2e5878630 |
@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
VERSION=3.1.0
|
VERSION=$(grep -oP '(?<=Version: ).*$' debian/DEBIAN/control)
|
||||||
dpkg-deb --root-owner-group -b debian "foodoord_${VERSION}_all.deb"
|
dpkg-deb --root-owner-group -b debian "foodoord_${VERSION}_all.deb"
|
||||||
|
4
debian/DEBIAN/control
vendored
4
debian/DEBIAN/control
vendored
@ -1,6 +1,6 @@
|
|||||||
Package: foodoord
|
Package: foodoord
|
||||||
Version: 3.0.4
|
Version: 3.3.3
|
||||||
Maintainer: Bandie <bandie@chaospott.de>
|
Maintainer: Tobi <tobi@chaospott.de>
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Description: Control the doors of the club, ja!
|
Description: Control the doors of the club, ja!
|
||||||
Depends: dash, git, python3, pip, tmux
|
Depends: dash, git, python3, pip, tmux
|
||||||
|
5
debian/DEBIAN/postinst
vendored
5
debian/DEBIAN/postinst
vendored
@ -26,8 +26,9 @@ while [ "$prompt" != "oben" ] && [ "$prompt" != "unten" ]; do
|
|||||||
done
|
done
|
||||||
echo "##################"
|
echo "##################"
|
||||||
|
|
||||||
echo "Installing dependencies via pip: pifacecommon pifacedigitalio"
|
PIP_DEP=(pifacecommon pifacedigitalio paho-mqtt)
|
||||||
pip install pifacecommon pifacedigitalio
|
echo "Installing dependencies via pip: ${PIP_DEP[*]}"
|
||||||
|
pip install "${PIP_DEP[@]}"
|
||||||
|
|
||||||
echo "Enabling and starting systemd-Services"
|
echo "Enabling and starting systemd-Services"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
5
debian/etc/foodoord.conf_example
vendored
5
debian/etc/foodoord.conf_example
vendored
@ -2,3 +2,8 @@
|
|||||||
status_url =
|
status_url =
|
||||||
key =
|
key =
|
||||||
secret =
|
secret =
|
||||||
|
|
||||||
|
[doorstatusv2]
|
||||||
|
status_url =
|
||||||
|
key =
|
||||||
|
secret =
|
||||||
|
4
debian/usr/sbin/foodoor-update-keydb
vendored
4
debian/usr/sbin/foodoor-update-keydb
vendored
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
||||||
@ -8,7 +8,7 @@ temp_outfile=$dest.tmp
|
|||||||
|
|
||||||
if [ ! -e "$dest/.git/config" ]; then
|
if [ ! -e "$dest/.git/config" ]; then
|
||||||
#echo "Repo does not exist, trying to clone..."
|
#echo "Repo does not exist, trying to clone..."
|
||||||
git -C "$dest" clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "$dest"
|
git clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "$dest"
|
||||||
else
|
else
|
||||||
#echo "Repo exists, updating..."
|
#echo "Repo exists, updating..."
|
||||||
git -C "$dest" fetch --quiet && git -C "$dest" merge --quiet origin/master master
|
git -C "$dest" fetch --quiet && git -C "$dest" merge --quiet origin/master master
|
||||||
|
165
debian/usr/sbin/foodoord_oben
vendored
165
debian/usr/sbin/foodoord_oben
vendored
@ -8,94 +8,163 @@ import signal
|
|||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
import pifacedigitalio
|
import pifacedigitalio
|
||||||
|
|
||||||
# Definitions for output
|
|
||||||
LED_RED = 6
|
|
||||||
LED_GREEN = 7
|
|
||||||
RELAYS_LOCK = 0
|
|
||||||
RELAYS_UNLOCK = 1
|
|
||||||
|
|
||||||
# Definitions for input
|
class FoodoorMQTT:
|
||||||
DOOR_BELL = 0
|
def __init__(self, area):
|
||||||
REED_RELAYS = 1 # not implemented yet
|
self.area = area
|
||||||
|
self.client = mqtt.Client()
|
||||||
|
self.client.on_connect = self.on_connect
|
||||||
|
self.client.on_message = self.on_message
|
||||||
|
|
||||||
|
self._last_state = None
|
||||||
|
self._connect_lock = threading.Condition()
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
try:
|
||||||
|
self.client.connect("mqtt.chaospott.de")
|
||||||
|
self.client.loop_start()
|
||||||
|
with self._connect_lock:
|
||||||
|
self._connect_lock.wait()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Verbindungsfehler zu MQTT-Server: {e}")
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
self.client.loop_stop()
|
||||||
|
|
||||||
|
def on_connect(self, client, userdata, flags, rc):
|
||||||
|
if self._last_state is not None:
|
||||||
|
self.send_state(self._last_state)
|
||||||
|
with self._connect_lock:
|
||||||
|
self._connect_lock.notify()
|
||||||
|
|
||||||
|
def on_message(self, client, userdata, msg):
|
||||||
|
print(f"MQTT-Server Message: {msg.topic} {msg.payload}")
|
||||||
|
|
||||||
|
def send_state(self, locked: bool):
|
||||||
|
self._last_state = locked
|
||||||
|
self.client.publish(f"foobar/{self.area}/foodoor/status", {
|
||||||
|
False: "open",
|
||||||
|
True: "closed",
|
||||||
|
}[locked], qos=0, retain=True)
|
||||||
|
|
||||||
# Definitions for LED color
|
|
||||||
RED = 1
|
|
||||||
GREEN = 2
|
|
||||||
ORANGE = 3
|
|
||||||
|
|
||||||
# Read config
|
# Read config
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read('/etc/foodoord.conf')
|
parser.read('/etc/foodoord.conf')
|
||||||
|
|
||||||
DOORAPI = parser.get('doorstatus', 'status_url')
|
|
||||||
CONSUMERKEY = parser.get('doorstatus', 'key')
|
|
||||||
CONSUMERSECRET = parser.get('doorstatus', 'secret')
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class API:
|
||||||
|
location: str
|
||||||
|
api_url: str
|
||||||
|
consumer_key: str
|
||||||
|
consumer_secret: str
|
||||||
|
|
||||||
def update_api(locked):
|
def update_state(self, locked):
|
||||||
try:
|
|
||||||
subprocess.check_call([
|
subprocess.check_call([
|
||||||
"/usr/bin/curl", "-XPOST",
|
"/usr/bin/curl", "-XPOST",
|
||||||
"--header", "Content-Type: application/json",
|
"--header", "Content-Type: application/json",
|
||||||
"--data",
|
"--data",
|
||||||
json.dumps({"consumer_key": CONSUMERKEY, "consumer_secret": CONSUMERSECRET, "aerie": locked})
|
json.dumps({"consumer_key": self.consumer_key, "consumer_secret": self.consumer_secret, self.location: locked}),
|
||||||
|
self.api_url
|
||||||
])
|
])
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def set_led(color):
|
APIv1 = API("aerie",
|
||||||
if color == RED:
|
parser.get('doorstatus', 'status_url'),
|
||||||
pifacedigital.leds[LED_RED].turn_on()
|
parser.get('doorstatus', 'key'),
|
||||||
pifacedigital.leds[LED_GREEN].turn_off()
|
parser.get('doorstatus', 'secret'),
|
||||||
elif color == GREEN:
|
)
|
||||||
pifacedigital.leds[LED_GREEN].turn_on()
|
APIv2 = API("aerie",
|
||||||
pifacedigital.leds[LED_RED].turn_off()
|
parser.get('doorstatusv2', 'status_url'),
|
||||||
elif color == ORANGE:
|
parser.get('doorstatusv2', 'key'),
|
||||||
pifacedigital.leds[LED_RED].turn_on()
|
parser.get('doorstatusv2', 'secret'),
|
||||||
pifacedigital.leds[LED_GREEN].turn_on()
|
)
|
||||||
|
|
||||||
|
|
||||||
class Foodoord:
|
class Foodoord:
|
||||||
|
# Definitions for LED color
|
||||||
|
RED = 0b1
|
||||||
|
GREEN = 0b10
|
||||||
|
ORANGE = RED | GREEN
|
||||||
|
|
||||||
|
# Definitions for output
|
||||||
|
LEDS = {
|
||||||
|
RED: 6,
|
||||||
|
GREEN: 7,
|
||||||
|
}
|
||||||
|
RELAYS_LOCK = 0
|
||||||
|
RELAYS_UNLOCK = 1
|
||||||
|
|
||||||
|
# Definitions for input
|
||||||
|
DOOR_BELL = 0
|
||||||
|
CLOSE_BUTTON = 1
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.status_open = False
|
self.status_open = False
|
||||||
|
self.mqtt = FoodoorMQTT("oben")
|
||||||
|
|
||||||
|
self.pifacedigital = pifacedigitalio.PiFaceDigital()
|
||||||
self.listener = pifacedigitalio.InputEventListener()
|
self.listener = pifacedigitalio.InputEventListener()
|
||||||
self.listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, self.doorbell, settle_time=10)
|
self.listener.register(self.DOOR_BELL, pifacedigitalio.IODIR_RISING_EDGE, self.doorbell, settle_time=10)
|
||||||
self.listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, self.close_button, settle_time=5)
|
self.listener.register(self.CLOSE_BUTTON, pifacedigitalio.IODIR_RISING_EDGE, self.close_button, settle_time=5)
|
||||||
|
|
||||||
def signal_handler(self, _signal, _frame):
|
def signal_handler(self, _signal, _frame):
|
||||||
self.listener.deactivate()
|
self.listener.deactivate()
|
||||||
os.remove("/var/run/foodoord.pipe")
|
os.remove("/var/run/foodoord.pipe")
|
||||||
|
|
||||||
update_api(True)
|
self.update_api(True)
|
||||||
set_led(RED)
|
self.set_led(self.RED)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
def update_api(self, locked):
|
||||||
|
try:
|
||||||
|
self.mqtt.send_state(locked)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
APIv1.update_state(locked)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
APIv2.update_state(locked)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set_led(self, color):
|
||||||
|
for led, gpio in self.LEDS.items():
|
||||||
|
if color & led:
|
||||||
|
self.pifacedigital.leds[gpio].turn_on()
|
||||||
|
else:
|
||||||
|
self.pifacedigital.leds[gpio].turn_off()
|
||||||
|
|
||||||
def doorbell(self, event):
|
def doorbell(self, event):
|
||||||
if self.status_open:
|
if self.status_open:
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
self.pifacedigital.relays[self.RELAYS_UNLOCK].toggle()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
self.pifacedigital.relays[self.RELAYS_UNLOCK].toggle()
|
||||||
|
|
||||||
def close_button(self, _event):
|
def close_button(self, _event):
|
||||||
self.status_open = False
|
self.status_open = False
|
||||||
update_api(True)
|
self.update_api(True)
|
||||||
set_led(RED)
|
self.set_led(self.RED)
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
|
self.mqtt.connect()
|
||||||
self.listener.activate()
|
self.listener.activate()
|
||||||
|
|
||||||
pifacedigital = pifacedigitalio.PiFaceDigital()
|
|
||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||||
|
|
||||||
# Start settings
|
# Start settings
|
||||||
pifacedigital.leds[LED_RED].turn_on()
|
self.set_led(self.RED)
|
||||||
|
|
||||||
# Setting up FiFo to get sshd-output
|
# Setting up FiFo to get sshd-output
|
||||||
try:
|
try:
|
||||||
@ -111,23 +180,23 @@ class Foodoord:
|
|||||||
pipe_cmd = ssh_input.readline().strip()
|
pipe_cmd = ssh_input.readline().strip()
|
||||||
|
|
||||||
if pipe_cmd == "close" and self.status_open:
|
if pipe_cmd == "close" and self.status_open:
|
||||||
pifacedigital.relays[RELAYS_LOCK].toggle()
|
self.pifacedigital.relays[self.RELAYS_LOCK].toggle()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
pifacedigital.relays[RELAYS_LOCK].toggle()
|
self.pifacedigital.relays[self.RELAYS_LOCK].toggle()
|
||||||
|
|
||||||
self.status_open = False
|
self.status_open = False
|
||||||
update_api(True)
|
self.update_api(True)
|
||||||
set_led(RED)
|
self.set_led(self.RED)
|
||||||
|
|
||||||
elif pipe_cmd == "open":
|
elif pipe_cmd == "open":
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
self.pifacedigital.relays[self.RELAYS_UNLOCK].toggle()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
self.pifacedigital.relays[self.RELAYS_UNLOCK].toggle()
|
||||||
|
|
||||||
if not self.status_open:
|
if not self.status_open:
|
||||||
update_api(False)
|
self.update_api(False)
|
||||||
self.status_open = True
|
self.status_open = True
|
||||||
set_led(GREEN)
|
self.set_led(self.GREEN)
|
||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
109
debian/usr/sbin/foodoord_unten
vendored
109
debian/usr/sbin/foodoord_unten
vendored
@ -6,53 +6,112 @@ import json
|
|||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
import RPi.GPIO as gpio
|
import RPi.GPIO as gpio
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
|
||||||
|
class FoodoorMQTT:
|
||||||
|
def __init__(self, area):
|
||||||
|
self.area = area
|
||||||
|
self.client = mqtt.Client()
|
||||||
|
self.client.on_connect = self.on_connect
|
||||||
|
self.client.on_message = self.on_message
|
||||||
|
|
||||||
|
self._last_state = None
|
||||||
|
self._connect_lock = threading.Condition()
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
try:
|
||||||
|
self.client.connect("mqtt.chaospott.de")
|
||||||
|
self.client.loop_start()
|
||||||
|
with self._connect_lock:
|
||||||
|
self._connect_lock.wait()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Verbindungsfehler zu MQTT-Server: {e}")
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
self.client.loop_stop()
|
||||||
|
|
||||||
|
def on_connect(self, client, userdata, flags, rc):
|
||||||
|
if self._last_state is not None:
|
||||||
|
self.send_state(self._last_state)
|
||||||
|
with self._connect_lock:
|
||||||
|
self._connect_lock.notify()
|
||||||
|
|
||||||
|
def on_message(self, client, userdata, msg):
|
||||||
|
print(f"MQTT-Server Message: {msg.topic} {msg.payload}")
|
||||||
|
|
||||||
|
def send_state(self, locked: bool):
|
||||||
|
self._last_state = locked
|
||||||
|
self.client.publish(f"foobar/{self.area}/foodoor/status", {
|
||||||
|
False: "open",
|
||||||
|
True: "closed",
|
||||||
|
}[locked], qos=0, retain=True)
|
||||||
|
|
||||||
|
|
||||||
# Definitions for output
|
# Definitions for output
|
||||||
LED_RED = 6
|
|
||||||
LED_GREEN = 7
|
|
||||||
RELAYS_LOCK = 0
|
|
||||||
RELAYS_UNLOCK = 1
|
|
||||||
PIN_OPEN = 24
|
PIN_OPEN = 24
|
||||||
PIN_CLOSE = 27
|
PIN_CLOSE = 27
|
||||||
# Definitions for input
|
|
||||||
DOOR_BELL = 0
|
|
||||||
REED_RELAYS = 1 # not implemented yet
|
|
||||||
|
|
||||||
# Definitions for LED color
|
|
||||||
RED = 1
|
|
||||||
GREEN = 2
|
|
||||||
ORANGE = 3
|
|
||||||
|
|
||||||
# Read config
|
# Read config
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read('/etc/foodoord.conf')
|
parser.read('/etc/foodoord.conf')
|
||||||
|
|
||||||
DOORAPI = parser.get('doorstatus', 'status_url')
|
|
||||||
CONSUMERKEY = parser.get('doorstatus', 'key')
|
@dataclass
|
||||||
CONSUMERSECRET = parser.get('doorstatus', 'secret')
|
class API:
|
||||||
|
location: str
|
||||||
|
api_url: str
|
||||||
|
consumer_key: str
|
||||||
|
consumer_secret: str
|
||||||
|
|
||||||
|
def update_state(self, locked):
|
||||||
|
subprocess.check_call([
|
||||||
|
"/usr/bin/curl", "-XPOST",
|
||||||
|
"--header", "Content-Type: application/json",
|
||||||
|
"--data",
|
||||||
|
json.dumps({"consumer_key": self.consumer_key, "consumer_secret": self.consumer_secret, self.location: locked}),
|
||||||
|
self.api_url
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
MQTT = FoodoorMQTT("unten")
|
||||||
|
APIv1 = API("cellar",
|
||||||
|
parser.get('doorstatus', 'status_url'),
|
||||||
|
parser.get('doorstatus', 'key'),
|
||||||
|
parser.get('doorstatus', 'secret'),
|
||||||
|
)
|
||||||
|
APIv2 = API("cellar",
|
||||||
|
parser.get('doorstatusv2', 'status_url'),
|
||||||
|
parser.get('doorstatusv2', 'key'),
|
||||||
|
parser.get('doorstatusv2', 'secret'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def write_state(state):
|
def write_state(state):
|
||||||
try:
|
try:
|
||||||
with open("/tmp/door_state", "w") as handle:
|
with open("/tmp/door_state", "w") as f:
|
||||||
handle.write(state)
|
f.write(state)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_api(locked):
|
def update_api(locked):
|
||||||
try:
|
try:
|
||||||
subprocess.check_call([
|
MQTT.send_state(locked)
|
||||||
"/usr/bin/curl", "-XPOST",
|
except:
|
||||||
"--header", "Content-Type: application/json",
|
pass
|
||||||
"--data",
|
try:
|
||||||
json.dumps({"consumer_key": CONSUMERKEY, "consumer_secret": CONSUMERSECRET, "cellar": locked}),
|
APIv1.update_state(locked)
|
||||||
DOORAPI
|
except:
|
||||||
])
|
pass
|
||||||
|
try:
|
||||||
|
APIv2.update_state(locked)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -71,6 +130,8 @@ def main():
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
MQTT.connect()
|
||||||
|
|
||||||
ssh_input = open("/var/run/foodoord.pipe", "r")
|
ssh_input = open("/var/run/foodoord.pipe", "r")
|
||||||
while True:
|
while True:
|
||||||
# Read sshd output from pipe
|
# Read sshd output from pipe
|
||||||
|
Reference in New Issue
Block a user