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.
 
 

117 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. import json
  13. last_delivered = 0
  14. debug = 0
  15. def main() :
  16. eg = Eagle( debug=debug , addr="10.1.1.39")
  17. # timeout=45,
  18. # print "\nlist_devices :"
  19. # r = eg.list_devices()
  20. # print "pprint 2"
  21. # pprint(r)
  22. print "\nget_device_data :"
  23. r = eg.get_device_data()
  24. print
  25. # pprint(r['InstantaneousDemand'])
  26. print_instantdemand( r['InstantaneousDemand'])
  27. print
  28. # pprint(r['CurrentSummation'])
  29. print_currentsummation(r['CurrentSummation'])
  30. print
  31. exit(0)
  32. def print_currentsummation(cs) :
  33. multiplier=int(cs['Multiplier'], 16)
  34. divisor=int(cs['Divisor'], 16)
  35. delivered=int(cs['SummationDelivered'], 16)
  36. received=int(cs['SummationReceived'], 16)
  37. if multiplier == 0 :
  38. multiplier=1
  39. if divisor == 0 :
  40. divisor=1
  41. reading_received = received * multiplier / float (divisor )
  42. reading_delivered = delivered * multiplier / float (divisor )
  43. time_stamp = to_epoch_1970(cs['TimeStamp'])
  44. print time.asctime(time.localtime(time_stamp)), " : "
  45. print "\tReceived=", reading_received, "Kw"
  46. print "\tDelivered=", reading_delivered, "Kw"
  47. print "\t\t", (reading_delivered - reading_received)
  48. # print "{0}\t{1:.4f}\t{2:0.4f}\t{3:.4f}".format(
  49. # time.strftime("%Y-%m-%d %H:%M:%S", time_struct),
  50. # reading_received,
  51. # reading_delivered,
  52. # (reading_delivered - reading_received) )
  53. def print_instantdemand(idemand) :
  54. time_stamp = to_epoch_1970(idemand['TimeStamp'])
  55. multiplier=int(idemand['Multiplier'], 16)
  56. divisor=int(idemand['Divisor'], 16)
  57. demand=int(idemand['Demand'], 16)
  58. # print "Multiplier=", multiplier, "Divisor=", divisor, "Demand=", demand
  59. if multiplier == 0 :
  60. multiplier=1
  61. if divisor == 0 :
  62. divisor=1
  63. reading = demand * multiplier / float (divisor )
  64. print time.asctime(time.localtime(time_stamp)), " : "
  65. print "\tDemand=", reading, "Kw"
  66. print "\tAmps={:.3f}".format( ((reading * 1000) / 240) )
  67. def print_reading(eg, rd) :
  68. for dat in rd['Reading'] :
  69. the_time = time.asctime(time.localtime( to_epoch_1970(dat['TimeStamp']) ) )
  70. print the_time, "Type=", dat['Type'], "Value=", dat['Value']
  71. #
  72. if __name__ == "__main__":
  73. # import __main__
  74. # print(__main__.__file__)
  75. # print("syntax ok")
  76. main()
  77. exit(0)