diff --git a/_C002_DomoMQTT.py b/_C002_DomoMQTT.py index 876ffb0..e84b238 100644 --- a/_C002_DomoMQTT.py +++ b/_C002_DomoMQTT.py @@ -56,7 +56,11 @@ def controller_init(self,enablecontroller=None): except: self.useping = True try: - self.mqttclient = DMQTTClient() + mqttcompatibility = mqtt.CallbackAPIVersion.VERSION1 + except: + mqttcompatibility = None + try: + self.mqttclient = DMQTTClient(mqttcompatibility) self.mqttclient.subscribechannel = self.outchannel self.mqttclient.controllercb = self.on_message self.mqttclient.connectcb = self.on_connect diff --git a/_C014_GenMQTT.py b/_C014_GenMQTT.py index a3add7c..3ca7ec0 100644 --- a/_C014_GenMQTT.py +++ b/_C014_GenMQTT.py @@ -108,7 +108,11 @@ def controller_init(self,enablecontroller=None): pass except: self.globalretain = False - self.mqttclient = GMQTTClient() + try: + mqttcompatibility = mqtt.CallbackAPIVersion.VERSION1 + except: + mqttcompatibility = None + self.mqttclient = GMQTTClient(mqttcompatibility) self.mqttclient.subscribechannel = self.outch self.mqttclient.controllercb = self.on_message self.mqttclient.connectcb = self.on_connect @@ -174,7 +178,7 @@ def connect(self): except: self.keepalive = 60 try: - self.mqttclient.will_set(self.lwt_t, self.lwtdisconnmsg, qos=0, retain=True) + self.mqttclient.will_set(self.lwt_t, payload=self.lwtdisconnmsg, qos=0, retain=True) self.mqttclient.connect(self.controllerip,int(self.controllerport),keepalive=self.keepalive) # connect_async() is faster but maybe not the best for user/pass method self.mqttclient.loop_start() except Exception as e: @@ -184,7 +188,7 @@ def connect(self): def disconnect(self): try: - (mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtdisconnmsg, qos=0, retain=True) + (mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtdisconnmsg) except Exception as e: print(e) try: @@ -223,7 +227,7 @@ def isconnected(self,ForceCheck=True): commands.rulesProcessing("GenMQTT#Disconnected",rpieGlobals.RULE_SYSTEM) else: try: - (mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtconnmsg, qos=0, retain=True) + (mres,mid) = self.mqttclient.publish(self.lwt_t,self.lwtconnmsg) except: pass commands.rulesProcessing("GenMQTT#Connected",rpieGlobals.RULE_SYSTEM) @@ -582,4 +586,4 @@ def on_disconnect(self, client, userdata, rc): def on_message(self, mqttc, obj, msg): if self.controllercb is not None: self.controllercb(msg) - + \ No newline at end of file diff --git a/_C017_Zabbix.py b/_C017_Zabbix.py new file mode 100644 index 0000000..e646c99 --- /dev/null +++ b/_C017_Zabbix.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +############################################################################# +##################### Zabbix controller for RPIEasy ######################### +############################################################################# +# +# Zabbix controller +# +# Copyright (C) 2018-2024 by Alexander Nagy - https://bitekmindenhol.blog.hu/ +# +import controller +import misc +import rpieGlobals +import time +import webserver +import Settings +import socket +import struct +import json +import threading +import Settings + +class Controller(controller.ControllerProto): + CONTROLLER_ID = 17 + CONTROLLER_NAME = "Zabbix" + + def __init__(self,controllerindex): + controller.ControllerProto.__init__(self,controllerindex) + self.usesID = False + self.onmsgcallbacksupported = False # use direct set_value() instead of generic callback to make sure that values setted anyway + self.controllerport = 10051 + + def controller_init(self,enablecontroller=None): + if enablecontroller != None: + self.enabled = enablecontroller + self.initialized = True + return True + + def webform_load(self): + webserver.addFormNote("Value names will be transmitted as 'taskname-valuename' to Zabbix server!") + + def sender(self,data): + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect( (self.controllerip,int(self.controllerport)) ) + s.send(data) + #resp_header = s.recv(5) + #if 'ZBXD' in str(resp_header): + # resp_header = s.recv(8) + # resp_header = resp_header[:4] + # response_len = struct.unpack('i', resp_header)[0] + # response_raw = s.recv(response_len) + # print(response_raw) + s.close() + except Exception as e: + print(e) + + def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): # called by plugin + if tasknum is None: + return False + if tasknum!=-1 and self.enabled: + if tasknumOpen device configuration page") + if self.controllerindex >= 0: + webserver.addHtml("Open device configuration page") webserver.addFormNumericBox("Keepalive time","keepalive",self.keepalive,2,600) webserver.addUnit("s") try: diff --git a/_C025_ThingsboardM.py b/_C025_ThingsboardM.py index 8b5ba5d..b12e108 100644 --- a/_C025_ThingsboardM.py +++ b/_C025_ThingsboardM.py @@ -58,8 +58,11 @@ def controller_init(self,enablecontroller=None): self.connectinprogress = 0 self.inch = str(self.inchannel) self.outch = str(self.outchannel) - - self.mqttclient = GMQTTClient() + try: + mqttcompatibility = mqtt.CallbackAPIVersion.VERSION1 + except: + mqttcompatibility = None + self.mqttclient = GMQTTClient(mqttcompatibility) self.mqttclient.subscribechannel = self.outch self.mqttclient.controllercb = self.on_message self.mqttclient.connectcb = self.on_connect diff --git a/rpieGlobals.py b/rpieGlobals.py index 2fe3170..9efde60 100644 --- a/rpieGlobals.py +++ b/rpieGlobals.py @@ -6,7 +6,7 @@ # Copyright (C) 2018-2023 by Alexander Nagy - https://bitekmindenhol.blog.hu/ # PROGNAME = "RPIEasy" -BUILD = 24025 +BUILD = 24068 PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:] gpMenu = []