]> git.frykholm.com Git - heatpump.git/blobdiff - heatpump.py
Added some monitoring
[heatpump.git] / heatpump.py
index d715d07c8b09dcdeb398bc12982c2b8a5de96e7f..b6187195e8273bad41ecefd4e8929344f2b1750a 100644 (file)
@@ -1,7 +1,11 @@
 import piplates.DAQCplate as DAQC
 import time
 from decimal import Decimal
-DAQC.setDOUTbit(0,0) 
+import os
+import paho.mqtt.client as mqtt #import the client1
+from prometheus_client import start_http_server, Summary, Gauge
+
+#DAQC.setDOUTbit(0,0) 
 #thermistor reading function
 def compressor(state=None):
     if state==None:
@@ -12,7 +16,7 @@ def compressor(state=None):
         DAQC.clrDOUTbit(0,0) 
 
 def temp_get(volts,supply_voltage=5):
-    divider_resistor=10000
+    divider_resistor=1500
     ohms = Decimal(divider_resistor*supply_voltage/volts-divider_resistor) #calculate the ohms of the thermisttor
     #IVT oem NTC
     a = Decimal(1.298022762e-3)
@@ -24,18 +28,42 @@ def temp_get(volts,supply_voltage=5):
     tempc = temp - Decimal(273.15) #K to C
     return tempc
 
+def log(fp, data):
+    print(*data,sep=',', file=fp)
+    fp.flush()
+
+fp = open("/var/tmp/heatpump.csv","w+")
+start_http_server(8000)
+running_g = Gauge('heatpump_running', 'Is the compressor running?')
+top_g = Gauge('heatpump_toptemp', 'Temperature at top of tank.')
+return_g = Gauge('heatpump_returntemp', 'Temperature at inlet sensor.')
+gas_g = Gauge('heatpump_hottemp', 'Temperature at Hot Gas side sensor.')
 while(True):
     vv_retur=temp_get(DAQC.getADC(0,0),DAQC.getADC(0,8))
+    vv_top=temp_get(DAQC.getADC(0,2),DAQC.getADC(0,8))
     hetgas=temp_get(DAQC.getADC(0,1),DAQC.getADC(0,8))
     print("VV retur:",vv_retur)
+    print("VV top:",vv_top)
     print("Hetgas:",hetgas)
     print("Kompressor:",compressor())
-    if vv_retur < 35:
+    log(fp, [vv_retur,vv_top,hetgas,str(compressor()[0])])
+    broker_address="monitor.tranquillity.se" 
+    client = mqtt.Client("P1") #create new instance
+    client.connect(broker_address) #connect to broker
+    client.publish("heatpump/running",str(compressor()[0]), retain=True)#publish
+    client.publish("heatpump/toptemp",str(vv_top), retain=True)#publish
+    client.publish("heatpump/returntemp",str(vv_retur), retain=True)#publish
+    client.publish("heatpump/hottemp",str(hetgas), retain=True)#publish
+    running_g.set(compressor()[0])
+    top_g.set(vv_top)
+    return_g.set(vv_retur)
+    gas_g.set(hetgas)
+    if vv_top < 47:
         compressor(True)
-        print("Returtemp under 35. Startar kompressor")
-    if vv_retur > 45:
+        print("Toptemp under 47. Startar kompressor")
+    if vv_top > 51:
         compressor(False)
-        print("Returtemp över 45. Stänger av kompressor")
+        print("Toptemp över 51. Stänger av kompressor")
 #    import pdb;pdb.set_trace()
     time.sleep(1)