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.
 
 

126 lines
2.5 KiB

  1. #!/usr/bin/env python
  2. """
  3. based on TalkToEagle.py
  4. """
  5. import socket
  6. import sys
  7. import time
  8. import xml.etree.ElementTree as ET
  9. my_macid = "0xd8d5b90000001296"
  10. # Enter your Eagle's IP below
  11. Eagle_IP = "10.1.1.39"
  12. def print_summ(cs) :
  13. # global last_delivered
  14. # time_stamp = eg.to_epoch_1970(cs['TimeStamp'])
  15. _delivered = cs.find('SummationDelivered').text
  16. _received = cs.find('SummationReceived').text
  17. _multiplier = cs.find('Multiplier').text
  18. _divisor = cs.find('Divisor').text
  19. # print "Multiplier=", _multiplier, "Divisor=", _divisor, "Delivered=", _delivered, "Received=", _received
  20. multiplier=int(_multiplier, 16)
  21. divisor=int(_divisor, 16)
  22. delivered=int(_delivered, 16)
  23. received=int(_received, 16)
  24. time_stamp = 946684800 + int(cs.find('TimeStamp').text, 16)
  25. # print "Multiplier=", multiplier, "Divisor=", divisor, "Delivered=", delivered, "Received=", received, "TimeStamp", time_stamp
  26. if multiplier == 0 :
  27. multiplier=1
  28. if divisor == 0 :
  29. divisor=1
  30. reading_received = received * multiplier / float (divisor )
  31. reading_delivered = delivered * multiplier / float (divisor )
  32. #reading_delta = (reading_delivered - last_delivered)
  33. #last_delivered = reading_delivered
  34. print time.asctime(time.localtime(time_stamp)), " : ", reading_received, "\t", reading_delivered
  35. def print_reading(eg, rd) :
  36. for dat in rd['Reading'] :
  37. time_stamp = time.asctime(time.localtime( to_epoch_1970(dat['TimeStamp']) ) )
  38. ## list_devices
  39. s = socket.create_connection( (Eagle_IP, 5002), 10)
  40. print s
  41. time.sleep(1)
  42. sendstr = "<LocalCommand>\n<Name>list_devices</Name>\n</LocalCommand>\n"
  43. s.sendall(sendstr)
  44. print
  45. print "sending to Eagle: \n\r"
  46. print sendstr
  47. print
  48. time.sleep(1)
  49. print "Eagle response: \n\r"
  50. while 1:
  51. buf = s.recv(1000)
  52. if not buf:
  53. break
  54. sys.stdout.write(buf)
  55. s.close()
  56. ## get_history_data
  57. s = socket.create_connection( (Eagle_IP, 5002), 10)
  58. print s
  59. time.sleep(1)
  60. sendstr = "<LocalCommand>\n<Name>get_history_data</Name>\n<MacId>{0}</MacId>\n<StartTime>0x00000000</StartTime>\n</LocalCommand>\n".format(my_macid)
  61. s.sendall(sendstr)
  62. print
  63. print "sending to Eagle: \n\r"
  64. print sendstr
  65. print
  66. time.sleep(1)
  67. print "Eagle response: \n\r"
  68. j=0
  69. buf_list = []
  70. while 1:
  71. buf = s.recv(1000)
  72. if not buf:
  73. break
  74. buf_list.append(buf)
  75. #sys.stdout.write(buf)
  76. j = j + 1
  77. result_xml = ''.join(buf_list)
  78. print result_xml
  79. etree = ET.fromstring(result_xml)
  80. for cs in etree.iter('CurrentSummation'):
  81. print_summ(cs)
  82. print "j =", j
  83. s.close()
  84. #main()
  85. exit(0)