Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion mqtt-data-logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@
from command import command_input
import command
import sys
from packaging import version

print("Python version is", sys.version_info)

# Check paho-mqtt version for API compatibility
try:
import paho.mqtt
paho_version = paho.mqtt.__version__
use_callback_api_version = version.parse(paho_version) >= version.parse("2.0.0")
except:
use_callback_api_version = False # Default to False for older versions

q=Queue()

##helper functions
Expand All @@ -38,7 +48,10 @@ def convert(t):
class MQTTClient(mqtt.Client):#extend the paho client class
run_flag=False #global flag used in multi loop
def __init__(self,cname,**kwargs):
super(MQTTClient, self).__init__(cname,**kwargs)
if use_callback_api_version:
super(MQTTClient, self).__init__(mqtt.CallbackAPIVersion.VERSION1, cname,**kwargs)
else:
super(MQTTClient, self).__init__(cname,**kwargs)
self.last_pub_time=time.time()
self.topic_ack=[] #used to track subscribed topics
self.run_flag=True
Expand Down
15 changes: 14 additions & 1 deletion mqttdatalogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@
from command import command_input
import command
import sys
from packaging import version

print("Python version is", sys.version_info)

# Check paho-mqtt version for API compatibility
try:
import paho.mqtt
paho_version = paho.mqtt.__version__
use_callback_api_version = version.parse(paho_version) >= version.parse("2.0.0")
except:
use_callback_api_version = False # Default to False for older versions

q=Queue()

##helper functions
Expand All @@ -38,7 +48,10 @@ def convert(t):
class MQTTClient(mqtt.Client):#extend the paho client class
run_flag=False #global flag used in multi loop
def __init__(self,cname,**kwargs):
super(MQTTClient, self).__init__(cname,**kwargs)
if use_callback_api_version:
super(MQTTClient, self).__init__(mqtt.CallbackAPIVersion.VERSION1, cname,**kwargs)
else:
super(MQTTClient, self).__init__(cname,**kwargs)
self.last_pub_time=time.time()
self.topic_ack=[] #used to track subscribed topics
self.run_flag=True
Expand Down