笔记——用手机来获取nodemcu传来的温湿度数据

笔记——用手机来获取nodemcu传来的温湿度数据

用4号脚来接led,5号脚来接DTH11
用到是AP模式,建立服务器的
从这个大佬学到的 https://www.bilibili.com/video/BV1CW41137dh.
之后可以通过手机下载一个TCP/IP的软件来发送信息到nodemcu上,收到信息后,nodemcu会将需要的信息返回
下面是代码,用lua写的,用的是ESPlorer

现在刚学习没几天,命令只能按照固定的
之后会搞查找字符串,只要里面有ledup led就变亮,不用去输入数字,前面有空格也没事
朴素而又简单的调用

--script1.lua
pin = 4
gpio.mode(pin,gpio.OUTPUT)
wifi.setmode(wifi.SOFTAP)
cfg={}
cfg.ssid="diosama"
cfg.pwd="12345678"
wifi.ap.config(cfg)
print(wifi.ap.getip())
sv = net.createServer(net.TCP,60)
sv:listen(80,function(c)   
    c:send("hello world")
    c:on("receive",function(c, msg)
        zfc = msg
        --print(string.find(zfc,[[open]]))
        s = string.find(zfc,[[open]])
        if(s == nil)then s = 0 end
        print(s)
        print(msg)
        if (zfc == "open\n") then
            print([[led open]])
            gpio.write(pin,gpio.LOW)
        elseif(s >= 1)then
            print(zfc)
            local sub = string.sub(zfc,5,-1)
            print(sub)
            pwm.setup(pin,500,sub)
            pwm.start(pin)
        elseif(zfc == "close\n") then
            print([[led close]])
            pwm.close(pin)
            gpio.write(pin,gpio.HIGH)
        elseif(zfc == "wendu\n")then
            print(wendu)
            for i=1,30 do
                status, temp, humi, temp_dec, humi_dec = dht.read11(5)
                if( temp~=-999 and humi~=-999)then
                    print("DHT Temperature:"..temp..";".."Humidity:"..humi)
                    c:send("DHT Temperature:"..temp..";".."Humidity:"..humi)
                    break
                end
                tmr.delay(100000)
            end
        end
    end)
end)

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值