|  | @@ -18,7 +18,7 @@ import os
 | 
	
		
			
				|  |  |  import re
 | 
	
		
			
				|  |  |  import configparser
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -version = 0.3
 | 
	
		
			
				|  |  | +version = 0.4
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # Change working dir to the same dir as this script
 | 
	
		
			
				|  |  |  os.chdir(sys.path[0])
 | 
	
	
		
			
				|  | @@ -36,7 +36,7 @@ devdata = {}
 | 
	
		
			
				|  |  |  RXcodesToDevFunction_IT = {}
 | 
	
		
			
				|  |  |  RXcodesToDevFunction_RAW = {}
 | 
	
		
			
				|  |  |  InTopicsToDevIds = {}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +lastDataReceiveTime = time.time()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # config vars
 | 
	
		
			
				|  |  |  deviceConfigFile = config['main'].get('devices_config_yml')
 | 
	
	
		
			
				|  | @@ -580,7 +580,11 @@ def encodeInterTechnoRX(itname, cmd):
 | 
	
		
			
				|  |  |          if debug: log_write("    unknown or invalid IT code '" + rx_code + "'")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def cul_received(payload, source_cul):
 | 
	
		
			
				|  |  | -    global lastReceivedTime, lastReceivedMaxAge
 | 
	
		
			
				|  |  | +    global lastReceivedTime, lastReceivedMaxAge, lastDataReceiveTime
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    lastDataReceiveTime = time.time()
 | 
	
		
			
				|  |  | +    if debug:
 | 
	
		
			
				|  |  | +        print("lastDataReceiveTime=" + str(lastDataReceiveTime))
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      if payload[:2] == 'is': # msg is reply from CUL to raw send command
 | 
	
		
			
				|  |  |          pass
 | 
	
	
		
			
				|  | @@ -853,29 +857,40 @@ if mqtt_user is not None and mqtt_password is not None:
 | 
	
		
			
				|  |  |  mqttc.connect(mqtt_server, mqtt_port, 60)
 | 
	
		
			
				|  |  |  mqttc.loop_start()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -while True:
 | 
	
		
			
				|  |  | -    if receive_from_serial_cul:
 | 
	
		
			
				|  |  | -        serLine = ser.readline()
 | 
	
		
			
				|  |  | -        if len(serLine) > 0:
 | 
	
		
			
				|  |  | -            now = int(round(time.time() * 1000))
 | 
	
		
			
				|  |  | -            recvCmd = serLine.decode('ascii')
 | 
	
		
			
				|  |  | -            recvCmd = recvCmd.rstrip('\r\n')
 | 
	
		
			
				|  |  | +try:
 | 
	
		
			
				|  |  | +    while True:
 | 
	
		
			
				|  |  | +        if receive_from_serial_cul:
 | 
	
		
			
				|  |  | +            serLine = ser.readline()
 | 
	
		
			
				|  |  | +            if len(serLine) > 0:
 | 
	
		
			
				|  |  | +                now = int(round(time.time() * 1000))
 | 
	
		
			
				|  |  | +                recvCmd = serLine.decode('ascii')
 | 
	
		
			
				|  |  | +                recvCmd = recvCmd.rstrip('\r\n')
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                #if debug:
 | 
	
		
			
				|  |  | +                #    print("lastSentCmd: " + lastSentCmd + ", lastSentCmdTime=" + str(lastSentCmdTime))
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                if recvCmd == lastSentCmd and (now - lastSentCmdTime) < filterSelfSentIncomingTimeout:
 | 
	
		
			
				|  |  | +                    pass
 | 
	
		
			
				|  |  | +                else:
 | 
	
		
			
				|  |  | +                    if verbose:
 | 
	
		
			
				|  |  | +                        log_write("")
 | 
	
		
			
				|  |  | +                        log_write("UART-CUL RX: '" + recvCmd + "'")
 | 
	
		
			
				|  |  | +                    cul_received(recvCmd, "UART")
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  | -            #if debug:
 | 
	
		
			
				|  |  | -            #    print("lastSentCmd: " + lastSentCmd + ", lastSentCmdTime=" + str(lastSentCmdTime))
 | 
	
		
			
				|  |  | +        #touch("/tmp/culagent_running")
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        # check if receive timeout is exceeded 
 | 
	
		
			
				|  |  | +        # - if so there is possibly something wrong
 | 
	
		
			
				|  |  | +        # -> quit program (will be restarted by systemd)
 | 
	
		
			
				|  |  | +        if config['main'].get('dataReceiveTimeout') is not None:
 | 
	
		
			
				|  |  | +            if (time.time() - lastDataReceiveTime) >= float(config['main'].get('dataReceiveTimeout')):
 | 
	
		
			
				|  |  | +                print("WARNING: received no data from CUL for >" + str(config['main'].get('dataReceiveTimeout')) + "s -> something has gone wrong -> quitting program.")
 | 
	
		
			
				|  |  | +                quit()
 | 
	
		
			
				|  |  | +        #else:
 | 
	
		
			
				|  |  | +        #    print("dataReceiveTimeout not configured")
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  | -            if recvCmd == lastSentCmd and (now - lastSentCmdTime) < filterSelfSentIncomingTimeout:
 | 
	
		
			
				|  |  | -                pass
 | 
	
		
			
				|  |  | -            else:
 | 
	
		
			
				|  |  | -                if verbose:
 | 
	
		
			
				|  |  | -                    log_write("")
 | 
	
		
			
				|  |  | -                    log_write("UART-CUL RX: '" + recvCmd + "'")
 | 
	
		
			
				|  |  | -                cul_received(recvCmd, "UART")
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | -    sleep(0.05)
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -##         #print "test"
 | 
	
		
			
				|  |  | -##         #touch("/tmp/culagent_running")
 | 
	
		
			
				|  |  | +        sleep(0.05)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -#except KeyboardInterrupt:
 | 
	
		
			
				|  |  | -#    print("\n")
 | 
	
		
			
				|  |  | +except KeyboardInterrupt:
 | 
	
		
			
				|  |  | +    print("\n")
 |