Initial commit

This commit is contained in:
Kumi 2018-11-27 10:20:00 +01:00
parent a15d74b4a1
commit fa6b3895eb
No known key found for this signature in database
GPG key ID: 8D4E139A5FF9082F
4 changed files with 59 additions and 1 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
__pycache__
*.pyc

View file

@ -4,7 +4,8 @@ Serial Client
Preparation
-----------
Disable the login shell (raspi-config > Interfacing Options > Serial)
1. Disable the login shell (raspi-config > Interfacing Options > Serial)
2. Install Python3 modules (pip3 install serial python-crontab)
Run
---

36
cron.py Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python3
from crontab import CronTab
import os
import csv
import sys
def whereami():
return os.path.dirname(os.path.abspath(__file__))
class Cron(CronTab):
def __init__(self, user=True):
CronTab.__init__(self, user=user)
def clearCron(self):
return self.remove_all()
def getJob(self, code):
return self.new(command="%s/send.py %s" % (whereami(), code))
def buildJob(self, code, minute=False, hour=False):
job = self.getJob(code)
job.setall(time(hour, minute))
job.enable()
def readCSV(self, path):
self.clearCron()
with open(path) as csvfile:
r = csv.DictReader(csvfile, [minute, hour, code])
for row in r:
self.buildJob(row["code"], row["minute"], row["hour"])
self.write()
if __name__ == "__main__":
Cron().readCSV(sys.argv[1])

19
send.py Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import time
import serial
import sys
def sendMessage(code):
with serial.Serial(
port='/dev/ttyAMA0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
) as s:
s.write(code + "\r")
if __name__ == "__main__":
sendMessage(sys.argv[1])