-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmqtt.py
More file actions
48 lines (38 loc) · 982 Bytes
/
mqtt.py
File metadata and controls
48 lines (38 loc) · 982 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
'''
@Author: Aaron.chen
@Date: 2026-03-31
@LastEditTime: 2020-04-24 17:06:08
@Description: example for module umqtt
@FilePath: example_mqtt_file.py
'''
from umqtt import MQTTClient
import utime
import log
import checkNet
import audio
import ujson
from machine import Pin
state = 0
usrname="quectel"
password="12345678"
gpio1=Pin(Pin.GPIO31,Pin.OUT,Pin.PULL_DISABLE,1)
def sub_cb(topic, msg):
data=msg.decode()
print(data)
if data == "led":
gpio1.write(0)
print("led open...")
utime.sleep(3)
gpio1.write(1)
if __name__ == '__main__':
try:
c = MQTTClient("umqtt_client", "101.37.104.185", 41094,usrname,password,ssl=True)
c.set_callback(sub_cb)
c.connect()
c.subscribe("/public/TEST/python")
c.publish("/public/TEST/python", "my name is Quecpython!")
while True:
c.wait_msg()
utime.sleep(1)
except KeyboardInterrupt as e:
c.disconnect()