-
Notifications
You must be signed in to change notification settings - Fork 0
/
awsiotsub.py
38 lines (29 loc) · 1.01 KB
/
awsiotsub.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
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
import paho.mqtt.client as paho
import os
import socket
import ssl
def on_connect(client, userdata, flags, rc):
print("Connection returned result: " + str(rc) )
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("#" , 1 )
def on_message(client, userdata, msg):
print("topic: "+msg.topic)
print("payload: "+str(msg.payload))
#def on_log(client, userdata, level, msg):
# print(msg.topic+" "+str(msg.payload))
mqttc = paho.Client()
mqttc.on_connect = on_connect
mqttc.on_message = on_message
#mqttc.on_log = on_log
awshost = "data.iot.us-east-1.amazonaws.com"
awsport = 8883
clientId = "LabSeat"
thingName = "LabSeat"
caPath = "aws-iot-rootCA.crt"
certPath = "cert.pem"
keyPath = "private.pem"
mqttc.tls_set(caPath, certfile=certPath, keyfile=keyPath, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
mqttc.connect(awshost, awsport, keepalive=60)
mqttc.loop_forever()