|
楼主 |
发表于 2020-6-2 21:34
|
显示全部楼层
4、登录小程序“掌控板物联网”
#MicroPython动手做(27)——物联网之微信小程序
#登录小程序“掌控板物联网”
[mw_shl_code=python,true]#MicroPython动手做(27)——物联网之微信小程序
#登录小程序“掌控板物联网”
from mpython import *
import network
from umqtt.simple import MQTTClient
from machine import Timer
import machine
import ubinascii
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
def OneNET_recv(_msg):pass
_OneNET_msg_list = []
def OneNET_callback(_topic, _msg):
global _OneNET_msg_list
try: _msg = _msg.decode('utf-8', 'ignore')
except: print(_msg);return
OneNET_recv(_msg)
if _msg in _OneNET_msg_list:
eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')
tim14 = Timer(14)
_iot_count = 0
def timer14_tick(_):
global _iot, _iot_count
_iot_count = _iot_count + 1
if _iot_count == 1000: _iot.ping(); _iot_count = 0
try: _iot.check_msg()
except: machine.reset()
_iot = None
def OneNET_setup():
global _iot
_iot = MQTTClient("595250725", "183.230.40.39", 6002, "221628", "hiN7Cwz4Gd7d3ReMnNgtaEKBvv4=", keepalive=300)
_iot.set_callback(OneNET_callback)
if 1 == _iot.connect(): print('Successfully connected to MQTT server.')
tim14.init(period=200, mode=Timer.PERIODIC, callback=timer14_tick)
OneNET_setup()[/mw_shl_code]
|
|