Advertisement
Guest User

Untitled

a guest
May 7th, 2021
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None
  1. import PyIndi
  2. import time
  3. import subprocess
  4. import csv
  5. import os
  6.  
  7. class IndiClient(PyIndi.BaseClient):
  8. def __init__(self):
  9. super(IndiClient, self).__init__()
  10. def newDevice(self, d):
  11. global dmonitor
  12. # We catch the monitored device
  13. dmonitor=d
  14. print("New device ", d.getDeviceName())
  15. def newProperty(self, p):
  16. global monitored
  17. global cmonitor
  18. # we catch the "CONNECTION" property of the monitored device
  19. if (p.getDeviceName()==monitored and p.getName() == "CONNECTION"):
  20. cmonitor=p.getSwitch()
  21. print("New property ", p.getName(), " for device ", p.getDeviceName())
  22. def removeProperty(self, p):
  23. pass
  24. def newBLOB(self, bp):
  25. pass
  26. def newSwitch(self, svp):
  27. pass
  28. def newNumber(self, nvp):
  29. global newval
  30. global prop
  31. # We only monitor Number properties of the monitored device
  32. prop=nvp
  33. newval=True
  34. def newText(self, tvp):
  35. pass
  36. def newLight(self, lvp):
  37. pass
  38. def newMessage(self, d, m):
  39. pass
  40. def serverConnected(self):
  41. pass
  42. def serverDisconnected(self, code):
  43. pass
  44.  
  45. monitored="Vantage"
  46. dmonitor=None
  47. cmonitor=None
  48.  
  49. indiclient=IndiClient()
  50. indiclient.setServer("localhost",7624)
  51.  
  52. indiclient.watchDevice(monitored)
  53. indiclient.connectServer()
  54.  
  55. while not(cmonitor):
  56. time.sleep(0.05)
  57.  
  58. if not(dmonitor.isConnected()):
  59. cmonitor[0].s=PyIndi.ISS_ON
  60. cmonitor[1].s=PyIndi.ISS_OFF
  61. indiclient.sendNewSwitch(cmonitor)
  62.  
  63. title = '/var/www/html/Weather_Info'
  64.  
  65. i = 0
  66. j = 0
  67. while i < 1:
  68. CPU_Temp = os.popen('cat /sys/class/thermal/thermal_zone0/temp').read()
  69. CPU_Temp = float(CPU_Temp)/1000
  70. WEATH = dmonitor.getNumber("WEATHER_PARAMETERS")
  71. weather = [WEATH[0].value, WEATH[1].value, WEATH[2].value, WEATH[3].value, WEATH[4].value, WEATH[5].value, WEATH[6].value, WEATH[7].value, CPU_Temp]
  72. Time = time.time()
  73.  
  74. with open(title + '.csv', 'a') as csvfile:
  75. filewriter = csv.writer(csvfile, delimiter=',', lineterminator='\n')
  76. filewriter.writerow([weather[0],weather[1],weather[2],weather[3],weather[4],weather[5],weather[6],weather[7],weather[8],Time])
  77. print('Minutes Since Beginning of Data:',j)
  78. j = j + 1
  79. time.sleep(60)
  80.  
Advertisement
RAW Paste Data Copied
Advertisement