added stat mqtt watcher
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Oct 2018 11:52:14 +0000 (12:52 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Oct 2018 11:54:29 +0000 (12:54 +0100)
mqtt-stat-pgsql.service [new file with mode: 0644]
mqtt-stat-pgsql.sh [new file with mode: 0755]
stat.sql [new file with mode: 0644]

diff --git a/mqtt-stat-pgsql.service b/mqtt-stat-pgsql.service
new file mode 100644 (file)
index 0000000..128403d
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=mqtt-stat-pgsql
+
+[Service]
+User=dpavlin
+ExecStart=/klin/rtl433-sensors/mqtt-stat-pgsql.sh
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/mqtt-stat-pgsql.sh b/mqtt-stat-pgsql.sh
new file mode 100755 (executable)
index 0000000..b954c3a
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh -e
+
+mosquitto_sub -h 10.13.37.5 -t 'stat/#' -v | while read topic value ; do
+       topic=`echo $topic | sed 's/^stat\///'`
+       psql --quiet -c "insert into stat (topic,value) values ('$topic','$value')" rot13
+done
diff --git a/stat.sql b/stat.sql
new file mode 100644 (file)
index 0000000..48a253a
--- /dev/null
+++ b/stat.sql
@@ -0,0 +1,8 @@
+drop table stat;
+create table stat (
+       _id serial,
+       time timestamp without time zone default now(),
+       topic text not null,
+       value text
+);
+