|
- import json
- import RainEagle
- import sys
- import time
-
- def print_data(*args):
- print '\t'.join(x.encode('utf8').encode('string-escape') for x in args)
-
- 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)
- tzinterval = conf.get('tzinterval', 24*60*60)
- tzs = 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_data('l', *(usage_data[x] for x in fields))
- e = time.time()
-
- if e >= tzs:
- tzs += tzinterval
- # {u'timezone_tzName': u'GMT+7', u'timezone_status': u'success', u'timezone_localTime': u'1571844539', u'timezone_olsonName': u'Etc/GMT+7', u'timezone_utcTime': u'1571869739', u'timezone_utcOffset': u'-0700'}
- tzinfo = raineagle.get_timezone(macid)
- tzoffset = int(tzinfo['timezone_utcTime']) - \
- int(tzinfo['timezone_localTime'])
- tzfields = [ 'timezone_tzName', 'timezone_localTime',
- 'timezone_utcTime', 'timezone_utcOffset' ]
- print_data('z', *(tzinfo[x] for x in tzfields))
-
- sys.stdout.flush()
- s += interval
- delay = s - e
- if delay <= 0:
- s = time.time()
- continue
-
- time.sleep(delay)
- #print `raineagle.get_time_source(macid)`
|