From 25c6442bb4d5616712893f6c4a8993bf1f097323 Mon Sep 17 00:00:00 2001 From: Joachim Hummel Date: Fri, 6 Jan 2017 15:36:16 +0100 Subject: [PATCH] Added Scripts for MQTT --- scripts/pressure.sh | 3 +++ scripts/temperature.sh | 3 +++ temperature.py | 57 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100755 scripts/pressure.sh create mode 100755 scripts/temperature.sh create mode 100755 temperature.py diff --git a/scripts/pressure.sh b/scripts/pressure.sh new file mode 100755 index 0000000..a51db67 --- /dev/null +++ b/scripts/pressure.sh @@ -0,0 +1,3 @@ +PRESS1=`python /home/pi/myweather/pressure.py` + +mosquitto_pub -h mqtt.unixweb.de -p 1883 -t abcde/p1 -m $PRESS1 diff --git a/scripts/temperature.sh b/scripts/temperature.sh new file mode 100755 index 0000000..86cba74 --- /dev/null +++ b/scripts/temperature.sh @@ -0,0 +1,3 @@ +TEMP=`python /home/pi/myweather/tmperature.py |head -1` + +mosquitto_pub -h mqtt.unixweb.de -p 1883 -t abcde/temp1 -m $TEMP diff --git a/temperature.py b/temperature.py new file mode 100755 index 0000000..c169224 --- /dev/null +++ b/temperature.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# +# Creation: 02.01.2013 +# Last Update: 07.04.2015 +# +# Copyright (c) 2013-2015 by Georg Kainzbauer +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + +# import sys module +import sys + +# open 1-wire slaves list for reading +file = open('/sys/devices/w1_bus_master1/w1_master_slaves') + +# read 1-wire slaves list +w1_slaves = file.readlines() + +# close 1-wire slaves list +file.close() + +# print header for results table + +# repeat following steps with each 1-wire slave +for line in w1_slaves: + + # extract 1-wire slave + w1_slave = line.split("\n")[0] + + # open 1-wire slave file + file = open('/sys/bus/w1/devices/' + str(w1_slave) + '/w1_slave') + + # read content from 1-wire slave file + filecontent = file.read() + + # close 1-wire slave file + file.close() + + # extract temperature string + stringvalue = filecontent.split("\n")[1].split(" ")[9] + + # convert temperature value + temperature = float(stringvalue[2:]) / 1000 + + # print temperature + print(str() + "%.1f" % temperature) + #print temperature + + +# quit python script +sys.exit(0)