Copy over other files from christoph

This commit is contained in:
Sven Koehler
2024-01-16 22:10:54 +01:00
parent 65340158b3
commit 7b1fe5f7fd
12 changed files with 307 additions and 16 deletions

View File

@@ -0,0 +1,3 @@
#!/usr/bin/bash
influx query 'from(bucket:"schreiomat") |> range(start:-1h)'

View File

@@ -0,0 +1,44 @@
import os
import paho.mqtt.client as mqtt
from influxdb_client import InfluxDBClient
from influxdb_client import Point
from influxdb_client.client.write_api import SYNCHRONOUS
import json
import logging
logging.basicConfig(level=logging.DEBUG)
# mqttc = mqtt.Client("client-id")
# but note that the client id must be unique on the broker. Leaving the client
# id parameter empty will generate a random id for you.
mqttc = mqtt.Client()
influx_client = InfluxDBClient(url="http://localhost:8086", token="7KIKWL-7REcvJzNnDHKmvTDWqtJ_vflOfDXwncM78SI80xLEo2aXrjiLspCxPhVTiWFn4V6VWfAqedaxLJX9nQ==", org="sensors")
write_api = influx_client.write_api(write_options=SYNCHRONOUS)
def messageReceived(client, userdata, message):
print("received topic" + str(message.topic) + "with payload: " + str(message.payload) + "\n")
sensorId = message.topic.replace("schreiomat/","")
print("sensor id: " + sensorId)
print("sending")
result = ""
write_api.write("dac77b8b5d0fd121", "sensors", Point("soundlevel").tag("sensor", sensorId).field("dbA", float(message.payload)))
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
if (rc == 0):
print("(Success)")
else:
print("(Fail)")
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("schreiomat/#", 0)
mqttc.username_pw_set("knurps", "LEPEZ1ELYDUmjg")
mqttc.on_message = messageReceived
mqttc.on_connect = on_connect
mqttc.connect("ccc-p.org", 1883, 60)
mqttc.loop_forever()

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Sending the noise data to the influx db
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python /usr/bin/schreiomat-receiver
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target