#!/usr/local/bin/python -u
__author__ = "Oliver Ratzesberger"

print "Starting InfluxDB JSON feed for Rainforest Eagle"

import requests
import json
import random
import time
import os
import ConfigParser

from RainEagle import Eagle, to_epoch_1970

config = ConfigParser.ConfigParser()
config.read(os.path.expanduser('~/home.cfg'))

eagle_addr     = config.get('raineagle', 'eagle_addr')
influx_addr    = config.get('influxdb', 'influx_addr')
influx_port    = config.get('influxdb', 'influx_port')
influx_db      = config.get('influxdb', 'influx_db')
influx_user    = config.get('influxdb', 'influx_user')
influx_pass    = config.get('influxdb', 'influx_pass')

influx_path = "http://" + influx_addr + ":" + influx_port + "/db/" + influx_db + "/series?time_precision=s&u=" + influx_user
print "Path: " + influx_path
 
eg = Eagle(debug=0, addr=eagle_addr)

while True:
  raindata= eg.get_device_data()

  idemand = raindata['InstantaneousDemand']

  multiplier = int(idemand['Multiplier'], 16)
  divisor = int(idemand['Divisor'], 16)
  demand = int(idemand['Demand'], 16)

  if demand > 0x7FFFFFFF: demand -= 0x100000000

  if multiplier == 0 : multiplier = 1

  if divisor == 0 : divisor = 1

  power = ((demand * multiplier) / float (divisor))*1000
  amps = power/240

  event = [{
    'name': 'power',
    'columns': [ 'whole_house_power', 'whole_house_amps' ],
    'points': [[ power, amps ]]
  }]

  print event

  try:
    r = requests.post(influx_path + "&p=" + influx_pass, data=json.dumps(event))
    print r
  except Exception:
    print 'Exception posting data to ' + influx_path
    pass

  time.sleep(5)

@@ -378,24 +378,101 @@
 agle_addr')%0A
+eagle_poll_interval = int(config.get('raineagle', 'eagle_poll_interval', 1))%0A
 influx_addr 
@@ -887,17 +887,16 @@
 ux_path%0A
- 
 %0Aeg = Ea
@@ -981,16 +981,20 @@
  idemand
+data
  = raind
@@ -1023,16 +1023,17 @@
 nd'%5D%0A%0A  
+i
 multipli
@@ -1048,16 +1048,20 @@
 (idemand
+data
 %5B'Multip
@@ -1074,16 +1074,17 @@
 , 16)%0A  
+i
 divisor 
@@ -1096,16 +1096,20 @@
 (idemand
+data
 %5B'Diviso
@@ -1119,16 +1119,17 @@
 , 16)%0A  
+i
 demand =
@@ -1140,16 +1140,20 @@
 (idemand
+data
 %5B'Demand
@@ -1166,16 +1166,17 @@
 )%0A%0A  if 
+i
 demand %3E
@@ -1188,16 +1188,17 @@
 FFFFFF: 
+i
 demand -
@@ -1211,22 +1211,22 @@
 0000000%0A
-%0A
   if 
+i
 multipli
@@ -1235,16 +1235,17 @@
  == 0 : 
+i
 multipli
@@ -1251,22 +1251,22 @@
 ier = 1%0A
-%0A
   if 
+i
 divisor 
@@ -1272,16 +1272,17 @@
  == 0 : 
+i
 divisor 
@@ -1298,16 +1298,17 @@
 wer = ((
+i
 demand *
@@ -1308,16 +1308,17 @@
 emand * 
+i
 multipli
@@ -1330,16 +1330,17 @@
  float (
+i
 divisor)
@@ -1366,16 +1366,508 @@
 er/240%0A%0A
+  csumdata = raindata%5B'CurrentSummation'%5D%0A%0A  csummultiplier = int(csumdata%5B'Multiplier'%5D, 16)%0A  csumdivisor = int(csumdata%5B'Divisor'%5D, 16)%0A  csumreceived = int(csumdata%5B'SummationReceived'%5D, 16)%0A  csumdelivered = int(csumdata%5B'SummationDelivered'%5D, 16)%0A%0A  if csummultiplier == 0 : csummultiplier = 1%0A  if csumdivisor == 0 : csumdivisor = 1%0A%0A  received = ((csumreceived * csummultiplier) / float (csumdivisor))*1000%0A  delivered = ((csumdelivered * csummultiplier) / float (csumdivisor))*1000%0A%0A
   event 
@@ -1948,16 +1948,65 @@
 se_amps'
+, 'whole_house_received', 'whole_house_delivered'
  %5D,%0A    
@@ -2029,16 +2029,37 @@
 er, amps
+, received, delivered
  %5D%5D%0A  %7D%5D
@@ -2275,7 +2275,25 @@
 eep(
-5
+eagle_poll_interval
 )%0A

Add Summation Data