Pārlūkot izejas kodu

2024-03-29:
- add option to speficy JeeLink initialisation command (support different sensor baud rates concurrently by set JeeLink to toggle mode, i.E. when using TX29 AND TX35 sensors)
- add config option (Jeelink) initTimeout
- minor improvements

FloKra 8 mēneši atpakaļ
vecāks
revīzija
8a412098dd
3 mainītis faili ar 84 papildinājumiem un 14 dzēšanām
  1. 5 0
      CHANGELOG.md
  2. 20 0
      jeelinklog/jeelinklog.ini
  3. 59 14
      jeelinklog/jeelinklog.py

+ 5 - 0
CHANGELOG.md

@@ -1,5 +1,10 @@
 # JeeLinkLogMQTT - change log
 
+## 2024-03-29
+* add option to speficy JeeLink initialisation command (support different sensor baud rates concurrently by set JeeLink to toggle mode, i.E. when using TX29 AND TX35 sensors)
+* add config option (Jeelink) initTimeout
+* minor improvements
+
 ## 2024-03-19
 * support LaCrosse-ID value 0
 

+ 20 - 0
jeelinklog/jeelinklog.ini

@@ -9,6 +9,26 @@ logfile_new_sensors = jeelink_new_sensors.log
 [jeelink]
 serialport = /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AL01MYTF-if00-port0
 baudrate = 57600
+initTimeout = 2
+
+# JeeLink Init Command
+#    <n>a     set to 0 if the blue LED bothers
+#    <n>f     initial frequency in kHz (5 kHz steps, 860480 ... 879515)  (for RFM #1)
+#    <n>F     initial frequency in kHz (5 kHz steps, 860480 ... 879515)  (for RFM #2)
+#    <n>h     altituide above sea level
+#    <n>m     bits 1: 17.241 kbps, 2 : 9.579 kbps, 4 : 8.842 kbps (for RFM #1)
+#    <n>M     bits 1: 17.241 kbps, 2 : 9.579 kbps, 4 : 8.842 kbps (for RFM #2)
+#    <n>r     use one of the possible data rates (for RFM #1)
+#    <n>R     use one of the possible data rates (for RFM #2)
+#    <n>t     0=no toggle, else interval in seconds (for RFM #1)
+#    <n>T     0=no toggle, else interval in seconds (for RFM #2)
+#       v     show version
+#    <n>y     if 1 all received packets will be retransmitted  (Relay mode)
+
+# init cmd for TX29 AND TX35 sensors (17.241 and 9.579 kbps, toggle every 30s)
+initCmd = 30t 3m v
+# init cmd for TX29 sensors only (17.241 kbps, no toggle)
+#initCmd = 0t 1m v
 
 [mqtt]
 enable = True

+ 59 - 14
jeelinklog/jeelinklog.py

@@ -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