-
-
Save kylejohnson/1cc2681fbff54be2a4dfefb2d6179889 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import Adafruit_DHT | |
| sensor = Adafruit_DHT.DHT22 | |
| pin = 26 | |
| humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) | |
| if humidity is not None and temperature is not None: | |
| print('{0:0.0f}').format(humidity) | |
| #print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| humidity=$(python ~/h.py) | |
| # Regex to make sure $humidity is what I want it to be. | |
| re='^[0-9]+([.][0-9]+)?$' | |
| if ! [[ "$humidity" =~ $re ]] ; then | |
| echo "error: Not a number" >&2 | |
| exit 1 | |
| else | |
| # Log a message to syslog | |
| logger -t humidity "sending over $humidity" | |
| if mosquitto_pub -h mqtt.home.gnulnx.net -p 8883 --cafile tls/ca.crt --cert tls/bedroom.crt --key tls/bedroom.key -t "environment/bedroom/humidity" -m "$humidity" -r; then | |
| logger -t humidity 'success' | |
| else | |
| logger -t humidity 'failure' | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment