Die Sensoren sind fertig. Der Python Code müsste passen.
This commit is contained in:
parent
879c5eb881
commit
4a58d6cce5
36 changed files with 41 additions and 91 deletions
|
@ -1 +0,0 @@
|
|||
[]
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"id": "sensor_004",
|
||||
"type": "light",
|
||||
"unit": "state",
|
||||
"reading": [
|
||||
{
|
||||
"ts": 1748452265,
|
||||
"state": "dunkel"
|
||||
},
|
||||
{
|
||||
"ts": 1748452267,
|
||||
"state": "dunkel"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
{
|
||||
"id": "sensor_001",
|
||||
"type": "noise",
|
||||
"unit": "bool",
|
||||
"readings": [
|
||||
{
|
||||
"ts": 1748452253,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748452254,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748452255,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748452256,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748452257,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748452258,
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"ts": 1748452259,
|
||||
"value": 1
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -4,17 +4,18 @@ import os
|
|||
import board
|
||||
import digitalio
|
||||
|
||||
json_file = "ky018_data.json"
|
||||
json_file = "json/ky018_data.json"
|
||||
MAX_ENTRIES = 3000
|
||||
|
||||
light_pin = digitalio.DigitalInOut(board.D17)
|
||||
light_pin.direction = digitalio.Direction.INPUT
|
||||
|
||||
data_template = {
|
||||
dataldr = {
|
||||
"location": "Hausstrasse - 1",
|
||||
"id": "sensor_004",
|
||||
"type": "light",
|
||||
"unit": "bool",
|
||||
"reading": []
|
||||
"readings": []
|
||||
}
|
||||
|
||||
def load_data():
|
||||
|
@ -22,7 +23,7 @@ def load_data():
|
|||
with open(json_file, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
else:
|
||||
return data_template.copy()
|
||||
return dataldr.copy()
|
||||
|
||||
def save_data(data):
|
||||
with open(json_file, 'w', encoding='utf-8') as f:
|
||||
|
@ -32,10 +33,10 @@ def capture_and_store(state):
|
|||
timestamp = int(time.time())
|
||||
data = load_data()
|
||||
|
||||
data["reading"].append({"ts": timestamp,"value": state})
|
||||
data["readings"].append({"ts": timestamp,"value": state})
|
||||
|
||||
if len(data["reading"]) > MAX_ENTRIES:
|
||||
data["reading"] = data["reading"][-MAX_ENTRIES:]
|
||||
if len(data["readings"]) > MAX_ENTRIES:
|
||||
data["readings"] = data["readings"][-MAX_ENTRIES:]
|
||||
|
||||
save_data(data)
|
||||
|
||||
|
|
|
@ -5,17 +5,18 @@ from datetime import datetime
|
|||
import os
|
||||
|
||||
SENSOR_PIN = 17
|
||||
JSON_FILE = "ky037_data.json"
|
||||
JSON_FILE = "json/ky037_data.json"
|
||||
INTERVAL = 1
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(SENSOR_PIN, GPIO.IN)
|
||||
|
||||
|
||||
SENSOR_INFO = {
|
||||
datamikro = {
|
||||
"location": "Hausstrasse - 2",
|
||||
"id": "sensor_001",
|
||||
"type": "noise", # Geräuschsensor
|
||||
"unit": "bool", # 1 oder 0 (geräusch ja/nein)
|
||||
"type": "noise",
|
||||
"unit": "bool",
|
||||
"readings": []
|
||||
}
|
||||
|
||||
|
@ -24,7 +25,7 @@ def load_data():
|
|||
with open(JSON_FILE, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
else:
|
||||
return SENSOR_INFO.copy() # frisches Grundgerüst
|
||||
return datamikro.copy()
|
||||
|
||||
def save_data(data):
|
||||
with open(JSON_FILE, 'w', encoding='utf-8') as f:
|
||||
|
@ -32,7 +33,7 @@ def save_data(data):
|
|||
|
||||
def capture_and_store():
|
||||
state = GPIO.input(SENSOR_PIN)
|
||||
timestamp = int(time.time()) # Unix-Zeitstempel (int)
|
||||
timestamp = int(time.time())
|
||||
noise = True if state == 0 else False
|
||||
|
||||
entry = { "ts": timestamp, "value": noise}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
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:
|
|
@ -9,23 +9,30 @@ dhtDevice = adafruit_dht.DHT11(board.D23)
|
|||
|
||||
json_file = "json/ky015_data.json"
|
||||
|
||||
datatemphum = {
|
||||
"id": "sensor_002/3",
|
||||
"type": "environment",
|
||||
"unit": {
|
||||
"temperature": "°C",
|
||||
"humidity": "%"
|
||||
},
|
||||
"reading": []
|
||||
datatemp = {
|
||||
"location": "Hausstrasse - 3",
|
||||
"sensors": [
|
||||
{
|
||||
"id": "sensor_002",
|
||||
"type": "temperature",
|
||||
"unit": "°C",
|
||||
"readings": []
|
||||
},
|
||||
{
|
||||
"id": "sensor_003",
|
||||
"type": "humidity",
|
||||
"unit": "%",
|
||||
"readings": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
return datatemp.copy()
|
||||
|
||||
def save_data(data):
|
||||
with open(json_file, 'w', encoding='utf-8') as f:
|
||||
|
@ -35,17 +42,18 @@ max_entries=3000
|
|||
|
||||
def capture_and_store(temperature_c,humidity):
|
||||
timestamp = int(time.time())
|
||||
data=load_data()
|
||||
|
||||
data = load_data()
|
||||
data["reading"].append({
|
||||
"ts": timestamp,
|
||||
"temperature": temperature_c,
|
||||
"humidity":humidity
|
||||
})
|
||||
temp_sensor = next(s for s in data["sensors"] if s["type"] == "temperature")
|
||||
hum_sensor = next(s for s in data["sensors"] if s["type"] == "humidity")
|
||||
|
||||
temp_sensor["readings"].append({"ts": timestamp, "value": temperature_c})
|
||||
hum_sensor["readings"].append({"ts": timestamp, "value": humidity})
|
||||
|
||||
if len(data["reading"]) > max_entries:
|
||||
data["reading"] = data["reading"][-max_entries:]
|
||||
if len(temp_sensor["readings"]) > max_entries:
|
||||
temp_sensor["readings"] = temp_sensor["readings"][-max_entries:]
|
||||
if len(hum_sensor["readings"]) > max_entries:
|
||||
hum_sensor["readings"] = hum_sensor["readings"][-max_entries:]
|
||||
|
||||
save_data(data)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue