Copy over other files from christoph
This commit is contained in:
3
schreiomat-receiver/queryschreiomat.sh
Executable file
3
schreiomat-receiver/queryschreiomat.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
influx query 'from(bucket:"schreiomat") |> range(start:-1h)'
|
||||
44
schreiomat-receiver/schreiomat-receiver.py
Executable file
44
schreiomat-receiver/schreiomat-receiver.py
Executable 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()
|
||||
12
schreiomat-receiver/schreiomat-receiver.service
Normal file
12
schreiomat-receiver/schreiomat-receiver.service
Normal 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
|
||||
Reference in New Issue
Block a user