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

ESP8266-智能插座

ESP8266-智能插座的詳細(xì)介紹

創(chuàng)作者:ridxqqqq | 更新日期:2016-12-14 | 在線時(shí)長:3天
【藍(lán)狐網(wǎng)絡(luò)】利用ESP8266-01模塊來控制插座

--init.lua

print("set up wifi mode")

wifi.setmode(wifi.STATION)

wifi.sta.config("XXXXX","XXXXX")  //修改相關(guān)路由器信息WIFI的賬號(hào)和密碼//

--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("kaiguan.lua")

end

end)

 

DEVICEID = "XXXXX"   //設(shè)備的ID//

APIKEY = "XXXXX"     //設(shè)備的APIKEY//

INPUTID = "XXXXX"    //設(shè)備的接口ID//

host = host or "m.placeboworld.cn"

port = port or 8181

LED = 4

gpio.mode(LED,gpio.OUTPUT)

cu = net.createConnection(net.TCP)

cu:on("receive", function(cu, c) 

print(c)

r = cjson.decode(c)

if r.M == "say" then

  if r.C == "play" then  

gpio.write(LED, gpio.HIGH)

ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn on!"})

cu:send( played.."\n" )

  end

  if r.C == "stop" then  

gpio.write(LED, gpio.LOW)

ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn off!"})

cu:send( stoped.."\n" )

  end

  end

end)

cu:connect(port, host)

ok, s = pcall(cjson.encode, {M="checkin",ID=DEVICEID,K=APIKEY})

if ok then

  print(s)

else

  print("failed to encode!")

end

cu:send( s.."\n" )

tmr.alarm(1, 60000, 1, function()

    cu:send( s.."\n" )

  end)

 

輸入node.restart()重啟esp8266,看到本地ip說明連接路由器成功,看到welcome to bigiot 說明連接貝殼物聯(lián)服務(wù)器成功,看到checkinok說明設(shè)備登錄成功。

 

登錄用戶中心對(duì)話設(shè)備,遙控設(shè)備輸入play、stop驗(yàn)證,LED燈是否有變化。