Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ mqtt:
serial:
port: /dev/ttyAMA0
baud: 115200
member_system:
api_key:
device:
19 changes: 19 additions & 0 deletions fred.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import logging
import paho.mqtt.client as mqtt
import yaml
import requests
import json

with open('config.yaml') as config_f:
config = yaml.safe_load(config_f)
Expand Down Expand Up @@ -38,6 +40,22 @@

ser.write(b'E')


def report_activity(card_id):
try:
url = 'https://members.hacman.org.uk/acs/activity'
data = {
'tagId': card_id,
'device': config['member_system']['device']
}
headers = {
'ApiKey': config['member_system']['api_key']
}
requests.post(url, data=json.dumps(data), headers=headers, timeout=3.05)
except:
logging.error("Error reporting activity for ID %s", card_id)


while True:
card_id = ser.readline().decode("utf-8").strip()

Expand Down Expand Up @@ -66,6 +84,7 @@
found = True
logging.info("%s found, %s opened the door!", card_id, member[1])
mqttc.publish("door/%s/opened/username" % config['door']['name'], member[1], qos=2)
report_activity(card_id)

if not found:
ser.write(b'R')
Expand Down
3 changes: 3 additions & 0 deletions pull_members_from_wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
cd "${0%/*}"
source "config.sh"
curl https://members.hacman.org.uk/query2.php?key=${SECRETKEY} -o "members"

curl --location --request POST 'https://members.hacman.org.uk/acs/node/heartbeat' \
--header "ApiKey: ${MEMBERSYSTEMKEY}"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
paho-mqtt>=1.2,<2
PyYAML>=3.12,<4
pyserial
requests