第八次课内容回顾

读取温湿度传感器数据

使用MQTT传输温湿度数据到巴法云

开发板温湿度传感器数据

开发板温湿度传感器连线

image.png

温湿度测量代码

import dht
import time,json
import machine

dht11=dht.DHT11(machine.Pin(5))

# 构建测量函数
def measure(dht11):
    dht11.measure()
    temp,hum=dht11.temperature(), dht11.humidity()
    data = f"当前温度: {temp}℃  湿度: {hum}RH"
    print(data)
    time.sleep(1)
    return temp,hum
def main():
	 temp,hum=measure(dht11)
   print(f"wd:{temp},sd:{hum}")   
    
if __name__=="__main__":
    main()   

接入巴法云MQTT远程读取温湿度

巴法云:https://cloud.bemfa.com/tcp/devicemqtt.html

接入流程:

  1. 创建巴法云账号,并登录

  2. 进入控制台切换为MQTT设备云

    image.png

  3. 右边根据需要,创建自定义Topic

    image.png