Created
October 22, 2016 13:24
-
-
Save aniline/68ab3a870a1a7d50c08149e8131aa205 to your computer and use it in GitHub Desktop.
Collect some stuff form apcupsd.
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/env python | |
from subprocess import Popen, PIPE | |
import urllib2 | |
from time import sleep | |
p = Popen(['/sbin/apcaccess'], stdout=PIPE, stderr=PIPE) | |
(o, e) = p.communicate() | |
status = {} | |
for l in o.splitlines(): | |
pm = l.split(':') | |
status[pm[0].strip()] = (':'.join(pm[1:])).strip() | |
voltage = status['LINEV'].split()[0] | |
loadpct = status['LOADPCT'].split()[0] | |
timeproj = status['TIMELEFT'].split()[0] | |
battchg = status['BCHARGE'].split()[0] | |
base_url='https://api.thingspeak.com/update?api_key=APIKEY' | |
update_url=base_url+'&field1='+voltage+'&field2='+loadpct+'&field3='+timeproj+'&field4='+battchg | |
try: | |
urllib2.urlopen(update_url, timeout = 10) | |
except urllib2.URLError, e: | |
pass | |
sleep(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment