-
-
Save ulises/0d687bde76d1c6f60f07f620ecd1fe40 to your computer and use it in GitHub Desktop.
This file contains 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 time | |
import datetime | |
import sys | |
import logging | |
import flotilla | |
interval = 60 # report metrics every 60 seconds | |
hostname = "{{ inventory_hostname }}" | |
logging.basicConfig(filename='/var/log/plantinator/plantinator.log', | |
level=logging.DEBUG) | |
def putval(name, value): | |
print "PUTVAL %s/weather/gauge-%s interval=%d N:%f" % (hostname, | |
name, | |
interval, | |
value) | |
now = datetime.datetime.now() | |
logging.info("%s: PUTVAL %s/weather/gauge-%s interval=%d N:%f" % (now.isoformat(), | |
hostname, | |
name, | |
interval, | |
value)) | |
client = flotilla.Client() | |
while not client.ready: | |
pass | |
weather = client.first(flotilla.Weather) | |
light = client.first(flotilla.Light) | |
colour = client.first(flotilla.Colour) | |
r = int(colour.red/float(colour.clear)*255.0) | |
g = int(colour.green/float(colour.clear)*255.0) | |
b = int(colour.blue/float(colour.clear)*255.0) | |
putval("temperature", weather.temperature) | |
# unsure about units, but this is cleary the right scaling | |
putval("pressure", weather.pressure / 10.0) | |
putval("lux", light.lux) | |
putval("red", r) | |
putval("green", g) | |
putval("blue", b) | |
client.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment