wetterstation:alle_sensoren
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| wetterstation:alle_sensoren [2020/12/03 14:27] – benjamin | wetterstation:alle_sensoren [2023/05/15 13:09] (aktuell) – marlon | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | =====Komplete Kontroll===== | + | =====Raspberry Py - Server Abfragen===== |
| - | Hier befindet sich der Code, die alle Sensoren | + | Bei Anfragen vom Server führt dieses Programm den Code für die einzelnen |
| - | Es beinhaltet: | + | |
| - | ===Temperatur=== | + | |
| - | * [[wetterstation: | + | |
| + | |||
| + | Hier befindet sich der Code, für die einzelnen Sensoren:\\ | ||
| + | |||
| + | ===Temperatur=== | ||
| + | * [[wetterstation: | ||
| * [[wetterstation: | * [[wetterstation: | ||
| - | ===UV Sensor=== | + | ===UV Sensor=== |
| * [[wetterstation: | * [[wetterstation: | ||
| - | ===Windgeschwindigkeit=== | + | ===Windgeschwindigkeit=== |
| * [[wetterstation: | * [[wetterstation: | ||
| - | ===Windrichtung=== | + | ===Windrichtung=== |
| * [[wetterstation: | * [[wetterstation: | ||
| - | ===Regensensor=== | + | ===Regensensor=== |
| * [[wetterstation: | * [[wetterstation: | ||
| + | |||
| + | === Der Code, der auf dem Raspberry Pi ausgeführt wird: === | ||
| + | |||
| + | https:// | ||
| <code python> | <code python> | ||
| - | import time | + | from flask import |
| - | import RPi.GPIO as GPIO | + | from flask import |
| - | import math | + | import camera |
| - | from gpiozero | + | |
| - | from gpiozero | + | |
| - | GPIO.setmode(GPIO.BOARD) | + | |
| - | Niederschlag = 0 | + | |
| - | N = 2 | + | |
| - | adc = MCP3008(channel=0) | + | |
| - | windrichtung = {0.4: " | + | |
| - | y = " | + | |
| - | j = " | + | |
| - | f = 0 | + | |
| - | k = 0 | + | |
| - | radius_cm = 9.0 | + | |
| - | zeit = time.time() | + | |
| - | km_per_hour = 0 | + | |
| - | sensor_path = "/ | + | |
| - | wind_speed_sensor = Button(5) | + | |
| - | Regensensor = Button(N) | + | |
| - | old = 5 | + | |
| - | def halfturn(): | + | app = Flask(__name__) |
| - | global zeit | + | |
| - | global km_per_hour | + | |
| - | zeit2 = time.time() | + | |
| - | diff = zeit2 - zeit | + | |
| - | zeit = zeit2 | + | |
| - | circumference_cm = math.pi * radius_cm | + | |
| - | speed_cm_per_sec = circumference_cm / diff | + | |
| - | km_per_sec = speed_cm_per_sec / 100000.0 | + | |
| - | km_per_hour = km_per_sec * 3600 | + | |
| - | wind_speed_sensor.when_pressed = halfturn | ||
| - | def get_temp(): | ||
| - | f = open(sensor_path, | ||
| - | content = f.readlines() | ||
| - | f.close() | ||
| - | temp = " | ||
| - | if (content[0].strip())[-3: | ||
| - | index = content[-1].find(' | ||
| - | if index != -1: | ||
| - | temp = float(content[-1][index+2: | ||
| - | temp = temp/1000.0 | ||
| - | return temp | ||
| - | def Temperatur(): | + | @app.route('/' |
| - | | + | def index(): |
| - | | + | |
| - | | + | |
| + | import rain | ||
| + | import winddirection | ||
| + | import uv | ||
| + | import BME280 | ||
| - | def Windrichtung(): | + | rain = rain.rainfall() |
| - | | + | speed = speed.speed() |
| - | | + | direction = winddirection.Windrichtung() |
| - | | + | |
| + | UV = uv.out() | ||
| + | bme280 = BME280.getPressure() | ||
| + | |||
| + | all_sensores = speed + " | ||
| + | print(all_sensores + 10*' ', end=" | ||
| + | |||
| + | sensor_data = { | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | | ||
| + | ' | ||
| + | } | ||
| - | def Niederschlagssensor(): | + | print(sensor_data) |
| - | | + | |
| - | Niederschlag = Niederschlag + 0.1397 | + | |
| - | Regensensor.when_pressed = Niederschlagssensor | ||
| - | while True: | + | @app.route('/ |
| - | b = Windrichtung() | + | def picture(): |
| - | a = Temperatur() | + | # import camera.py |
| - | Zeit3 = time.time() | + | camera.take_picture() |
| - | if Zeit3 - zeit > 3: | + | |
| - | km_per_hour = 0 | + | |
| - | # time.sleep(0.5) | + | app.run(debug=False, host=' |
| - | c = km_per_hour = round(km_per_hour, 1) | + | |
| - | if b != y: | + | |
| - | print(" | + | |
| - | y = b | + | |
| - | elif j != a: | + | |
| - | print(" | + | |
| - | j = a | + | |
| - | elif k != c: | + | |
| - | print(" | + | |
| - | k = c | + | |
| - | elif f != Niederschlag: | + | |
| - | print(" | + | |
| - | f = Niederschlag | + | |
| </ | </ | ||
| {{: | {{: | ||
wetterstation/alle_sensoren.1607005675.txt.gz · Zuletzt geändert: von benjamin
