国内综合精彩aⅤ无码不卡_日本少妇做爰全过程_欧美性爱在线播放免费_午夜?V日韩一区二区_免费a级毛片无码免费播放_成在人线av无码喷水_亚洲精品网站色视频_国产婷婷精品成人_老师撩起裙子让我桶的视频_秋霞影院国产

紅外感應

紅外感應的詳細介紹

創(chuàng)作者:bigiot | 更新日期:2023-12-01 | 在線時長:18天
有人闖入,發(fā)送命令至蜂鳴器。

一、功能

有人闖入,發(fā)送命令至蜂鳴器。

二、硬件

三、接線

紅外輸出接ESP8266 GPIO14

四、代碼

1、初始化代碼(init.lua)

--init.lua
print("set up wifi mode")
wifi.setmode(wifi.STATION)
wifi.sta.config("FAST_SXM","lcxxxx56")
--here SSID and PassWord should be modified according your wireless router
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("hongwai.lua")
end
end)

2、檢測代碼(hongwai.lua)

--modify DEVICEID1 INPUTID APIKEY DEVICEID2
local DEVICEID1 = "112"
local INPUTID="162"
local APIKEY = "cxx036f9c"
local DEVICEID2 = "4"
local HONGWAI = 5
local trig = gpio.trig
local host = host or "m.placeboworld.cn"
local port = port or 8181
gpio.mode(HONGWAI,gpio.INT)
cu = net.createConnection(net.TCP)
cu:connect(port, host)
cu:on("receive", function(cu, c) 
print(c)
end)
ok1, s1 = pcall(cjson.encode, {M="checkin",ID=DEVICEID1,K=APIKEY})
if ok1 then
  print(s1)
  cu:send( s1.."\n" )
else
  print("failed to encode1!")
end
tmr.alarm(1, 40000, 1, function()
    cu:send( s1.."\n" )
  end)
local function sendmessage(level)
    if level == gpio.HIGH then
        ok2, s2 = pcall(cjson.encode, {M="say",ID="D"..DEVICEID2,C="play"})
        local v = {[INPUTID]="1"}
        ok3, s3 = pcall(cjson.encode, {M="update",ID=DEVICEID1,V=v})
        if ok2 and ok3 then
          print(s2)
          print(s3)
          cu:send( s2.."\n"..s3.."\n" )
        else
          print("failed to encode2.3!")
        end
    else
        ok4, s4 = pcall(cjson.encode, {M="say",ID="D"..DEVICEID2,C="stop"})
        local v = {[INPUTID]="0"}
        ok5, s5 = pcall(cjson.encode, {M="update",ID=DEVICEID1,V=v})
        if ok4 and ok5 then
          print(s4)
          print(s5)
          cu:send( s4.."\n"..s5.."\n" )
        else
          print("failed to encode4.5!")
        end
    end
end
trig(HONGWAI, "both", sendmessage)