PWSS/main.py

49 lines
1.2 KiB
Python
Raw Normal View History

2022-01-02 00:40:42 +02:00
from flask import Flask
2022-01-02 02:29:31 +02:00
import RPi.GPIO as gpio
from time import sleep
import subprocess
2022-01-02 00:40:42 +02:00
2022-01-02 02:29:31 +02:00
# MQ-135 gas sensor
def stinker():
gpio.setmode(gpio.BCM)
gpio.setup(4, gpio.IN)
try:
if gpio.input(4):
return False
else:
return True
sleep(2)
except KeyboardInterrupt:
print("\n")
finally:
print("clean")
gpio.cleanup()
# BME280 Humidity, Temperature, Pressure sensor
def HTP():
string = subprocess.check_output(["./HTP"]).decode(encoding='UTF-8',errors='strict')
string = string.split("temperature:")[1]
temperature = string.split(" pressure:")[0].replace("*C", "C")
string = string.split(" pressure:")[1]
pressure = string.split(" humidity:")[0]
humidity = string.split(" humidity:")[1].replace("\r\n", "")
result = {
"temperature":temperature,
"pressure":pressure,
"humidity":humidity}
# for i in string:
# if i.isdigit():
# result.append(i)
return result
# Flask server
2022-01-02 00:40:42 +02:00
app = Flask(__name__)
@app.route("/")
def hello_world():
2022-01-02 02:29:31 +02:00
return f"<p>{HTP()}</p>"
2022-01-02 00:40:42 +02:00
if __name__=="__main__":
2022-01-02 02:29:31 +02:00
app.run(host='0.0.0.0')