-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmy-board.py
27 lines (21 loc) · 958 Bytes
/
my-board.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Import SDK packages
# import ssl - is this useful?
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
# For Websocket connection
myMQTTClient = AWSIoTMQTTClient("my-board", useWebsocket=True)
# AWS IoT MQTT Client
myMQTTClient.configureIAMCredentials("ID", "SECRET")
# Configurations
# For Websocket
myMQTTClient.configureEndpoint("ENDPOINT", 443)
# For Websocket, we only need to configure the root CA
myMQTTClient.configureCredentials("rootCA.pem")
myMQTTClient.configureOfflinePublishQueueing(-1) # Infinite offline Publish queueing
myMQTTClient.configureDrainingFrequency(2) # Draining: 2 Hz
myMQTTClient.configureConnectDisconnectTimeout(10) # 10 sec
myMQTTClient.configureMQTTOperationTimeout(5) # 5 sec
myMQTTClient.connect()
myMQTTClient.publish("myFirstTopic", "hello from my-board, I'm using a WebSocket!", 0)
# myMQTTClient.subscribe("test/topic", 1, customCallback)
myMQTTClient.unsubscribe("myFirstTopic")
myMQTTClient.disconnect()