Guest User

Untitled

a guest
May 24th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.42 KB | None | 0 0
  1. #!/usr/bin/python3
  2. #---------------------------------------------------------------------
  3. # ___ ___ _ ____
  4. # / _ \/ _ \(_) __/__ __ __
  5. # / , _/ ___/ /\ \/ _ \/ // /
  6. # /_/|_/_/ /_/___/ .__/\_, /
  7. # /_/ /___/
  8. #
  9. # Pool Monitor System
  10. # poollib.py
  11. #
  12. # This is a supporting set of functions that are used
  13. # by the main script (poolmain.py) and the web front-end (poolweb.py).
  14. #
  15. # It serves a status page and allows users to set the
  16. # pump mode and edit the schedule.
  17. #
  18. # Author : Matt Hawkins
  19. # Date : 06/08/2018
  20. #
  21. # Additional details of this project here:
  22. # http://bit.ly/pizeropool
  23. #
  24. # Visit my Raspberry Pi Blog for other awesome content:
  25. # https://www.raspberrypi-spy.co.uk/
  26. #
  27. # Modified by Bo Herrmannsen to control a electrical heating panel
  28. #
  29. #---------------------------------------------------------------------
  30.  
  31. import os
  32. import time
  33. import datetime
  34. import pickle
  35. import requests
  36. import config as c
  37. #import wiringpi
  38. import RPi.GPIO as GPIO
  39. import sys, string
  40. import http.client
  41. import socket
  42.  
  43. # RPi.GPIO numbers
  44.  
  45. relay = 11
  46. boost_switch = 15
  47. internet_led = 13
  48. boost_led = 37
  49.  
  50. GPIO.setmode(GPIO.BOARD) # Use hardware pin numbers, listed above
  51. GPIO.setwarnings(False) # Disregard warnings
  52.  
  53. GPIO.setup(relay, GPIO.OUT) # Sets pin 11 as output
  54. GPIO.setup(boost_switch, GPIO.IN) # Sets pin 15 as input
  55. GPIO.setup(internet_led, GPIO.OUT) # Sets pin 13 as output
  56. GPIO.setup(boost_led, GPIO.OUT) # Sets pin 37 as output
  57.  
  58. # wiringpi numbers
  59.  
  60. #wiringpi.wiringPiSetup()
  61. #wiringpi.pinMode(0, 1) # sets pin 0 to output (GPIO 17, Actual hardware pin number is 11) (Relay)
  62. #wiringpi.pinMode(2, 1) # sets pin 2 to output (GPIO 27, Actual hardware pin number is 13) (Internet connection LED)
  63. #wiringpi.pinMode(25, 1) # sets pin 25 to output (GPIO 26, Actual hardware pin number is 37) (Spare LED)
  64. #wiringpi.pinMode(3, 0) # sets pin 3 to input (GPIO 22, Actual hardware pin number is 15) (latching button)
  65.  
  66. def internet_connected(host='8.8.8.8', port=53):
  67. """
  68. Host: 8.8.8.8 (google-public-dns-a.google.com)
  69. OpenPort: 53/tcp
  70. Service: domain (DNS/TCP)
  71. """
  72. try:
  73. socket.setdefaulttimeout(20)
  74. socket.socket(socket.AF_INET,
  75. socket.SOCK_STREAM).connect((host, port))
  76. return True
  77. except Exception as ex:
  78. print(time.asctime( time.localtime(time.time()) ) + " This error occurred: " + str(ex))
  79.  
  80. return False
  81.  
  82. def uptime():
  83.  
  84. try:
  85. with open('/proc/uptime', 'r') as f:
  86. uptime_seconds = float(f.readline().split()[0])
  87. uptime_string = (((uptime_seconds/60)/60)/24)
  88. print(time.asctime( time.localtime(time.time()) ), end=' ')
  89. print(' Uptime since last reboot: ', end=' ')
  90. print (uptime_string)
  91.  
  92. return uptime_string
  93.  
  94. except Exception as ex:
  95. print(time.asctime( time.localtime(time.time()) ), end=' ')
  96. print(' This error occurred: ' + str(ex))
  97.  
  98. def cpu():
  99.  
  100. try:
  101. print(time.asctime( time.localtime(time.time()) ), end=' ')
  102. print(' Getting CPU Temp')
  103. temp = os.popen("vcgencmd measure_temp").readline()
  104. print(time.asctime( time.localtime(time.time()) ), end=' ')
  105. print(' Got CPU Temp')
  106.  
  107. return (temp.replace("temp=","").replace("'C\n",""))
  108.  
  109. except Exception as ex:
  110. print(time.asctime( time.localtime(time.time()) ), end=' ')
  111. print(' This error occurred: ' + str(ex))
  112.  
  113. def saveStatus(mode,status,booststart):
  114. try:
  115. print(time.asctime( time.localtime(time.time()) ), end=' ')
  116. print(' Saving status file')
  117. pickle.dump( [mode,status,booststart], open( "/home/pi/pool/status.p", "wb" ) )
  118. print(time.asctime( time.localtime(time.time()) ), end=' ')
  119.  
  120. except Exception as ex:
  121. print(time.asctime( time.localtime(time.time()) ), end=' ')
  122. print(' This error occurred: ' + str(ex))
  123.  
  124. def getStatus():
  125. try:
  126. print(time.asctime( time.localtime(time.time()) ), end=' ')
  127. print(' Getting status file')
  128. mode,status,booststart=pickle.load(open( "/home/pi/pool/status.p", "rb" ))
  129. return mode,status,booststart
  130. print(time.asctime( time.localtime(time.time()) ), end=' ')
  131.  
  132. except Exception as ex:
  133. print(time.asctime( time.localtime(time.time()) ), end=' ')
  134. print(' This error occurred: ' + str(ex))
  135.  
  136. def saveSchedule(hours):
  137. try:
  138. print(time.asctime( time.localtime(time.time()) ), end=' ')
  139. print(' Saving schedule file')
  140. pickle.dump( hours, open( "/home/pi/pool/schedule.p", "wb" ) )
  141. print(time.asctime( time.localtime(time.time()) ), end=' ')
  142.  
  143. except Exception as ex:
  144. print(time.asctime( time.localtime(time.time()) ), end=' ')
  145. print(' This error occurred: ' + str(ex))
  146.  
  147. def saveTarget(target):
  148. try:
  149. print(time.asctime( time.localtime(time.time()) ), end=' ')
  150. print(' Saving target file')
  151. pickle.dump( target, open( "/home/pi/pool/target.p", "wb" ) )
  152. print(time.asctime( time.localtime(time.time()) ), end=' ')
  153.  
  154. except Exception as ex:
  155. print(time.asctime( time.localtime(time.time()) ), end=' ')
  156. print(' This error occurred: ' + str(ex))
  157.  
  158. def saveTarget2(target2):
  159. try:
  160. print(time.asctime( time.localtime(time.time()) ), end=' ')
  161. print(' Saving target2 file')
  162. pickle.dump( target2, open( "/home/pi/pool/boost.p", "wb" ) )
  163. print(time.asctime( time.localtime(time.time()) ), end=' ')
  164.  
  165. except Exception as ex:
  166. print(time.asctime( time.localtime(time.time()) ), end=' ')
  167. print(' This error occurred: ' + str(ex))
  168.  
  169. def saveTarget3(target3):
  170. try:
  171. print(time.asctime( time.localtime(time.time()) ), end=' ')
  172. print(' Saving target3 file')
  173. pickle.dump( target3, open( "/home/pi/pool/cpu.p", "wb" ) )
  174. print(time.asctime( time.localtime(time.time()) ), end=' ')
  175.  
  176. except Exception as ex:
  177. print(time.asctime( time.localtime(time.time()) ), end=' ')
  178. print(' This error occurred: ' + str(ex))
  179.  
  180. def saveTarget4(target4):
  181. try:
  182. print(time.asctime( time.localtime(time.time()) ), end=' ')
  183. print(' Saving target4 file')
  184. pickle.dump( target4, open( "/home/pi/pool/night.p", "wb" ) )
  185. print(time.asctime( time.localtime(time.time()) ), end=' ')
  186.  
  187. except Exception as ex:
  188. print(time.asctime( time.localtime(time.time()) ), end=' ')
  189. print(' This error occurred: ' + str(ex))
  190.  
  191. def saveTarget5(target5):
  192. try:
  193. print(time.asctime( time.localtime(time.time()) ), end=' ')
  194. print(' Saving target5 file')
  195. pickle.dump( target5, open( "/home/pi/pool/on.p", "wb" ) )
  196. print(time.asctime( time.localtime(time.time()) ), end=' ')
  197.  
  198. except Exception as ex:
  199. print(time.asctime( time.localtime(time.time()) ), end=' ')
  200. print(' This error occurred: ' + str(ex))
  201.  
  202. def saveTarget6(target6):
  203. try:
  204. print(time.asctime( time.localtime(time.time()) ), end=' ')
  205. print(' Saving target6 file')
  206. pickle.dump( target6, open( "/home/pi/pool/off.p", "wb" ) )
  207. print(time.asctime( time.localtime(time.time()) ), end=' ')
  208.  
  209. except Exception as ex:
  210. print(time.asctime( time.localtime(time.time()) ), end=' ')
  211. print(' This error occurred: ' + str(ex))
  212.  
  213. def getSchedule():
  214. try:
  215. print(time.asctime( time.localtime(time.time()) ), end=' ')
  216. print(' Getting schedule file')
  217. hours=pickle.load(open( "/home/pi/pool/schedule.p", "rb" ))
  218. return hours
  219. print(time.asctime( time.localtime(time.time()) ), end=' ')
  220.  
  221. except Exception as ex:
  222. print(time.asctime( time.localtime(time.time()) ), end=' ')
  223. print(' This error occurred: ' + str(ex))
  224.  
  225. def getTarget():
  226. try:
  227. print(time.asctime( time.localtime(time.time()) ), end=' ')
  228. print(' Getting target file')
  229. target=pickle.load(open( "/home/pi/pool/target.p", "rb" ))
  230. return target
  231. print(time.asctime( time.localtime(time.time()) ), end=' ')
  232.  
  233. except Exception as ex:
  234. print(time.asctime( time.localtime(time.time()) ), end=' ')
  235. print(' This error occurred: ' + str(ex))
  236.  
  237. def getTarget2():
  238. try:
  239. print(time.asctime( time.localtime(time.time()) ), end=' ')
  240. print(' Getting target2 file')
  241. target2=pickle.load(open( "/home/pi/pool/boost.p", "rb" ))
  242. return target2
  243. print(time.asctime( time.localtime(time.time()) ), end=' ')
  244.  
  245. except Exception as ex:
  246. print(time.asctime( time.localtime(time.time()) ), end=' ')
  247. print(' This error occurred: ' + str(ex))
  248.  
  249. def getTarget3():
  250. try:
  251. print(time.asctime( time.localtime(time.time()) ), end=' ')
  252. print(' Getting target3 file')
  253. target3=pickle.load(open( "/home/pi/pool/cpu.p", "rb" ))
  254. return target3
  255. print(time.asctime( time.localtime(time.time()) ), end=' ')
  256.  
  257. except Exception as ex:
  258. print(time.asctime( time.localtime(time.time()) ), end=' ')
  259. print(' This error occurred: ' + str(ex))
  260.  
  261. def getTarget4():
  262. try:
  263. print(time.asctime( time.localtime(time.time()) ), end=' ')
  264. print(' Getting target4 file')
  265. target4=pickle.load(open( "/home/pi/pool/night.p", "rb" ))
  266. return target4
  267. print(time.asctime( time.localtime(time.time()) ), end=' ')
  268.  
  269. except Exception as ex:
  270. print(time.asctime( time.localtime(time.time()) ), end=' ')
  271. print(' This error occurred: ' + str(ex))
  272.  
  273. def getTarget5():
  274. try:
  275. print(time.asctime( time.localtime(time.time()) ), end=' ')
  276. print(' Getting target5 file')
  277. target5=pickle.load(open( "/home/pi/pool/on.p", "rb" ))
  278. return target5
  279. print(time.asctime( time.localtime(time.time()) ), end=' ')
  280.  
  281. except Exception as ex:
  282. print(time.asctime( time.localtime(time.time()) ), end=' ')
  283. print(' This error occurred: ' + str(ex))
  284.  
  285. def getTarget6():
  286. try:
  287. print(time.asctime( time.localtime(time.time()) ), end=' ')
  288. print(' Getting target6 file')
  289. target6=pickle.load(open( "/home/pi/pool/off.p", "rb" ))
  290. return target6
  291. print(time.asctime( time.localtime(time.time()) ), end=' ')
  292.  
  293. except Exception as ex:
  294. print(time.asctime( time.localtime(time.time()) ), end=' ')
  295. print(' This error occurred: ' + str(ex))
  296.  
  297. def checkStatus():
  298. try:
  299. print(time.asctime( time.localtime(time.time()) ), end=' ')
  300. print(' Checking status file')
  301.  
  302. if not os.path.isfile('/home/pi/pool/status.p'):
  303. print("No status.p file found")
  304. saveStatus('off',False,0)
  305. else:
  306. print("Existing status.p file found")
  307.  
  308. except Exception as ex:
  309. print(time.asctime( time.localtime(time.time()) ), end=' ')
  310. print(' This error occurred: ' + str(ex))
  311.  
  312. def checkSchedule():
  313. try:
  314. print(time.asctime( time.localtime(time.time()) ), end=' ')
  315. print(' Checking schedule file')
  316.  
  317. if not os.path.isfile('/home/pi/pool/schedule.p'):
  318. print("No schedule.p file found")
  319. saveSchedule(['7','8'])
  320. else:
  321. print("Existing schedule.p file found")
  322.  
  323. except Exception as ex:
  324. print(time.asctime( time.localtime(time.time()) ), end=' ')
  325. print(' This error occurred: ' + str(ex))
  326.  
  327. def checkTarget():
  328. try:
  329. print(time.asctime( time.localtime(time.time()) ), end=' ')
  330. print(' Checking target file')
  331.  
  332. if not os.path.isfile('/home/pi/pool/target.p'):
  333. print("No target.p file found")
  334. saveTarget(['20'])
  335. else:
  336. print("Existing target.p file found")
  337.  
  338. except Exception as ex:
  339. print(time.asctime( time.localtime(time.time()) ), end=' ')
  340. print(' This error occurred: ' + str(ex))
  341.  
  342. def checkTarget2():
  343. try:
  344. print(time.asctime( time.localtime(time.time()) ), end=' ')
  345. print(' Checking target2 file')
  346.  
  347. if not os.path.isfile('/home/pi/pool/boost.p'):
  348. print("No boost.p file found")
  349. saveTarget2(['25'])
  350. else:
  351. print("Existing boost.p file found")
  352.  
  353. except Exception as ex:
  354. print(time.asctime( time.localtime(time.time()) ), end=' ')
  355. print(' This error occurred: ' + str(ex))
  356.  
  357. def checkTarget3():
  358. try:
  359. print(time.asctime( time.localtime(time.time()) ), end=' ')
  360. print(' Checking target3 file')
  361.  
  362. if not os.path.isfile('/home/pi/pool/cpu.p'):
  363. print("No cpu.p file found")
  364. saveTarget3(['65'])
  365. else:
  366. print("Existing cpu.p file found")
  367.  
  368. except Exception as ex:
  369. print(time.asctime( time.localtime(time.time()) ), end=' ')
  370. print(' This error occurred: ' + str(ex))
  371.  
  372. def checkTarget4():
  373. try:
  374. print(time.asctime( time.localtime(time.time()) ), end=' ')
  375. print(' Checking target4 file')
  376.  
  377. if not os.path.isfile('/home/pi/pool/night.p'):
  378. print("No night.p file found")
  379. saveTarget4(['15'])
  380. else:
  381. print("Existing night.p file found")
  382.  
  383. except Exception as ex:
  384. print(time.asctime( time.localtime(time.time()) ), end=' ')
  385. print(' This error occurred: ' + str(ex))
  386.  
  387. def checkTarget5():
  388. try:
  389. print(time.asctime( time.localtime(time.time()) ), end=' ')
  390. print(' Checking target5 file')
  391.  
  392. if not os.path.isfile('/home/pi/pool/on.p'):
  393. print("No on.p file found")
  394. saveTarget5(['100'])
  395. else:
  396. print("Existing on.p file found")
  397.  
  398. except Exception as ex:
  399. print(time.asctime( time.localtime(time.time()) ), end=' ')
  400. print(' This error occurred: ' + str(ex))
  401.  
  402. def checkTarget6():
  403. try:
  404. print(time.asctime( time.localtime(time.time()) ), end=' ')
  405. print(' Checking target6 file')
  406.  
  407. if not os.path.isfile('/home/pi/pool/off.p'):
  408. print("No off.p file found")
  409. saveTarget6(['0'])
  410. else:
  411. print("Existing off.p file found")
  412.  
  413. except Exception as ex:
  414. print(time.asctime( time.localtime(time.time()) ), end=' ')
  415. print(' This error occurred: ' + str(ex))
  416.  
  417. def readTemps(sensorID,tempunit='C'):
  418. try:
  419. print(time.asctime( time.localtime(time.time()) ), end=' ')
  420. print(' Reading Temperatures')
  421. read1=getTemp(sensorID[0])/float(1000)
  422. read2 = getTemp(sensorID[1]) / float(1000)
  423.  
  424. if tempunit.upper()=='F':
  425. print(time.asctime( time.localtime(time.time()) ), end=' ')
  426. print(' Converting to Fahrenheit')
  427.  
  428. # Convert to Fahrenheit if unit is F
  429. read1=(read1*1.8)+32
  430. read2=(read2*1.8)+32
  431.  
  432. t1=read1
  433. t2=read2
  434.  
  435. return t1,t2
  436. print(time.asctime( time.localtime(time.time()) ), end=' ')
  437. print(' Got Temperatures')
  438.  
  439. except Exception as ex:
  440. print(time.asctime( time.localtime(time.time()) ), end=' ')
  441. print(' This error occurred: ' + str(ex))
  442.  
  443. def getTemp(id):
  444. try:
  445. print(time.asctime( time.localtime(time.time()) ), end=' ')
  446. print(' Getting Temperature')
  447. mytemp = ''
  448. filename = 'w1_slave'
  449. f = open('/sys/bus/w1/devices/' + id + '/' + filename, 'r')
  450. line = f.readline() # read 1st line
  451. print(time.asctime( time.localtime(time.time()) ), end=' ')
  452. print(' Got Temperature - Now checking crc')
  453. crc = line.rsplit(' ',1)
  454. crc = crc[1].replace('\n', '')
  455. if crc=='YES':
  456. print(time.asctime( time.localtime(time.time()) ), end=' ')
  457. print(' Crc ok')
  458. line = f.readline() # read 2nd line
  459. mytemp = line.rsplit('t=',1)
  460. else:
  461. print(time.asctime( time.localtime(time.time()) ), end=' ')
  462. print(' Crc failed')
  463. mytemp = 99999
  464. f.close()
  465.  
  466. return int(mytemp[1])
  467. print(time.asctime( time.localtime(time.time()) ), end=' ')
  468. print(' Got Temperature')
  469.  
  470.  
  471. except Exception as ex:
  472. print(time.asctime( time.localtime(time.time()) ), end=' ')
  473. print(' This error occurred: ' + str(ex))
  474. return 99999
  475.  
  476. def getSensorIDs():
  477. id1=c.id1
  478. id2=c.id2
  479.  
  480. sensorIDs=[]
  481.  
  482. sensorIDs.append(id1)
  483. sensorIDs.append(id2)
  484.  
  485. return sensorIDs
  486.  
  487. def pumpUpdate(mode):
  488. global status
  489. prevPumpMode,prevPumpStatus,booststart=getStatus()
  490. hours=getSchedule()
  491. t1,t2=readTemps(getSensorIDs(),c.TEMPUNIT)
  492. cpu1=cpu()
  493. cpu1=float(cpu1)
  494. target=getTarget()
  495. for i in range(0, len(target)):
  496. target_new=(target[i])
  497. target_new=float(target_new)
  498. target2=getTarget2()
  499. for i in range(0, len(target2)):
  500. target2_new=(target2[i])
  501. target2_new=float(target2_new)
  502. target3=getTarget3()
  503. for i in range(0, len(target3)):
  504. target3_new=(target3[i])
  505. target3_new=float(target3_new)
  506. target4=getTarget4()
  507. for i in range(0, len(target4)):
  508. target4_new=(target4[i])
  509. target4_new=float(target4_new)
  510. target5=getTarget5()
  511. for i in range(0, len(target5)):
  512. target5_new=(target5[i])
  513. target5_new=float(target5_new)
  514. target6=getTarget6()
  515. for i in range(0, len(target6)):
  516. target6_new=(target6[i])
  517. target6_new=float(target6_new)
  518.  
  519. if internet_connected():
  520. print(time.asctime( time.localtime(time.time()) ), end=' '),
  521. print (" We have an internet connection? " + str(internet_connected()))
  522. # wiringpi.digitalWrite(2, 0) # sets port 2 to OFF
  523. GPIO.output(internet_led, GPIO.LOW) # Turns internet led to OFF
  524. else:
  525. print (" Check internet Connection")
  526. # wiringpi.digitalWrite(2, 1) # sets port 2 to ON
  527. GPIO.output(internet_led, GPIO.HIGH) # Turns internet led to ON
  528.  
  529. if mode=='on':
  530. if t1 < target5_new and cpu1 < target3_new:
  531. # wiringpi.digitalWrite(0, 1) # sets port 0 to ON
  532. GPIO.output(relay, GPIO.HIGH) # Turns relay ON
  533. status=True
  534. print ("Current Temperature: ",t1)
  535. print ("CPU Temperature: ",cpu1)
  536. print ("Target: ",target5_new)
  537. print ("CPU Cap: ",target3_new)
  538. print ("Current heat status : ",status)
  539. print ("Current relay mode : ",mode)
  540. else:
  541. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  542. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  543. status=False
  544. print ("Current Temperature: ",t1)
  545. print ("CPU Temperature: ",cpu1)
  546. print ("Target: ",target5_new)
  547. print ("CPU Cap: ",target3_new)
  548. print ("Current heat status : ",status)
  549. print ("Current relay mode : ",mode)
  550. elif mode=='off':
  551. if t1 > target6_new and cpu1 < target3_new:
  552. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  553. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  554. status=False
  555. print ("Current Temperature: ",t1)
  556. print ("CPU Temperature: ",cpu1)
  557. print ("Target: ",target6_new)
  558. print ("CPU Cap: ",target3_new)
  559. print ("Current heat status : ",status)
  560. print ("Current relay mode : ",mode)
  561. if t1 < target6_new and cpu1 < target3_new:
  562. # wiringpi.digitalWrite(0, 1) # sets port 0 to ON
  563. GPIO.output(relay, GPIO.HIGH) # Turns relay ON
  564. status=True
  565. print ("Current Temperature: ",t1)
  566. print ("CPU Temperature: ",cpu1)
  567. print ("Target: ",target6_new)
  568. print ("CPU Cap: ",target3_new)
  569. print ("Current heat status : ",status)
  570. print ("Current relay mode : ",mode)
  571. else:
  572. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  573. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  574. status=False
  575. print ("Current Temperature: ",t1)
  576. print ("CPU Temperature: ",cpu1)
  577. print ("Target: ",target5_new)
  578. print ("CPU Cap: ",target3_new)
  579. print ("Current heat status : ",status)
  580. print ("Current relay mode : ",mode)
  581. elif mode=='boost':
  582. # wiringpi.digitalWrite(25, 1) # sets port 25 to ON (spare LED)
  583. GPIO.output(boost_led, GPIO.HIGH) # Turns boost led ON
  584. if prevPumpMode=='boost' and time.time()-booststart>900: #900 is the boost time in seconds
  585. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  586. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  587. status=False
  588. mode='auto'
  589. # wiringpi.digitalWrite(25, 0) # sets port 25 to OFF (spare LED)
  590. GPIO.output(boost_led, GPIO.LOW) # Turns boost led OFF
  591. else:
  592. if t1 < target2_new and cpu1 < target3_new:
  593. # wiringpi.digitalWrite(0, 1) # sets port 0 to ON
  594. GPIO.output(relay, GPIO.HIGH) # Turns relay ON
  595. status=True
  596. print ("Current Temperature: ",t1)
  597. print ("CPU Temperature: ",cpu1)
  598. print ("Target(boost): ",target2_new)
  599. print ("CPU Cap: ",target3_new)
  600. print ("Current heat status : ",status)
  601. print ("Current relay mode : ",mode)
  602. else:
  603. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  604. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  605. status=False
  606. print ("Current Temperature: ",t1)
  607. print ("CPU Temperature: ",cpu1)
  608. print ("Target(boost): ",target2_new)
  609. print ("CPU Cap: ",target3_new)
  610. print ("Current heat status : ",status)
  611. print ("Current relay mode : ",mode)
  612. elif mode=='auto':
  613. now = datetime.datetime.now()
  614. if str(now.hour) in hours and t1 < target_new and cpu1 < target3_new:
  615. # wiringpi.digitalWrite(0, 1) # sets port 0 to ON
  616. GPIO.output(relay, GPIO.HIGH) # Turns relay ON
  617. status=True
  618. print ("Current Temperature: ",t1)
  619. print ("CPU Temperature: ",cpu1)
  620. print ("Target (Day): ",target_new)
  621. print ("CPU Cap: ",target3_new)
  622. print ("Current heat status : ",status)
  623. print ("Current relay mode : ",mode)
  624. if str(now.hour) in hours and t1 > target_new and cpu1 < target3_new:
  625. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  626. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  627. status=False
  628. print ("Current Temperature: ",t1)
  629. print ("CPU Temperature: ",cpu1)
  630. print ("Target (Day): ",target_new)
  631. print ("CPU Cap: ",target3_new)
  632. print ("Current heat status : ",status)
  633. print ("Current relay mode : ",mode)
  634. if str(now.hour) in hours and t1 < target_new and cpu1 > target3_new:
  635. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  636. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  637. status=False
  638. print ("Current Temperature: ",t1)
  639. print ("CPU Temperature: ",cpu1)
  640. print ("Target (Day): ",target_new)
  641. print ("CPU Cap: ",target3_new)
  642. print ("Current heat status : ",status)
  643. print ("Current relay mode : ",mode)
  644. if str(now.hour) in hours and t1 > target_new and cpu1 > target3_new:
  645. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  646. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  647. status=False
  648. print ("Current Temperature: ",t1)
  649. print ("CPU Temperature: ",cpu1)
  650. print ("Target (Day): ",target_new)
  651. print ("CPU Cap: ",target3_new)
  652. print ("Current heat status : ",status)
  653. print ("Current relay mode : ",mode)
  654.  
  655. if str(now.hour) not in hours and t1 < target4_new and cpu1 < target3_new:
  656. # wiringpi.digitalWrite(0, 1) # sets port 0 to ON
  657. GPIO.output(relay, GPIO.HIGH) # Turns relay ON
  658. status=True
  659. print ("Current Temperature: ",t1)
  660. print ("CPU Temperature: ",cpu1)
  661. print ("Target (Night): ",target4_new)
  662. print ("CPU Cap: ",target3_new)
  663. print ("Current heat status : ",status)
  664. print ("Current relay mode : ",mode)
  665. if str(now.hour) not in hours and t1 > target4_new and cpu1 < target3_new:
  666. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  667. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  668. status=False
  669. print ("Current Temperature: ",t1)
  670. print ("CPU Temperature: ",cpu1)
  671. print ("Target (Night): ",target4_new)
  672. print ("CPU Cap: ",target3_new)
  673. print ("Current heat status : ",status)
  674. print ("Current relay mode : ",mode)
  675. if str(now.hour) not in hours and t1 < target4_new and cpu1 > target3_new:
  676. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  677. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  678. status=False
  679. print ("Current Temperature: ",t1)
  680. print ("CPU Temperature: ",cpu1)
  681. print ("Target (Night): ",target4_new)
  682. print ("CPU Cap: ",target3_new)
  683. print ("Current heat status : ",status)
  684. print ("Current relay mode : ",mode)
  685. if str(now.hour) not in hours and t1 > target4_new and cpu1 > target3_new:
  686. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  687. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  688. status=False
  689. print ("Current Temperature: ",t1)
  690. print ("CPU Temperature: ",cpu1)
  691. print ("Target (Night): ",target4_new)
  692. print ("CPU Cap: ",target3_new)
  693. print ("Current heat status : ",status)
  694. print ("Current relay mode : ",mode)
  695.  
  696. else:
  697. # wiringpi.digitalWrite(0, 0) # sets port 0 to OFF
  698. GPIO.output(relay, GPIO.LOW) # Turns relay OFF
  699. status=False
  700.  
  701. # If there has been a change in state save status
  702. if status!=prevPumpStatus or mode!=prevPumpMode:
  703. if prevPumpMode!='boost' and mode=='boost':
  704. booststart=time.time()
  705. print("BOST JUST STARTED")
  706. saveStatus(mode,status,booststart)
  707. print("Change in status so saving")
  708. else:
  709. print("No change in status so don't save")
  710.  
  711. return status
  712.  
  713. def target_new():
  714.  
  715. target_x=getTarget2()
  716. for i in range(0, len(target_x)):
  717. target_new=(target_x[i])
  718.  
  719. return target_new
  720.  
  721. def target_new1():
  722.  
  723. target_x=getTarget()
  724. for i in range(0, len(target_x)):
  725. target_new1=(target_x[i])
  726.  
  727. return target_new1
  728.  
  729. def target_new2():
  730.  
  731. target_x=getTarget4()
  732. for i in range(0, len(target_x)):
  733. target_new2=(target_x[i])
  734.  
  735. return target_new2
  736.  
  737. def target_new3():
  738.  
  739. target_x=getTarget6()
  740. for i in range(0, len(target_x)):
  741. target_new3=(target_x[i])
  742.  
  743. return target_new3
  744.  
  745. def target_new4():
  746.  
  747. target_x=getTarget5()
  748. for i in range(0, len(target_x)):
  749. target_new4=(target_x[i])
  750.  
  751. return target_new4
  752.  
Add Comment
Please, Sign In to add comment