Created
June 4, 2014 19:20
-
-
Save sergray/7ceb3e7ef239e282a9d2 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/env python | |
from __future__ import print_function | |
from datetime import datetime | |
from subprocess import call | |
from mercury206 import commands, communications, config | |
def update_rrd(path, values): | |
value = ':'.join(['N'] + map(str, values)) | |
call(['rrdtool', 'update', path, value]) | |
print("Updated", path) | |
def add_readings(port, address): | |
readings = commands.display_readings(port, address) | |
update_rrd('tariffs.rrd', readings[:2]) | |
def add_vcp(port, address): | |
voltage, current, power = commands.instant_vcp(port, address) | |
update_rrd('pcv.rrd', [power, current, voltage]) | |
def main(): | |
settings = config.get_settings() | |
port = communications.open_serial(settings['device']) | |
now = datetime.now() | |
if now.minute % 5 == 0: | |
add_readings(port, settings['address']) | |
add_vcp(port, settings['address']) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment