-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathawstest.py
More file actions
47 lines (36 loc) · 1000 Bytes
/
Copy pathawstest.py
File metadata and controls
47 lines (36 loc) · 1000 Bytes
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
39
40
41
42
43
44
45
46
47
import machine
import network
import time
from umqtt.robust import MQTTClient
def cb(topic,msg):
print(msg)
HOST = b'a3gpjj3vmsemcn-ats.iot.us-east-1.amazonaws.com'
#el host debe ser reemplazado por uno propio
#TOPIC = bytes('ESP32', 'utf-8')
TOPIC = b'ESP32'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("ARiDa-Lab","!K1@B25#3&s")
time.sleep(4)
cert="8851cd3501-certificate.pem.crt"
key="8851cd3501-private.pem.key"
root="AmazonRootCA3.pem"
with open(cert, 'rb') as f:
certf = f.read()
print(certf)
with open(key, 'rb') as f:
keyf = f.read()
print(keyf)
with open(root, 'rb') as f:
rootf = f.read()
print(rootf)
time.sleep(1)
conn = MQTTClient(client_id=TOPIC, server=HOST, port=8883, ssl=True, ssl_params={"cert":certf, "key":keyf})
conn = MQTTClient(client_id=TOPIC, server=HOST, port=8883, ssl=False)
conn.set_callback(cb)
conn.connect()
conn.subscribe(TOPIC)
msg='mensaje'
while True:
connection.publish(topic=TOPIC, msg=msg, qos=0)
sleep(2)