-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLucesControlESPALexa.py
More file actions
64 lines (53 loc) · 1.27 KB
/
LucesControlESPALexa.py
File metadata and controls
64 lines (53 loc) · 1.27 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import machine
import network
import time
from umqtt.robust import MQTTClient
import ledscontrol as leds
def cb(topic, msg):
if msg==b'11':
leds.ledson()
print(msg)
if msg==b'12':
leds.ledsoff()
print(msg)
if msg==b'13':
leds.ledsred()
print(msg)
if msg==b'14':
leds.ledsblue()
print(msg)
if msg==b'15':
leds.ledsyellow()
print(msg)
HOST = b'endpoint.iot.us-east-1.amazonaws.com'
TOPIC = bytes('PruebaESP32', 'utf-8')
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("SSID","PASS")
time.sleep(5)
cert="/cert/cert.pem.crt"
key="/cert/private.pem.key"
root="/cert/root_ca.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(5)
def run():
global state
global connection
connection = MQTTClient(client_id=TOPIC, server=HOST, port=8883, ssl=True, ssl_params={"cert":certf, "key":keyf})
connection.connect()
connection.set_callback(cb)
connection.subscribe(b'LedsState')
while True:
try:
connection.wait_msg()
except Exception:
pass
run()