[python] Embedded clima codes

This commit is contained in:
giuliof 2019-07-02 09:41:06 +02:00
parent d7fa1335fb
commit e6a58d40e4
2 changed files with 32 additions and 12 deletions

View File

@ -1,9 +1,5 @@
#!/usr/bin/python3
import serial
#import _thread
#import datetime
#import sys
#import signal
import math
from time import sleep
@ -64,6 +60,7 @@ class DomoticGateway:
try:
self.ser = serial.Serial(
"/dev/ttyUSB0", 115200, timeout=0.5, exclusive=True)
sleep(0.1)
except:
sleep(1)
continue
@ -76,8 +73,8 @@ class DomoticGateway:
def __del__(self):
self.ser.close()
def sendCommand(self, cmd):
self.ser.write(bytearray(packet_builder(cmd, [0x00])))
def sendCommand(self, cmd, args = [0x00]):
self.ser.write(bytearray(packet_builder(cmd, args)))
def receiveData(self):
# Receive size

View File

@ -1,12 +1,16 @@
import subprocess
import DomoticGateway as dg
from time import sleep
import sys
# TMP is in different database, this is stupid: merge all in a single database
HDD_LABELS = ('sda','sdb','sdc','sdd')
CORE_LABELS = ('core0', 'core1', 'core2', 'core3')
TMP_LABELS_AMB = ('tmp')
# Remote codes
CLIMA_CODES = {'freddo' : 0x4dc0bf, 'caldo' : 0x4d4033, 'spegni' : 0x4d841f}
# Read hard disk temperatures and put in array
def getDiskTmp():
tmp = {}
@ -30,8 +34,6 @@ def getCoreTmp():
def getRoomTmp():
dgh = dg.DomoticGateway()
# wait a bit, Arduino probably resets. An old-style RS232 would have been better
sleep(1)
dgh.sendCommand('CMD_TEMP')
try:
tmp = dgh.receiveData()
@ -40,10 +42,31 @@ def getRoomTmp():
return {TMP_LABELS_AMB : tmp}
def setClimaStatus(status):
dgh = dg.DomoticGateway()
try:
status = CLIMA_CODES[status]
except:
print ("Invalid clima option")
exit(-1)
# Clima packetis 4 bytes (uint32_t)
payload = []
payload.append(status & 0xff)
status >>= 8
payload.append(status & 0xff)
status >>= 8
payload.append(status & 0xff)
payload.append(0x00)
dgh.sendCommand('CMD_CLIMA', payload)
def main():
print (getDiskTmp())
print (getCoreTmp())
print (getRoomTmp())
if (len(sys.argv) != 3):
print (getDiskTmp())
print (getCoreTmp())
print (getRoomTmp())
else:
if (sys.argv[1] == 'clima'):
setClimaStatus(sys.argv[2])
# push into database
# read db to plot
@ -51,4 +74,4 @@ def main():
if __name__ == "__main__":
main()
main()