from flask import Flask import RPi.GPIO as gpio from time import sleep import subprocess import picamera import pyshine as ps # pip3 install pyshine==0.0.9 # Camera server def camera(): HTML=""" PyShine Live Streaming

PyShine Live Streaming using OpenCV

""" StreamProps = ps.StreamProps StreamProps.set_Page(StreamProps,HTML) address = ('0.0.0.0',9000) # Enter your IP address StreamProps.set_Mode(StreamProps,'picamera') with picamera.PiCamera(resolution='640x480', framerate=30) as camera: output = ps.StreamOut() StreamProps.set_Output(StreamProps,output) camera.rotation = 90 camera.start_recording(output, format='mjpeg') try: server = ps.Streamer(address, StreamProps) print('Camera serving started at','http://'+address[0]+':'+str(address[1])) server.serve_forever() finally: camera.stop_recording() # 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 app = Flask(__name__) @app.route("/") def hello_world(): return f"

{HTP()}

" if __name__=="__main__": app.run(host='0.0.0.0')