RainEagle library plus script for polling data
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

106 lines
2.5 KiB

  1. #!/usr/local/bin/python2.7
  2. """
  3. A simple script get current meter values
  4. """
  5. __author__ = "Peter Shipley"
  6. import sys
  7. sys.path.append('/usr/home/shipley/Projects/Eagle') # temp
  8. # import RainEagle
  9. from RainEagle import Eagle, to_epoch_1970
  10. import time
  11. from pprint import pprint
  12. debug = 0
  13. def main() :
  14. eg = Eagle( debug=debug , addr="10.1.1.39")
  15. # timeout=45,
  16. r = eg.get_device_data()
  17. print_instantdemand( r['InstantaneousDemand'])
  18. print
  19. print_currentsummation(r['CurrentSummation'])
  20. print
  21. exit(0)
  22. def twos_comp(val, bits=32):
  23. """compute the 2's compliment of int value val"""
  24. if( (val&(1<<(bits-1))) != 0 ):
  25. val = val - (1<<bits)
  26. return val
  27. def print_currentsummation(cs) :
  28. multiplier = int(cs['Multiplier'], 16)
  29. divisor = int(cs['Divisor'], 16)
  30. delivered = int(cs['SummationDelivered'], 16)
  31. received = int(cs['SummationReceived'], 16)
  32. if multiplier == 0 :
  33. multiplier = 1
  34. if divisor == 0 :
  35. divisor = 1
  36. reading_received = received * multiplier / float (divisor)
  37. reading_delivered = delivered * multiplier / float (divisor)
  38. time_stamp = to_epoch_1970(cs['TimeStamp'])
  39. print "{0:s} : ".format(time.asctime(time.localtime(time_stamp)))
  40. print "\tReceived = {0:{width}.3f} Kw".format(reading_received, width=10)
  41. print "\tDelivered = {0:{width}.3f} Kw".format(reading_delivered, width=10)
  42. print "\t\t{0:{width}.3f} Kw".format( (reading_delivered - reading_received), width=14)
  43. # print "{0}\t{1:.4f}\t{2:0.4f}\t{3:.4f}".format(
  44. # time.strftime("%Y-%m-%d %H:%M:%S", time_struct),
  45. # reading_received,
  46. # reading_delivered,
  47. # (reading_delivered - reading_received) )
  48. def print_instantdemand(idemand) :
  49. time_stamp = to_epoch_1970(idemand['TimeStamp'])
  50. multiplier = int(idemand['Multiplier'], 16)
  51. divisor = int(idemand['Divisor'], 16)
  52. # demand = twos_comp(int(idemand['Demand'], 16))
  53. demand = int(idemand['Demand'], 16)
  54. if demand > 0x7FFFFFFF:
  55. demand -= 0x100000000
  56. if multiplier == 0 :
  57. multiplier = 1
  58. if divisor == 0 :
  59. divisor = 1
  60. reading = (demand * multiplier) / float (divisor )
  61. print "{0:s} : ".format(time.asctime(time.localtime(time_stamp)))
  62. print "\tDemand = {0:{width}.3f} Kw".format(reading, width=10)
  63. print "\tAmps = {0:{width}.3f}".format( ((reading * 1000) / 240), width=10 )
  64. #
  65. if __name__ == "__main__":
  66. # import __main__
  67. # print(__main__.__file__)
  68. # print("syntax ok")
  69. main()
  70. exit(0)