Hi,
is it the « OpenTherm Gateway Arduino shield » compatible with your code:
#!/usr/bin/env python
import time
import serial
import sys
import os.path
import logging
from logging.handlers import RotatingFileHandler
# Constants
StatusCommand = "PS=1" + chr(13) # Status Command on Serial
ReadCache = 90 # Time in sec for cache on opentherm bus (only for reading values, no cache for writing)
cachefile = "/tmp/opentherm.values"
logfile ="/home/pi/opentherm.log"
MaxLogFileSize = 5*1024*1024 # max size for log file in Bytes x*1024*1024 ==> x MB max
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
file_handler = RotatingFileHandler(logfile, 'a', MaxLogFileSize, 1)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
#Parameters
Operation = sys.argv[1].lower() # Read or write (r or R or w or W)
if Operation =='r':
MsgID=sys.argv[2] # MsgID concerned
logger.info('Reading Requested on MsgID ' + MsgID)
#Dictionnaries
equivalence={} # MsgID requested to Array position
equivalence['0']=0 # Status Full field
equivalence['1']=1 # Control setpoint
equivalence['6']=2 # Remote parameter flags
equivalence['14']=3 # Maximum relative modulation level
equivalence['15']=4 # Boiler capacity and modulation limits
equivalence['16']=5 # Room Setpoint
equivalence['17']=6 # Relative modulation level
equivalence['18']=7 # CH water pressure
equivalence['24']=8 # Room temperature
equivalence['25']=9 # Boiler water temperature
equivalence['26']=10 # DHW temperature
equivalence['27']=11 # Outside temperature
equivalence['28']=12 # Return water temperature
equivalence['48']=13 # DHW setpoint boundaries
equivalence['49']=14 # Max CH setpoint boundaries
equivalence['56']=15 # DHW setpoint
equivalence['57']=16 # Max CH water setpoint
equivalence['116']=17 # Burner starts
equivalence['117']=18 # CH pump starts
equivalence['118']=19 # DHW pump/valve starts
equivalence['119']=20 # DHW burner starts
equivalence['120']=21 # Burner operation hours
equivalence['121']=22 # CH pump operation hours
equivalence['122']=23 # DHW pump/valve operation hours
equivalence['123']=24 # DHW burner operation hours
##### #Read from Opentherm Bus or from file depending cache value
if (not os.path.exists(cachefile)) or int(time.time() - os.path.getctime(cachefile)) > ReadCache:
logger.info('Reading from Bus, cache too old')
# Open serial port
serialport = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
serialport.write(StatusCommand) # Send command
ACK = serialport.readline() # Get Aknowledge
logger.info('Acknowledge on command ' + ACK.replace("\n",""))
StatusValueRead = serialport.readline() # Get all values
file = open(cachefile,"w")
file.write(StatusValueRead)
file.close()
else:
logger.info('Using cache file')
file = open(cachefile,"r")
StatusValueRead = file.read()
file.close()
values=StatusValueRead.split(",") # Store values in an Array
##### Send result from read
try:
if MsgID[0]=='L':
answer = values[equivalence[MsgID[1:]]].split('/')[0]
print answer
logger.info('Answer sent (1st Byte) : ' + answer)
elif MsgID[0]=='H':
answer = values[equivalence[MsgID[1:]]].split('/')[1]
print answer
logger.info('Answer sent (2nd Byte) : ' + answer)
elif MsgID=='ALL' or MsgID=='all':
answer = StatusValueRead
print answer
logger.info('ALL: Raw Answer sent : ' + answer)
else:
answer = values[equivalence[MsgID]]
print answer
logger.info('Answer sent : ' + answer)
except: # If MsgID is not valid, answer with Error with '-1'
print '-1'
logger.warning('MsgID not valid, "-1" Error code Sent')
elif Operation =='w':
Command=sys.argv[2] + chr(13)# Command to send
logger.info('Write Requested with command ' + Command)
# Open serial port
serialport = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
serialport.write(Command) # Send command
ACK = serialport.readline() # Get Aknowledge
print ACK
logger.info('Acknowledge on command ' + ACK.replace("\n",""))
else:
print -1
logger.error('Unknown Command : ' + Operation)
?