45
45
__version__ = "0.0.0-auto.0"
46
46
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Cloud_IOT_Core.git"
47
47
48
- TIME_SERVICE = (
49
- "https://io.adafruit.com/api/v2/%s/integrations/time/strftime?x-aio-key=%s"
50
- )
51
-
52
- # our strftime is %Y-%m-%d %H:%M:%S.%L %j %u %z %Z see http://strftime.net/ for decoding details
53
- # See https://apidock.com/ruby/DateTime/strftime for full options
54
- TIME_SERVICE_STRFTIME = (
55
- "&fmt=%25Y-%25m-%25d+%25H%3A%25M%3A%25S.%25L+%25j+%25u+%25z+%25Z"
56
- )
57
-
58
48
class MQTT_API_ERROR (Exception ):
59
49
"""Exception raised on MQTT API return-code errors."""
60
50
# pylint: disable=unnecessary-pass
@@ -64,6 +54,7 @@ class MQTT_API:
64
54
"""Client for interacting with Google's Cloud Core MQTT API.
65
55
66
56
:param MiniMQTT mqtt_client: MiniMQTT Client object.
57
+
67
58
"""
68
59
69
60
# pylint: disable=protected-access
@@ -196,6 +187,7 @@ def loop(self):
196
187
def loop_blocking (self ):
197
188
"""Begins a blocking loop to process messages from
198
189
IoT Core. Code below a call to this method will NOT run.
190
+
199
191
"""
200
192
self ._client .loop_forever ()
201
193
@@ -204,6 +196,7 @@ def subscribe(self, topic, subfolder=None, qos=1):
204
196
:param str topic: Required MQTT topic. Defaults to events.
205
197
:param str subfolder: Optional MQTT topic subfolder. Defaults to None.
206
198
:param int qos: Quality of Service level for the message.
199
+
207
200
"""
208
201
if subfolder is not None :
209
202
mqtt_topic = "/devices/{}/{}/{}" .format (self .device_id , topic , subfolder )
@@ -216,19 +209,22 @@ def subscribe_to_subfolder(self, topic, subfolder, qos=1):
216
209
:param str topic: Required MQTT topic.
217
210
:param str subfolder: Optional MQTT topic subfolder. Defaults to None.
218
211
:param int qos: Quality of Service level for the message.
212
+
219
213
"""
220
214
self .subscribe (topic , subfolder , qos )
221
215
222
216
def subscribe_to_config (self , qos = 1 ):
223
217
"""Subscribes to a Google Cloud IoT device's configuration
224
218
topic.
225
219
:param int qos: Quality of Service level for the message.
220
+
226
221
"""
227
222
self .subscribe ("config" , qos = qos )
228
223
229
224
def subscribe_to_all_commands (self , qos = 1 ):
230
225
"""Subscribes to a device's "commands/#" topic.
231
226
:param int qos: Quality of Service level for the message.
227
+
232
228
"""
233
229
self .subscribe ("commands/#" , qos = qos )
234
230
@@ -243,6 +239,7 @@ def publish(self, payload, topic="events", subfolder=None, qos=0):
243
239
:param str topic: Required MQTT topic. Defaults to events.
244
240
:param str subfolder: Optional MQTT topic subfolder. Defaults to None.
245
241
:param int qos: Quality of Service level for the message.
242
+
246
243
"""
247
244
if subfolder is not None :
248
245
mqtt_topic = "/devices/{}/{}/{}" .format (self .device_id , topic , subfolder )
@@ -259,6 +256,7 @@ def publish_state(self, payload):
259
256
sent by this method should be information about the device itself (such as number of
260
257
crashes, battery level, or device health). This method is unidirectional,
261
258
it communicates Device-to-Cloud only.
259
+
262
260
"""
263
261
self ._client .publish (payload , "state" )
264
262
@@ -318,12 +316,12 @@ def generate_jwt(self, ttl=43200, algo="RS256"):
318
316
319
317
jwt = CloudCore.generate_jwt()
320
318
print("Generated JWT: ", jwt)
319
+
321
320
"""
322
321
if self ._logger :
323
322
self ._logger .debug ("Generating JWT..." )
324
323
ntp = NTP .NTP (self ._esp )
325
324
ntp .set_time ()
326
- #self._get_local_time()
327
325
claims = {
328
326
# The time that the token was issued at
329
327
"iat" : time .time (),
0 commit comments