Skip to content

Commit 8d80b5c

Browse files
committed
ucloud: Push client version and mode.
Signed-off-by: iabdalkader <[email protected]>
1 parent e380caa commit 8d80b5c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/arduino_iot_cloud/ucloud.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import time
88
import sys
99
import logging
10+
import cbor2
1011
from senml import SenmlPack
1112
from senml import SenmlRecord
1213
from arduino_iot_cloud.umqtt import MQTTClient
13-
1414
import asyncio
1515
from asyncio import CancelledError
1616
try:
@@ -19,6 +19,10 @@
1919
# MicroPython doesn't have this exception
2020
class InvalidStateError(Exception):
2121
pass
22+
try:
23+
from arduino_iot_cloud._version import __version__
24+
except (ImportError, AttributeError):
25+
__version__ = "1.3.0"
2226

2327
# Server/port for basic auth.
2428
_DEFAULT_SERVER = "iot.arduino.cc"
@@ -213,6 +217,7 @@ def __init__(
213217
password = bytes(password, "utf-8")
214218

215219
self.device_topic = b"/a/d/" + device_id + b"/e/i"
220+
self.command_topic = b"/a/d/" + device_id + b"/c/up"
216221

217222
# Update RTC from NTP server on MicroPython.
218223
self.update_systime()
@@ -355,6 +360,10 @@ def poll_discovery(self, aiot=None):
355360
lastval_record.add_to_pack(self.senmlpack)
356361
self.mqtt.subscribe(self.create_topic("shadow", "i"), qos=1)
357362
self.mqtt.publish(self.create_topic("shadow", "o"), self.senmlpack.to_cbor(), qos=1)
363+
364+
# Push library version and mode.
365+
libv = "%s-%s" % (__version__, "async" if self.async_mode else "sync")
366+
self.mqtt.publish(self.command_topic, cbor2.dumps(cbor2.CBORTag(67328, [libv])), qos=1)
358367
logging.info("Device configured via discovery protocol.")
359368
if self.async_mode:
360369
raise DoneException()

0 commit comments

Comments
 (0)