55# file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
77import time
8- import sys
98import logging
109import cbor2
1110from senml import SenmlPack
@@ -22,7 +21,7 @@ class InvalidStateError(Exception):
2221try :
2322 from arduino_iot_cloud ._version import __version__
2423except (ImportError , AttributeError ):
25- __version__ = "1.3.0 "
24+ __version__ = "1.3.1 "
2625
2726# Server/port for basic auth.
2827_DEFAULT_SERVER = "iot.arduino.cc"
@@ -40,7 +39,7 @@ def timestamp():
4039
4140
4241def timestamp_ms ():
43- return time .time_ns ()// 1000000
42+ return time .time_ns () // 1000000
4443
4544
4645def log_level_enabled (level ):
@@ -199,14 +198,6 @@ def __init__(
199198 self .async_mode = not sync_mode
200199 self .connected = False
201200
202- if "pin" in ssl_params :
203- try :
204- # Use M2Crypto to load key and cert from HSM.
205- import M2Crypto # noqa
206- except (ImportError , AttributeError ):
207- logging .error ("The m2crypto module is required to use HSM." )
208- sys .exit (1 )
209-
210201 # Convert args to bytes if they are passed as strings.
211202 if isinstance (device_id , str ):
212203 device_id = bytes (device_id , "utf-8" )
@@ -372,9 +363,11 @@ def poll_discovery(self, aiot=None):
372363 self .mqtt .subscribe (self .create_topic ("shadow" , "i" ), qos = 1 )
373364 self .mqtt .publish (self .create_topic ("shadow" , "o" ), self .senmlpack .to_cbor (), qos = 1 )
374365
375- # Push library version and mode.
376- libv = "%s-%s" % (__version__ , "async" if self .async_mode else "sync" )
377- self .mqtt .publish (self .command_topic , cbor2 .dumps (cbor2 .CBORTag (67328 , [libv ])), qos = 1 )
366+ if hasattr (cbor2 , "dumps" ):
367+ # Push library version and mode.
368+ libv = "%s-%s" % (__version__ , "async" if self .async_mode else "sync" )
369+ # Note we have to add the tag manually because python-ecosys's cbor2 doesn't suppor CBORTags.
370+ self .mqtt .publish (self .command_topic , b"\xda \x00 \x01 \x07 \x00 " + cbor2 .dumps ([libv ]), qos = 1 )
378371 logging .info ("Device configured via discovery protocol." )
379372 if self .async_mode :
380373 raise DoneException ()
0 commit comments