|
|
@@ -0,0 +1,50 @@ |
|
|
|
import json |
|
|
|
import RainEagle |
|
|
|
import sys |
|
|
|
import time |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
with open('eagle.config') as fp: |
|
|
|
conf = json.load(fp) |
|
|
|
|
|
|
|
raineagle = RainEagle.Eagle( debug=0 , addr=conf['addr'], |
|
|
|
username = conf['username'], |
|
|
|
password = conf['password'] |
|
|
|
) |
|
|
|
|
|
|
|
try: |
|
|
|
macid = conf['macid'] |
|
|
|
except KeyError: |
|
|
|
ret_data = raineagle.list_devices() |
|
|
|
#print 'list devices:', `ret_data` |
|
|
|
macid = ret_data['DeviceInfo']['DeviceMacId'] |
|
|
|
#print "device MacID = ", macid |
|
|
|
print >>sys.stderr, 'macid not specified, detected:', `macid` |
|
|
|
|
|
|
|
#macid = '0xd8d5b90000001346' |
|
|
|
|
|
|
|
#print `raineagle.get_instantaneous_demand(macid)` |
|
|
|
#print `raineagle.get_summation_values(macid, interval='day')` |
|
|
|
#print `raineagle.get_fast_poll_status(macid)` |
|
|
|
interval = conf.get('interval', 10) |
|
|
|
s = time.time() |
|
|
|
while True: |
|
|
|
usage_data = raineagle.get_usage_data(macid) |
|
|
|
if False: |
|
|
|
print `usage_data` |
|
|
|
else: |
|
|
|
#{u'message_queue': u'active', u'threshold_lower_demand': u'-2.000000', u'fast_poll_frequency': u'0x00', u'summation_delivered': u'65374.021', u'message_read': u'Y', u'price': u'0.2700', u'demand_timestamp': u'1571842464', u'fast_poll_endtime': u'0x00000000', u'meter_status': u'Connected', u'message_confirm_required': u'N', u'message_confirmed': u'N', u'demand_units': u'kW', u'summation_units': u'kWh', u'demand': u'0.9980', u'price_units': u'840', u'message_timestamp': u'946684800', u'price_label': u'Set by User', u'threshold_upper_demand': u'9.155000', u'message_id': u'0', u'summation_received': u'0.000'} |
|
|
|
fields = [ 'demand_timestamp', 'meter_status', 'demand', |
|
|
|
'threshold_upper_demand', 'demand_units', 'summation_delivered', |
|
|
|
'summation_received', 'summation_units', ] |
|
|
|
print '\t'.join(usage_data[x].encode('utf8').encode('string-escape') for x in fields) |
|
|
|
e = time.time() |
|
|
|
s += interval |
|
|
|
delay = s - e |
|
|
|
print `delay` |
|
|
|
if delay <= 0: |
|
|
|
s = time.time() |
|
|
|
continue |
|
|
|
|
|
|
|
time.sleep(delay) |
|
|
|
#print `raineagle.get_time_source(macid)` |