MikrofonSensor und TemperaturSenor die zwei Python programme funktionieren. mit den jeweiligen 2 json Datein. Beim TemperaturSensor wird im Terminal keine Wertre ausgegeben aber in der json Datei kann man die Temp und Hum sehen.
This commit is contained in:
parent
4c654ec969
commit
1751076592
2614 changed files with 349009 additions and 0 deletions
30
sensors/ky015_data.json
Normal file
30
sensors/ky015_data.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"id": "sensor_002/3",
|
||||
"type": "environment",
|
||||
"unit": {
|
||||
"temperature": "°C",
|
||||
"humidity": "%"
|
||||
},
|
||||
"reading": [
|
||||
{
|
||||
"ts": 1748436535,
|
||||
"temperature": 24.7,
|
||||
"humidity": 58
|
||||
},
|
||||
{
|
||||
"ts": 1748436538,
|
||||
"temperature": 24.6,
|
||||
"humidity": 58
|
||||
},
|
||||
{
|
||||
"ts": 1748436541,
|
||||
"temperature": 24.7,
|
||||
"humidity": 58
|
||||
},
|
||||
{
|
||||
"ts": 1748436544,
|
||||
"temperature": 24.7,
|
||||
"humidity": 59
|
||||
}
|
||||
]
|
||||
}
|
|
@ -154,6 +154,158 @@
|
|||
{
|
||||
"ts": 1747819735,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421490,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421491,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421492,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421493,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421494,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421495,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421496,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421497,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421498,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421499,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421500,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421501,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421502,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421503,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421504,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421505,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421506,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421507,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421508,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421509,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421510,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421511,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421512,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421513,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421514,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421515,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421516,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421517,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421518,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421519,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421520,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421521,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421522,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748421523,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421524,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421525,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421526,
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"ts": 1748421528,
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
}
|
|
@ -11,6 +11,7 @@ INTERVAL = 1
|
|||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(SENSOR_PIN, GPIO.IN)
|
||||
|
||||
|
||||
SENSOR_INFO = {
|
||||
"id": "sensor_001",
|
||||
"type": "noise", # Geräuschsensor
|
|
@ -0,0 +1,9 @@
|
|||
Temperatur Sensor: Ich müss eine extra venv umgebung erstellen für den Sensor DHT11. Ich mache alles in Visula Studio Code. Ich habe eine Test programm versucht. test.temp.py
|
||||
Fehlermeldungen:
|
||||
1. Board nicht gefunden: pip install board
|
||||
2. adafruit_dht nicht funktioniert: pip3 install adafruit-circuitpython-dht
|
||||
3. RPI nicht gefunden: pip install RPI.GPIO
|
||||
|
||||
|
||||
|
||||
TemperaturSensor:
|
79
sensors/temperaturSensor.py
Normal file
79
sensors/temperaturSensor.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
import time
|
||||
import board
|
||||
import adafruit_dht
|
||||
import json
|
||||
from datetime import datetime
|
||||
import os
|
||||
|
||||
dhtDevice = adafruit_dht.DHT11(board.D23)
|
||||
|
||||
json_file = "ky015_data.json"
|
||||
|
||||
datatemphum = {
|
||||
"id": "sensor_002/3",
|
||||
"type": "environment",
|
||||
"unit": {
|
||||
"temperature": "°C",
|
||||
"humidity": "%"
|
||||
},
|
||||
"reading": []
|
||||
}
|
||||
|
||||
|
||||
def load_data():
|
||||
if os.path.exists(json_file):
|
||||
with open(json_file, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
else:
|
||||
return datatemphum.copy()
|
||||
|
||||
def save_data(data):
|
||||
with open(json_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||
|
||||
max_entries=3000
|
||||
|
||||
def capture_and_store(temperature_c,humidity):
|
||||
timestamp = int(time.time())
|
||||
|
||||
data = load_data()
|
||||
data["reading"].append({
|
||||
"ts": timestamp,
|
||||
"temperature": temperature_c,
|
||||
"humidity":humidity
|
||||
})
|
||||
|
||||
|
||||
if len(data["reading"]) > max_entries:
|
||||
data["reading"] = data["reading"][-max_entries:]
|
||||
|
||||
save_data(data)
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
temperature_c = dhtDevice.temperature
|
||||
humidity = dhtDevice.humidity
|
||||
|
||||
timestamp = datetime.now().isoformat()
|
||||
|
||||
if temperature_c is not None and humidity is not None:
|
||||
capture_and_store(temperature_c, humidity)
|
||||
else:
|
||||
print("Ungültige Messwerte.")
|
||||
|
||||
except RuntimeError as error:
|
||||
print("Lese-Fehler:", error.args[0])
|
||||
dhtDevice.exit()
|
||||
time.sleep(3.0)
|
||||
dhtDevice=adafruit_dht.DHT11(board.D23)
|
||||
continue
|
||||
except KeyboardInterrupt:
|
||||
dhtDevice.exit()
|
||||
print("Beendet durch Benutzer.")
|
||||
break
|
||||
except Exception as error:
|
||||
dhtDevice.exit()
|
||||
raise error
|
||||
|
||||
time.sleep(3.0)
|
Loading…
Add table
Add a link
Reference in a new issue