|  | @@ -17,6 +17,7 @@ import yaml
 | 
	
		
			
				|  |  |  import json
 | 
	
		
			
				|  |  |  import statistics
 | 
	
		
			
				|  |  |  import math
 | 
	
		
			
				|  |  | +from time import sleep
 | 
	
		
			
				|  |  |  #import math
 | 
	
		
			
				|  |  |  #import numpy as np
 | 
	
		
			
				|  |  |  #import httplib
 | 
	
	
		
			
				|  | @@ -34,6 +35,18 @@ config.read('jeelinklog.ini')
 | 
	
		
			
				|  |  |  serialport = config['jeelink'].get('serialport')
 | 
	
		
			
				|  |  |  serialbaud = int(config['jeelink'].get('baudrate'))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +if config['jeelink'].get('initTimeout') != None:
 | 
	
		
			
				|  |  | +    serialInitTimeout = int(config['jeelink'].get('initTimeout'))
 | 
	
		
			
				|  |  | +else:
 | 
	
		
			
				|  |  | +    serialInitTimeout = 2
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +jeelinkInitCmd = config['jeelink'].get('initCmd')
 | 
	
		
			
				|  |  | +if jeelinkInitCmd == None:
 | 
	
		
			
				|  |  | +    jeelinkInitCmd = "30t 3m v" # init cmd for TX29 AND TX35 sensors (17.241 and 9.579 kbps toggle every 30s)
 | 
	
		
			
				|  |  | +    #jeelinkInitCmd = "0t 1m v" # init cmd for TX29 sensors only (17.241 kbps, no toggle)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  mqtt_topic_prefix = config['mqtt'].get('topic_prefix')
 | 
	
		
			
				|  |  |  topic_prefix_outside_temphum = config['mqtt'].get('topic_prefix_outside_temphum')
 | 
	
		
			
				|  |  |  mqtt_topic_atemp = config['mqtt'].get('topic_outside_temp')
 | 
	
	
		
			
				|  | @@ -206,11 +219,17 @@ def vaporPressure(temp, relHum):
 | 
	
		
			
				|  |  |  if verbosemode:
 | 
	
		
			
				|  |  |      print("JeeLink2MQTT by Flo Kra")
 | 
	
		
			
				|  |  |      print("=======================================================================")
 | 
	
		
			
				|  |  | -    print("loading InfluxDB configuration...")
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  | +    print("JeeLink initCmd: " + jeelinkInitCmd)
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# load InfluxDB configuration 
 | 
	
		
			
				|  |  |  influxdb_yaml = yaml.load(open(config['main'].get('influx_config_yml')), Loader=yaml.SafeLoader)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  if verbosemode: 
 | 
	
		
			
				|  |  | +    print("loading InfluxDB configuration...")
 | 
	
		
			
				|  |  |      print("InfluxDB Instances:")
 | 
	
		
			
				|  |  |      print(json.dumps(influxdb_yaml, indent=4))
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -226,11 +245,18 @@ for instance in influxdb_yaml:
 | 
	
		
			
				|  |  |              influxclient[instance] = InfluxDBClient(i_host, i_port, i_username, i_password, i_database)
 | 
	
		
			
				|  |  |          else:
 | 
	
		
			
				|  |  |              influxclient[instance] = InfluxDBClient(i_host, i_port, i_database)
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +if verbosemode: 
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# load sensors configuration
 | 
	
		
			
				|  |  |  if verbosemode:    
 | 
	
		
			
				|  |  |      print("loading sensors configuration: ")
 | 
	
		
			
				|  |  |      print(json.dumps(sensors_yaml, indent=3))
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  for key in sensors_yaml:
 | 
	
		
			
				|  |  |      #print(key, '->', sensors_yaml[key])
 | 
	
	
		
			
				|  | @@ -262,19 +288,20 @@ for key in sensors_yaml:
 | 
	
		
			
				|  |  |              if verbosemode: print("isOutsideTempSensor:", sensors_yaml[key].get('isOutsideTempSensor'))
 | 
	
		
			
				|  |  |              sensors_outside_sensors.append(sensorId)
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  |      else: 
 | 
	
		
			
				|  |  |          print("WARNING: Sensor " + key + " has no LaCrosseID!")
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -    if verbosemode: print()
 | 
	
		
			
				|  |  | +    if verbosemode: 
 | 
	
		
			
				|  |  | +        print()
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +if verbosemode: 
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  | +    print()
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |  #print(json.dumps(sensor))
 | 
	
		
			
				|  |  |  #print("sensors_id_to_name =",sensors_id_to_name)
 | 
	
		
			
				|  |  |  #print("outside sensors: ", sensors_outside_sensors)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -if verbosemode:
 | 
	
		
			
				|  |  | -    print("\n")
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |  mqttc = mqtt.Client()
 | 
	
	
		
			
				|  | @@ -301,13 +328,21 @@ checkLastUpdateInterval_lastRun = time.time() # first check after timeout expire
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # set serialReceivedLastTime to current time so that we can detect if nothing is received for some time
 | 
	
		
			
				|  |  |  serialReceivedLastTime = int(time.time())
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# init JeeLink device
 | 
	
		
			
				|  |  | +sleep(serialInitTimeout)
 | 
	
		
			
				|  |  | +ser.flushInput()
 | 
	
		
			
				|  |  | +ser.write(jeelinkInitCmd.encode('ascii')) # send init command to Jeelink
 | 
	
		
			
				|  |  | +#ser.write('v\r\n'.encode('ascii'))  # get JeeLink version info
 | 
	
		
			
				|  |  | +sleep(0.2)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  try:
 | 
	
		
			
				|  |  |      while True:
 | 
	
		
			
				|  |  |          msg_was_sent = 0
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          #clear serial buffer to remove junk and noise
 | 
	
		
			
				|  |  | -        ser.flushInput()
 | 
	
		
			
				|  |  | +        ###ser.flushInput()
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          #read buffer until cr/lf
 | 
	
		
			
				|  |  |          serLine = ser.readline().strip()
 | 
	
	
		
			
				|  | @@ -318,13 +353,19 @@ try:
 | 
	
		
			
				|  |  |              serLine = False
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if(serLine):
 | 
	
		
			
				|  |  | -            if serLine.find('OK 9') != -1:
 | 
	
		
			
				|  |  | +            if serLine.find('LaCrosseITPlusReader') != -1:
 | 
	
		
			
				|  |  | +                if verbosemode:
 | 
	
		
			
				|  |  | +                    print("Jeelink version/config: " + serLine)
 | 
	
		
			
				|  |  | +                    print()
 | 
	
		
			
				|  |  | +                    print()
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +            elif serLine.find('OK 9') != -1:
 | 
	
		
			
				|  |  |                  
 | 
	
		
			
				|  |  |                  # set serialReceivedLastTime to current time so that we can detect if nothing is received for some time
 | 
	
		
			
				|  |  |                  serialReceivedLastTime = int(time.time())
 | 
	
		
			
				|  |  |                  
 | 
	
		
			
				|  |  |                  if verbosemode:
 | 
	
		
			
				|  |  | -                    print(serLine + " = LaCrosse sensor")
 | 
	
		
			
				|  |  | +                    print("RX: " + serLine + " => LaCrosse sensor")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  # uns interessieren nur reinkommende Zeilen die mit "OK 9 " beginnen
 | 
	
		
			
				|  |  |                  
 | 
	
	
		
			
				|  | @@ -545,8 +586,12 @@ try:
 | 
	
		
			
				|  |  |                      #    print("\n")
 | 
	
		
			
				|  |  |                      
 | 
	
		
			
				|  |  |                  else:
 | 
	
		
			
				|  |  | -                    if verbosemode: print("ignored invalid sized data")
 | 
	
		
			
				|  |  | +                    if verbosemode: print("RX: " + serLine + " => ignored invalid data")
 | 
	
		
			
				|  |  |                      pass
 | 
	
		
			
				|  |  | +            else:
 | 
	
		
			
				|  |  | +                if verbosemode: 
 | 
	
		
			
				|  |  | +                    print("RX: " + serLine)
 | 
	
		
			
				|  |  | +                pass
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          # publish on MQTT on set interval
 |