python制作物联网控制软件下载_MicroPython动手做(29)——物联网之SIoT

6、尝试在SIoT平台输入消息,控制点亮或熄灭板载LED灯

[mw_shl_code=arduino,true]#MicroPython动手做(29)——物联网之SIoT

#尝试在SIoT平台输入消息,控制点亮或熄灭板载LED灯

from umqtt.simple import MQTTClient

from machine import Timer

from mpython import *

import ubinascii

import network

import music

_mqtt_topic_list = []

def timer14_tick(_):

global mqtt

mqtt.ping()

def mqtt_callback(topic, msg):

try:

topic = topic.decode('utf-8', 'ignore')

_msg = msg.decode('utf-8', 'ignore')

eval('mqtt_topic_' + bytes.decode(ubinascii.hexlify(topic)) + '("' + _msg + '")')

except:

print((topic, msg))

brightness=9

# 事件回调函数

def mqtt_topic_6561676c6572382f7a6b6231(_msg):

global g_my_variable

if (_msg == on):

music.pitch(196, 50)

rgb.fill((255*brightness//9, 255*brightness//9, 153*brightness//9))

rgb.write()

if (_msg == off):

music.pitch(784, 50)

rgb.fill( (0, 0, 0) )

rgb.write()

my_wifi = wifi()

tim14 = Timer(14)

my_wifi.connectWiFi("zh","zy1567")

mqtt = MQTTClient("", "192.168.31.248", 1883, "siot", "dfrobot")

try:

mqtt.connect()

print('Connected')

except:

print('Disconnected')

mqtt.set_callback(mqtt_callback)

tim14.init(period=20000, mode=Timer.PERIODIC, callback=timer14_tick)

mqtt.subscribe("eagler8/zkb1")

rgb[1] = (0*brightness//9, 102*brightness//9, 0*brightness//9)

rgb.write()

music.pitch(392, 50)

mqtt.publish("eagler8/zkb1","on")[/mw_shl_code]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值