5
5
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
7
7
import time
8
- import sys
9
8
import logging
10
9
import cbor2
11
10
from senml import SenmlPack
@@ -22,7 +21,7 @@ class InvalidStateError(Exception):
22
21
try :
23
22
from arduino_iot_cloud ._version import __version__
24
23
except (ImportError , AttributeError ):
25
- __version__ = "1.3.0 "
24
+ __version__ = "1.3.1 "
26
25
27
26
# Server/port for basic auth.
28
27
_DEFAULT_SERVER = "iot.arduino.cc"
@@ -40,7 +39,7 @@ def timestamp():
40
39
41
40
42
41
def timestamp_ms ():
43
- return time .time_ns ()// 1000000
42
+ return time .time_ns () // 1000000
44
43
45
44
46
45
def log_level_enabled (level ):
@@ -199,14 +198,6 @@ def __init__(
199
198
self .async_mode = not sync_mode
200
199
self .connected = False
201
200
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
-
210
201
# Convert args to bytes if they are passed as strings.
211
202
if isinstance (device_id , str ):
212
203
device_id = bytes (device_id , "utf-8" )
@@ -372,9 +363,11 @@ def poll_discovery(self, aiot=None):
372
363
self .mqtt .subscribe (self .create_topic ("shadow" , "i" ), qos = 1 )
373
364
self .mqtt .publish (self .create_topic ("shadow" , "o" ), self .senmlpack .to_cbor (), qos = 1 )
374
365
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 )
378
371
logging .info ("Device configured via discovery protocol." )
379
372
if self .async_mode :
380
373
raise DoneException ()
0 commit comments