Skip to content

ucloud: Push client version and mode. #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/client-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- 'main'
paths:
- '*.py'
- '**.py'
- '.github/workflows/*.yml'
- '.github/workflows/*.json'
- '!**/README.md'
Expand All @@ -19,7 +19,7 @@ on:
branches:
- 'main'
paths:
- '*.py'
- '**.py'
- '.github/workflows/*.yml'
- '.github/workflows/*.json'
- '!**/README.md'
Expand Down
11 changes: 10 additions & 1 deletion src/arduino_iot_cloud/ucloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import time
import sys
import logging
import cbor2
from senml import SenmlPack
from senml import SenmlRecord
from arduino_iot_cloud.umqtt import MQTTClient

import asyncio
from asyncio import CancelledError
try:
Expand All @@ -19,6 +19,10 @@
# MicroPython doesn't have this exception
class InvalidStateError(Exception):
pass
try:
from arduino_iot_cloud._version import __version__
except (ImportError, AttributeError):
__version__ = "1.3.0"

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

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

# Update RTC from NTP server on MicroPython.
self.update_systime()
Expand Down Expand Up @@ -355,6 +360,10 @@ def poll_discovery(self, aiot=None):
lastval_record.add_to_pack(self.senmlpack)
self.mqtt.subscribe(self.create_topic("shadow", "i"), qos=1)
self.mqtt.publish(self.create_topic("shadow", "o"), self.senmlpack.to_cbor(), qos=1)

# Push library version and mode.
libv = "%s-%s" % (__version__, "async" if self.async_mode else "sync")
self.mqtt.publish(self.command_topic, cbor2.dumps(cbor2.CBORTag(67328, [libv])), qos=1)
logging.info("Device configured via discovery protocol.")
if self.async_mode:
raise DoneException()
Expand Down
1 change: 1 addition & 0 deletions tests/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def on_value_changed(client, value):
device_id=os.getenv("DEVICE_ID"),
ssl_params={
"pin": "1234",
"use_hsm": True,
"keyfile": "pkcs11:token=arduino",
"certfile": "pkcs11:token=arduino",
"ca_certs": "ca-root.pem",
Expand Down
Loading