|
楼主 |
发表于 2020-6-12 10:04
|
显示全部楼层
8、读取环境光强度发送至SIoT网页端
[mw_shl_code=arduino,true]#MicroPython动手做(29)——物联网之SIoT
#读取环境光强度发送至SIoT网页端
from umqtt.simple import MQTTClient
from mpython import *
import network
import music
import time
brightness=9
# 事件回调函数
def on_button_a_down(_):
global g_my_variable
time.sleep_ms(10)
if button_a.value() == 1: return
oled.DispChar(" 采集光线值", 0, (3-1)*16, 1)
oled.show()
while True:
mqtt.publish("eagler8/zkb1",(str(light.read())))
time.sleep(2)
my_wifi = wifi()
button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)
my_wifi.connectWiFi("zh","zy1567")
while not (my_wifi.sta.isconnected()):
pass
mqtt = MQTTClient("", "192.168.31.248", 1883, "siot", "dfrobot")
try:
mqtt.connect()
print('Connected')
except:
print('Disconnected')
rgb[1] = (0*brightness//9, 102*brightness//9, 0*brightness//9)
rgb.write()
music.pitch(392, 50)
mqtt.publish("eagler8/zkb1","hello")
oled.invert(0)
oled.DispChar(" SIoT连接成功", 0, (2-1)*16, 1)
oled.show()[/mw_shl_code]
|
|