【公网远程】网页控制nodemcu的LED

通过修改McuNode程序,设置自己的id和连接的公网路由器信息,可以实现远程控制nodemcu的LED。访问特定格式的网址(如http://eiot.club/proxy/4567/index.html)即可操作,目前仅支持Get方法。服务器源码在https://github.com/IoTServ/McuNode-server,需自行部署。测试阶段,能从公网任意位置访问并控制nodemcu。
摘要由CSDN通过智能技术生成
id = '4567'  -自己设置自己的id替换4567
ssid = 'wifi名'
ssidpwd = 'wifi密码'
wifi.setmode(wifi.STATION)
wifi.sta.config(ssid,ssidpwd)    --set your ap info !!!!!!
wifi.sta.autoconnect(1)
led1 = 3  
led2 = 4  
gpio.mode(led1, gpio.OUTPUT)  
gpio.mode(led2, gpio.OUTPUT)  
function startServer()
conn=net.createConnection(net.TCP, 0) 
conn:on("connection", function(conn, c)
conn:send(id)
tmr.alarm(2, 30000, 1, function() 
	conn:send('<h1></h1>')
end)
end)
conn:on("receive", function(conn, pl)
		local _, _, method, path, vars = string.find(pl, "([A-Z]+) (.+)?(.+) HTTP");
		local buf = "";
		local _GET = {}  
        if (vars ~= nil)then  
            for k, v in string.gmat
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值