Skip to content

Commit 323b138

Browse files
committed
Device id is must
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent e41a5af commit 323b138

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

labstack/hub.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import paho.mqtt.client as mqtt
33

44
class Hub():
5-
def __init__(self, account_id, api_key, device_id=None, message_handler=None):
5+
def __init__(self, account_id, api_key, device_id, message_handler=None):
66
self.account_id = account_id
7-
self.client = mqtt.Client(client_id=device_id, clean_session=True)
7+
self.client = mqtt.Client(client_id=self._normalize_device_id(device_id), clean_session=True)
88
self.client.username_pw_set(account_id, api_key)
99
# self.client.tls_set(ca_certs='labstack.com/cert.pem')
1010
self.handlers = {}
@@ -17,11 +17,14 @@ def handler(client, userdata, msg):
1717
h(topic, msg.payload)
1818
self.client.on_message = handler
1919

20-
def _normalize_topic(self, topic):
21-
return '{}/{}'.format(self.account_id, topic)
20+
def _normalize_device_id(self, id):
21+
return '{}:{}'.format(self.account_id, id)
22+
23+
def _normalize_topic(self, name):
24+
return '{}/{}'.format(self.account_id, name)
2225

23-
def _denormalize_topic(self, topic):
24-
return topic.lstrip(self.account_id + '/')
26+
def _denormalize_topic(self, name):
27+
return name.lstrip(self.account_id + '/')
2528

2629
def connect(self, handler=None):
2730
self.client.connect("hub.labstack.com", 1883)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='labstack',
5-
version='0.32.0',
5+
version='0.32.1',
66
description='Official Python client library for the LabStack platform',
77
long_description='`<https://github.com/labstack/labstack-python>`_',
88
keywords='image compress, image resize, text summary, barcode generate, barcode scan',

0 commit comments

Comments
 (0)