From 62176171e1856b5e3d461643dcc342f8f9141fe3 Mon Sep 17 00:00:00 2001 From: DailyDreaming Date: Tue, 27 Feb 2024 13:48:09 -0800 Subject: [PATCH] Update MQTT client. --- pyproject.toml | 2 +- src/braingeneers/iot/messaging.py | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3bbaf21..9edf7b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ 'matplotlib', 'nptyping', 'numpy', - 'paho-mqtt', + 'paho-mqtt>=2', 'pandas', 'powerlaw', 'redis', diff --git a/src/braingeneers/iot/messaging.py b/src/braingeneers/iot/messaging.py index 7742c80..ce16e90 100644 --- a/src/braingeneers/iot/messaging.py +++ b/src/braingeneers/iot/messaging.py @@ -1,27 +1,22 @@ """ A simplified MQTT client for Braingeneers specific connections """ - import redis -import tempfile -import functools -import json -import inspect import logging import os import re -import time import io import configparser import threading import queue import uuid -from typing import Callable, Tuple, List, Dict, Union import random import json import braingeneers.iot.shadows as sh -from paho.mqtt import client as mqtt_client -from deprecated import deprecated import pickle -from tenacity import retry, wait_exponential, after_log + +from typing import Callable, Tuple, List, Dict, Union +from deprecated import deprecated +from paho.mqtt import client as mqtt_client +from paho.mqtt.enums import CallbackAPIVersion AWS_REGION = 'us-west-2' @@ -767,7 +762,7 @@ def on_log(client, userdata, level, buf): self.logger.debug("MQTT log: %s", buf) client_id = f'braingeneerspy-{random.randint(0, 1000)}' - self._mqtt_connection = mqtt_client.Client(client_id) + self._mqtt_connection = mqtt_client.Client(CallbackAPIVersion.VERSION1, client_id) self._mqtt_connection.username_pw_set(self._mqtt_profile_id, self._mqtt_profile_key) self._mqtt_connection.on_connect = on_connect self._mqtt_connection.on_log = on_log