diff --git a/RaspberryPie/flask_backend.py b/RaspberryPie/flask_backend.py new file mode 100644 index 0000000..fb8b7cf --- /dev/null +++ b/RaspberryPie/flask_backend.py @@ -0,0 +1,6 @@ +from flask import Flask, render_template, make_response + +app = Flask(__name__) +@app.route("/") +def index(): + pass \ No newline at end of file diff --git a/RaspberryPie/flask_backend.wsgi b/RaspberryPie/flask_backend.wsgi new file mode 100644 index 0000000..8e10bf5 --- /dev/null +++ b/RaspberryPie/flask_backend.wsgi @@ -0,0 +1,9 @@ +#! /usr/bin/python3 + +import logging +import sys +logging.basicConfig(stream=sys.stderr) +sys.path.insert(0, '/home/pi/RaspberryPie/RaspberryPie/') +from flask_backend import app as application + +application.secret_key = "Whatever" \ No newline at end of file diff --git a/RaspberryPie/js/main.js b/RaspberryPie/js/main.js new file mode 100644 index 0000000..e69de29 diff --git a/RaspberryPie/raspberryPie.py b/RaspberryPie/raspberryPie.py index c512618..7da6fa1 100644 --- a/RaspberryPie/raspberryPie.py +++ b/RaspberryPie/raspberryPie.py @@ -19,6 +19,9 @@ import Adafruit_DHT from picamera import PiCamera import RPi.GPIO as GPIO +# imports from project +import RaspberryPie.tasks + config = configparser.RawConfigParser() config.read("config.cfg") # edit this file for your specific configuration @@ -105,6 +108,7 @@ class MajGenApiTelecom: MajGenApiTelecom.delete_mail(id) def __init__(self, email_function, dropbox_function): + # using functions so in future, the storing can "easily" made more secure (not always stored in memory hopefully) self.email_function = email_function self.dropbox_function = dropbox_function self.mail_config = config["Mail"] @@ -209,11 +213,13 @@ class MajGenGPIOController: GPIO.cleanup() def close(self): + self.kill() GPIO.output(self.pinClose, GPIO.LOW) GPIO.output(self.pinOpen, GPIO.HIGH) captScribe.info("GPIO set to closing", "MajGenGPIOControl.close") def open(self): + self.kill() GPIO.output(self.pinClose, GPIO.HIGH) GPIO.output(self.pinOpen, GPIO.LOW) captScribe.info("GPIO set to opening", "MajGenGPIOControl.open") @@ -221,6 +227,7 @@ class MajGenGPIOController: def kill(self): GPIO.output(self.pinClose, GPIO.HIGH) GPIO.output(self.pinOpen, GPIO.HIGH) + time.sleep(.5) # waiting, so relay definetly has switched captScribe.info("GPIO switched off", "MajGenGPIOControl.kill") def delayedSwitchOff(self): @@ -254,13 +261,6 @@ class LtGenDataCollector: self._archive(event, {time: data}) class LtGenInterpreter: - class Task: - def __init__(self, function, check): - self.function = function - self.check = check - def test(self, email: MajGenApiTelecom.Telegram): - return self.check - def __init__(self, tasks: list, communicator: MajGenApiTelecom): self.tasks = tasks self.communicator = communicator @@ -301,6 +301,14 @@ class GenScheduler: reboot_str = lambda: " -r" if reboot else "" os.system("shutdown{} 0".format(reboot_str())) +def init(): + lib = {} + captScribe = CaptScribe(config["File Locations"]["logfile_info"], config["File Locations"]["logfile_error"]) + majGenObserver = MajGenObserver() + majGenApiTelecom = MajGenApiTelecom(lambda: {"address": config["Secrets"]["emailaddress"], "password": config["Secrets"]["emailpassword"]}, lambda: config["Secrets"]["dropboxtoken"]) + majGenGPIOController = MajGenGPIOController(config["Hardware"]["pinopen"], config["Hardware"]["pinclose"], config["Timing"]["gpioswitchoff"]) + ltGenDataCollector = LtGenDataCollector({"air": majGenObserver.get_sensorData(), "picture": majGenObserver.get_picture()}, lib) + ltGenInterpreter = LtGenInterpreter(RaspberryPie.tasks.tasks, majGenApiTelecom) -captScribe = CaptScribe("", "") -majGenGPIOController = MajGenGPIOController(0, 0, 0) \ No newline at end of file + +init() diff --git a/RaspberryPie/tasks.py b/RaspberryPie/tasks.py new file mode 100644 index 0000000..1b837ca --- /dev/null +++ b/RaspberryPie/tasks.py @@ -0,0 +1,11 @@ +class Task: + def __init__(self, function, check): + self.function = function + self.check = check + def test(self, email: MajGenApiTelecom.Telegram): + return self.check + +tasks = [ + Task(majGenGPIOController.open, lambda msg: 1 if ("auf" == msg.subject.lower() or "open" == msg.subject.lower()) else 0), + Task(majGenGPIOController.close, lambda msg: 1 if ("zu" == msg.subject.lower() or "close" == msg.subject.lower()) else 0) +] \ No newline at end of file diff --git a/RaspberryPie/templates/index.html b/RaspberryPie/templates/index.html new file mode 100644 index 0000000..d5154a3 --- /dev/null +++ b/RaspberryPie/templates/index.html @@ -0,0 +1,29 @@ + + +
+ + +{{ WeatherTime }}
Temperature: {{ temp }}, Humidity: {{ humi }}
+
+
+
\ No newline at end of file