ZlB0tWZMg设备接收到的数字命令消息
11、使用Easy IoT平台远距离收集声光数据
#MicroPython动手做(31)——物联网之Easy IoT
#使用Easy IoT平台远距离收集声光数据
from mpython import *
import network
from umqtt.simple import MQTTClient
import music
import time
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
mqtt = MQTTClient("664fa81baa7fe777", "182.254.130.180", 1883, "qlZ0uezGR", "3_W0uezGgz", keepalive=30)
mqtt.set_last_will("TvkJXezMR", "I am offline")
try:
mqtt.connect()
print('Connected')
except:
print('Disconnected')
oled.fill(0)
oled.DispChar("远距离收集声光数据", 10, 15, 1)
oled.show()
music.play('D5:1')
rgb.fill((int(0), int(102), int(0)))
rgb.write()
time.sleep_ms(1)
while True:
rgb = (int(255), int(0), int(0))
rgb.write()
time.sleep_ms(1)
mqtt.publish("TvkJXezMR", (str(light.read())))
mqtt.publish("ZlB0tWZMg", (str(sound.read())))
time.sleep(1)
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
收集到的声音数据
收集到的光线数据
mPython X 实验图形编程
12、移动端EasyIoT小程序
微信小程序搜索Easy IoT或打开微信扫描下方二维码,使用DFRobot用户中心账号登陆(手机号+验证码),进入“我的设备”页面。“我的设备”页面显示了在Easy IoT物联网网站中拥有的设备列表。可以看到设备中物联网数据的数据图表。
移动端EasyIoT小程序
移动端EasyIoT小程序
#MicroPython动手做(31)——物联网之Easy IoT
#使用移动端EasyIoT小程序控制RGB灯
#MicroPython动手做(31)——物联网之Easy IoT
#使用移动端EasyIoT小程序控制RGB灯
from mpython import *
import network
from umqtt.simple import MQTTClient
import time
import music
from machine import Timer
import ubinascii
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
mqtt = MQTTClient("0805e3d04f3b34e7", "182.254.130.180", 1883, "qlZ0uezGR", "3_W0uezGgz", keepalive=30)
try:
mqtt.connect()
print('Connected')
except:
print('Disconnected')
mqtt.set_last_will("TvkJXezMR", "Ready!")
def mqtt_topic_54766b4a58657a4d52(_msg):
oled.DispChar((str(_msg)), 55, 24, 1)
oled.show()
if "on" == _msg:
music.play('D5:1')
rgb.fill((int(255), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
oled.DispChar("开灯", 52, 36, 1)
oled.show()
elif "off" == _msg:
music.play('F5:1')
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
oled.DispChar("关灯", 52, 36, 1)
oled.show()
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))
mqtt.set_callback(mqtt_callback)
mqtt.subscribe("TvkJXezMR")
def timer14_tick(_):
mqtt.ping()
tim14 = Timer(14)
tim14.init(period=20000, mode=Timer.PERIODIC, callback=timer14_tick)
oled.invert(0)
oled.DispChar("移动版EasyIoT小程序", 5, 10, 1)
oled.show()
rgb = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
music.play('G5:1')
while True:
mqtt.wait_msg()
用移动端EasyIoT小程序发送指令
mPython X 实验图形编程
用移动端EasyIoT小程序发送指令
页:
1
[2]