Initial commit
This commit is contained in:
parent
a15d74b4a1
commit
fa6b3895eb
4 changed files with 59 additions and 1 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
__pycache__
|
||||
*.pyc
|
|
@ -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
36
cron.py
Executable 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
19
send.py
Executable 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])
|
Loading…
Reference in a new issue