3-51单片机WIFI学习(开发板8266底层源码介绍)
上一篇链接 http://www.cnblogs.com/yangfengwu/p/8743502.html
直接上源码:注意源码有两部分,第一部分是一开始的时候写在模块内部的,另一部分是存在手机内部的,方便后期更新功能
看第一部分的源码
亲们可以直接把下面的第一部分(注意只下载第一部分就行)的程序下载到8266里面就可以用自己的APP实现远程控制
怎么下载看我以前的文章,LUA开发的
--[[ GPIO0-- GPIO1-- GPIO2-- GPIO3-- GPIO4-- GPIO5-- GPIO9-- GPIO10-- GPIO12-- GPIO13-- GPIO14-- GPIO15-- GPIO16-- --GPIO16 --GPIO5 --GPIO4 --GPIO0 --GPIO2 --GPIO14 --GPIO12 --GPIO13 --GPIO15 --GPIO3 --GPIO1 --GPIO9 --GPIO10 ]] RelayPin=; splitStart = splitIdex=; splitTable={} function split(s, delim) then return end splitStart = splitTable = {} while true do splitIdex = string.find (s, delim, splitStart, true) -- plain find if not splitIdex then break end table.insert (splitTable, )) splitStart = splitIdex + string.len (delim) end table.insert (splitTable, string.sub (s, splitStart)) return splitTable end wifi.setmode(wifi.STATION) local updataFlage = YouInitData1 = "NULL"; YouInitData2 = "NULL"; YouInitData3 = "NULL"; YouInitData4 = "NULL"; MyInitData1 = ""; MyInitData2 = ""; MyInitData3 = ""; MyInitData4 = ""; NodeMcuTimeInSecond = ; NodeMcuTimeInUSecond = ; NodeMcuTimeInrate = ; NodeMcuYear = ; NodeMcuMonth = ; NodeMcuDay= ; NodeMcuHour= ; NodeMcuMinute= ; NodeMcuSecond= ; NodeMcuWeekday= ; NodeMcuRtctime={}; NodeMcuTimer={}; NodeMcuTimerList={}; NodeMcuDataString="nil" NodeMcuTimeString="nil"; NodeMcuWeekdayString="nil"; mqttConnectedFlage = ; NodeMcuRequestTime= sntpAddress="nil"; updataCnt = ; linkcnt=; printtimeCnt=; TCPReadDataOverTime = ; tmr.softwd()--watchdog 60S clientid = wifi.sta.getmac() SubscribeTopic = "yang/sw/"..clientid PublishTopic = "feng/sw/"..clientid if file.open("InitData.lua", "r") then local MyInitData = file.read(); local DataList = split(MyInitData, ';'); ] == "MyData" then MyInitData1 = DataList[] MyInitData2 = DataList[] MyInitData3 = DataList[] MyInitData4 = DataList[] end else print("no InitData") end print("Topic = switch/"..clientid) print("MyInitData1 = "..MyInitData1) print("MyInitData2 = "..MyInitData2) print("MyInitData3 = "..MyInitData3) print("MyInitData4 = "..MyInitData4) --[[Connect the phone to the ap]] apcfg={} apcfg.ssid="qqqqqq" apcfg.pwd=" wifi.sta.config(apcfg) wifi.sta.connect() --wifi.sta.autoconnect() --[[The connection serve phone]] connectIP="192.168.1.102" ClientConnectedFlage = ReceiveData = ""; ReceiveDataCopy = ""; UpdataDataCopy=""; ReceiveDataCnt = ; ReceiveDataCntCopy = ; function InitTimer0function() then Client = net.createConnection(net.TCP, ) --Client:connect(,connectIP) Client:connect(,gateway) Client:on("receive", function(Client, data) ReceiveData = ReceiveData..data; ReceiveDataCnt = ReceiveDataCnt + ; end) Client:on("connection", function(sck, c) ClientConnectedFlage = TcpConnect = Client print("Link OK") tmr.stop() Client:on("disconnection", function(sck, c) ClientConnectedFlage = TcpConnect = nil tmr.start() end) end) then print("Link Error") updataCnt = ; updataFlage = ; linkcnt = linkcnt+ then linkcnt = if TcpConnect ~= nil then TcpConnect:close() end tmr.stop() tmr.stop() dofile("updata.lua"); end end end end tmr.alarm(, , , InitTimer0function) function disposedata(data) local DataList = split(data, ';'); ] == "MyData" then if file.open("InitData.lua", "w+") then file.write(data)--MyInitData file.close() MyInitData1 = DataList[] MyInitData2 = DataList[] MyInitData3 = DataList[] MyInitData4 = DataList[] print(]) print(]) print(]) print(]) if TcpConnect ~= nil then TcpConnect:send(data); end print("write InitData success") end elseif DataList[] == "YouData" then if TcpConnect ~= nil then TcpConnect:send("YouData;"..clientid..";"..SubscribeTopic..";"..PublishTopic..";"..YouInitData1..";".. YouInitData2..";"..YouInitData3..";"..YouInitData4); end print("Send YouData success") elseif DataList[] == "UpdataData" then updataFlage = ; if TcpConnect ~= nil then TcpConnect:send("WaitUpdataData0;"); end print("WaitUpdataData......") file.open("updata.lua", "w+") end ReceiveDataCopy = ""; end function InitTimer1function() then if ReceiveDataCnt == ReceiveDataCntCopy then TCPReadDataOverTime = ; ReceiveDataCopy = ReceiveData; ReceiveData = ""; ReceiveDataCnt = ; ReceiveDataCntCopy = ; then disposedata(ReceiveDataCopy); else if ReceiveDataCopy ~= "UpdataDataSuccess" then file.write(ReceiveDataCopy) updataCnt = updataCnt + if TcpConnect ~= nil then TcpConnect:send("WaitUpdataData"..updataCnt..";"); end print("start down...") else if TcpConnect ~= nil then TcpConnect:send("UpdataDataSuccess"); TcpConnect:close() end file.close() updataFlage = print("UpdataDataSuccess") tmr.stop() tmr.stop() --dofile("main.lua"); node.compile("updata.lua") dofile("updata.lua"); --dofile("main.lc"); end ReceiveDataCopy = ""; end else ReceiveDataCntCopy = ReceiveDataCnt end end end tmr.alarm(, , , InitTimer1function) gpio.mode(,gpio.OUTPUT)--输出模式 tmr.alarm(, , , function() then gpio.write(,-gpio.read()) then sntp.sync(sntpAddress, function() print("sync succeeded:"..sntpAddress) NodeMcuRequestTime = ; end, function(index) print("failed : "..index) end) end end NodeMcurRtctime = rtctime.epoch2cal(rtctime.) NodeMcuTimer = string.format("%04d;%02d;%02d;%02d;%02d;%02d;%01d", NodeMcurRtctime["year"], NodeMcurRtctime["mon"], NodeMcurRtctime["day"], NodeMcurRtctime[, NodeMcurRtctime["min"], NodeMcurRtctime["sec"], NodeMcurRtctime["wday"]) NodeMcuTimerList = split(NodeMcuTimer, ';'); NodeMcuYear = tonumber(NodeMcuTimerList[]); NodeMcuMonth = tonumber(NodeMcuTimerList[]); NodeMcuDay = tonumber(NodeMcuTimerList[]); NodeMcuHour = tonumber(NodeMcuTimerList[]); NodeMcuMinute = tonumber(NodeMcuTimerList[]); NodeMcuSecond = tonumber(NodeMcuTimerList[]); NodeMcuWeekday = tonumber(NodeMcuTimerList[]); NodeMcuHour = NodeMcuHour - ; NodeMcuDataString=NodeMcuYear.."/"..NodeMcuMonth.."/"..NodeMcuDay; NodeMcuTimeString=NodeMcuHour..":"..NodeMcuMinute..":"..NodeMcuSecond; NodeMcuWeekdayString = NodeMcuWeekday..""; NodeMcuTimeInSecond,NodeMcuTimeInUSecond,NodeMcuTimeInrate= rtctime.get() and NodeMcuMinute == and NodeMcuSecond == then NodeMcuRequestTime = ; end printtimeCnt = printtimeCnt +; then printtimeCnt = ; print("Year="..NodeMcuYear..";Month="..NodeMcuMonth..";Day="..NodeMcuDay..";Hour=".. NodeMcuHour..";Minute="..NodeMcuMinute..";Second="..NodeMcuSecond..";Weekday=".. NodeMcuWeekdayString..";TimeInSecond="..NodeMcuTimeInSecond) end if TcpConnect ~= nil then TCPReadDataOverTime = TCPReadDataOverTime +; then TCPReadDataOverTime = ; TcpConnect:close() dofile("updata.lua"); end end tmr.softwd(); end) printip = wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED, function(T) printip = end) wifi.eventmon.register(wifi.eventmon.STA_GOT_IP, function(T) then ip,netmask,gateway = wifi.sta.getip() print(ip) end printip = end)
说一下源码
关于SNTP获取网络时间的问题,用阿里的博客写的
https://yq.aliyun.com/articles/511601?spm=a2c4e.11155435.0.0.15873312ZAcLKJ
直接把源码一贴,不好讲了,因为涉及的多...所以还是看后期自己一点一点的写源码吧
现在贴上第二部分源码,也就是存在手机上的,手机上就是这样存的,前面一点是接收用户配置的MQTT和WIFI的一些信息,所以做成这样子了
\n是换行 \" 的意思就是" 是因为特殊的字符在手机APP源码上要这样写
还有 \"% 其实就是 "% 也是因为特殊字符的问题
<string name="initupdata0"> configwifissid = \"%1$s\";\n configwifipwd= \"%2$s\";\n MqttUserString = \"%3$s\";\n MqttPwdString = \"%4$s\";\n MqttIPString = \"%5$s\";\n MqttPort = %$d;\n if configwifipwd == \"nil\" then\n configwifipwd = nil\n end\n globalSendData =\"nil\"; \n globalSendData1=\"nil\";\n globalSendData2=\"nil\";\n MemoryRelayState = \"3\"; regulartime={};\n regularoption={};\n regularrepetition={};\n DisposeOnceTime="nil";\n RegularTimeLabel=;\n RegularTimeData=\"0\";\n RegularOptionLabel=;\n RegularOptionData=\"0\";\n RegularRepetitionLabel=;\n RegularRepetitionData=\"0\";\n RegularCustom={}\n RegularCustomLabel=;\n RegularCustomData=\"0\";\n DelayData={};\n DelayTime={};\n DelayOption={};\n DelayUnixTime={};\n DelayunixTime=;\n DelayIndex=;\n DelayTimeLabel=;\n DelayTimeData=\"0\";\n DelayTimeDataNumber=;\n RelayNowState=\n RelayNowStateCopy=\n UsartReceiveData=\"\"; UsartReceiveDataCnt=; UsartReceiveDataCntCopy=; , do\n if file.open(\"regular=\"..i..\".lua\", \"r\") then\n local list = split(file.read(), \";\")\n for _, s in ipairs(list) do\n local mlist = split(s, \"=\")\n ],\"time\") then\n regulartime[i] = mlist[];print(regulartime[i])\n elseif ],\"option\") then \n regularoption[i] = mlist[];print(regularoption[i])\n elseif ],\"repetition\") then \n regularrepetition[i] = mlist[];print(regularrepetition[i])\n end\n end\n file.close() \n end\n if file.open(\"delay=\"..i..\".lua\", \"r\") then\n local list = split(file.read(), \";\")\n for _, s in ipairs(list) do\n local mlist = split(s, \"=\")\n ],\"data\") then\n DelayData[i] = mlist[];print(DelayData[i])\n elseif ],\"time\") then\n DelayTime[i] = mlist[];print(DelayTime[i])\n elseif ],\"option\") then \n DelayOption[i] = mlist[];print(DelayOption[i]) \n elseif ],\"unixTime\") then \n DelayUnixTime[i] = mlist[];print(DelayUnixTime[i]) \n end \n end\n file.close() \n end\n end\n if file.open(\"initpower.lua\",\"r\") then\n end\n </string> <string name="initupdata0_0" formatted="false"> if file.open(\"switch=1.lua\", \"r\") then\n if file.read() == \"relay=1\" then\n gpio.write(RelayPin,)\n gpio.mode(RelayPin,gpio.OUTPUT)\n RelayNowState=\n RelayNowStateCopy=\n print(\"relay=1\")\n end\n if file.read() == \"relay=0\" then\n gpio.write(RelayPin,)\n gpio.mode(RelayPin,gpio.OUTPUT)\n RelayNowState=\n RelayNowStateCopy=\n print(\"relay=0\")\n end\n file.close() \n else\n print(\"open RelayState.lua faild\") \n end\n apcfg={}\n apcfg.ssid=configwifissid\n apcfg.pwd=configwifipwd\n wifi.sta.config(apcfg)\n --wifi.sta.connect()\n wifi.sta.autoconnect()\n Mymqtt = mqtt.Client(clientid, ,MqttUserString, MqttPwdString);\n tmr.alarm(, , , function()\n Mymqtt:connect(MqttIPString, MqttPort, ,ConnectSuccess,ConnectFailed)\n end)\n function ConnectSuccess(client)\n client:subscribe(SubscribeTopic, , subscribeSuccess)\n print(\"connected\")\n mqttClient = client;\n tmr.stop();\n if sntpAddress == \"nil\" then \n sntpAddress=\"ntp2.aliyun.com\"; \n end \n mqttConnectedFlage = ;\n end\n function ConnectFailed(client,reason)\n mqttConnectedFlage = ;\n print(\"failed reason: \" .. reason)\n tmr.start()\n end\n function subscribeSuccess(client)\n print(\"subscribe success\") \n end\n </string> <string name="initupdata0_1" formatted="false"> Mymqtt:on(\"message\", function(client, topic, data) \n local list = split(data, \";\")\n ControlRelayFlage = -;\n uart.write(,data)\n ],\"regular\") ~= nil then\n ]..\".lua\", \"w+\") then\n file.write(data)\n file.close() \n for _, s in ipairs(list) do\n local mlist = split(s, \"=\")\n local aa = ],\"%d\"); \n ],\"time\") then\n regulartime[tonumber(aa)] = mlist[];\n elseif ],\"option\") then \n regularoption[tonumber(aa)] = mlist[];\n elseif ],\"repetition\") then \n regularrepetition[tonumber(aa)] = mlist[];\n end\n end\n globalSendData1 = data\n end elseif ],\"delay\") ~= nil then\n ]..\".lua\", \"w+\") then\n file.write(data)\n file.close() \n for _, s in ipairs(list) do\n local mlist = split(s, \"=\")\n local aa = ],\"%d\");\n ],\"data\") then\n DelayIndex = tonumber(aa);\n DelayData[tonumber(aa)] = mlist[];\n elseif ],\"time\") then\n DelayTime[tonumber(aa)] = mlist[];\n elseif ],\"option\") then \n DelayOption[tonumber(aa)] = mlist[]; \n elseif ],\"unixTime\") then \n DelayUnixTime[tonumber(aa)] = mlist[];\n DelayunixTime = tonumber(mlist[]);\n end \n end\n ; NodeMcuTimeInSecond and DelayunixTime ~= and DelayunixTime ~= then\n globalSendData1 = \"delayerror=\"..DelayIndex..\";data\"..DelayIndex..\"=\"..\n NodeMcuDataString..\";\"..\"time\"..DelayIndex..\"=\"..NodeMcuTimeString\n else\n globalSendData1 = data;\n end\n DelayunixTime=; \n end elseif ],\"switch\") ~= nil then \n ]..\".lua\", \"w+\") then \n file.write(list[]) \n file.close() \n for _, s in ipairs(list) do \n if string.find(s,\"relay=0\") ~= nil then \n gpio.write(RelayPin,) \n gpio.mode(RelayPin,gpio.OUTPUT) \n globalSendData1 = data \n end\n if string.find(s,\"relay=1\") ~= nil then \n gpio.write(RelayPin,) \n gpio.mode(RelayPin,gpio.OUTPUT) \n globalSendData1 = data \n end\n end\n end \n elseif ],\"initpower\") ~= nil then\n ]..\".lua\", \"w+\") then\n file.write(list[])\n file.close() \n globalSendData1 = data\n end \n elseif ],\"SWStatus\") ~= nil then \n globalSendData1 = \"switch=1;relay=\"..RelayNowState \n end \n end) \n </string> <string name="initupdata0_2" formatted="false"> tmr.alarm(, , , function() \n then \n RelayNowState = gpio.read(RelayPin) \n if RelayNowState ~= RelayNowStateCopy then \n RelayNowStateCopy = RelayNowState \n globalSendData1 = \"switch=1;relay=\"..RelayNowState \n end \n if globalSendData1~=\"nil\" then \n globalSendData=globalSendData1; \n globalSendData1=\"nil\" \n elseif globalSendData2 ~=\"nil\" then \n globalSendData=globalSendData2; \n globalSendData2=\"nil\" \n else \n globalSendData=\"nil\"; \n end \n if globalSendData ~= \"nil\" then \n mqttClient:publish(PublishTopic,globalSendData, , , function(client) \n end) \n end \n end \n then \n if UsartReceiveDataCntCopy == UsartReceiveDataCnt then \n UsartReceiveDataCnt=; \n UsartReceiveDataCntCopy = ; \n globalSendData2 = UsartReceiveData; \n UsartReceiveData=\"\"; \n else \n UsartReceiveDataCntCopy = UsartReceiveDataCnt; \n end \n end \n end) \n uart.setup(, , , uart.PARITY_NONE, uart.STOPBITS_1) uart.on(\"data\",0,function(data) UsartReceiveData = UsartReceiveData..data; UsartReceiveDataCnt = UsartReceiveDataCnt + ; end, ) tmr.alarm(, , , function() \n for RegularTimeLabel, RegularTimeData in pairs (regulartime) do \n if RegularTimeData == NodeMcuTimeString and DisposeOnceTime ~= NodeMcuTimeString then \n DisposeOnceTime = NodeMcuTimeString; \n if regularrepetition[RegularTimeLabel] == \"everyday\" then \n print(\"everyday\") \n DisposeData(RegularTimeLabel); \n elseif regularrepetition[RegularTimeLabel] == \"work\" then \n if NodeMcuWeekdayString==\"2\" or NodeMcuWeekdayString==\"3\" or NodeMcuWeekdayString==\"4\" or NodeMcuWeekdayString==\"5\" or NodeMcuWeekdayString==\"6\" then print(\"work\") \n DisposeData(RegularTimeLabel); \n end \n else \n RegularCustom={} \n RegularCustom = split(regularrepetition[RegularTimeLabel], \",\"); \n for RegularCustomLabel, RegularCustomData in ipairs (RegularCustom) do \n if RegularCustomData == NodeMcuWeekdayString then \n print(\"custom\") \n DisposeData(RegularTimeLabel); \n end \n end \n end \n else \n negationOnceTime=\"nil\"; \n end \n end \n for DelayTimeLabel, DelayTimeData in pairs (DelayUnixTime) do \n --DelayTimeDataNumber = tonumber(DelayTimeData); \n if DelayTimeData == NodeMcuTimeInSecond..\"\" then \n if DelayOption[DelayTimeLabel] == \"on\" then \n gpio.write(RelayPin,) \n gpio.mode(RelayPin,gpio.OUTPUT) \n print(\"on\") \n elseif DelayOption[DelayTimeLabel] == \"off\" then \n gpio.write(RelayPin,) \n gpio.mode(RelayPin,gpio.OUTPUT) \n print(\"off\") \n elseif DelayOption[DelayTimeLabel] == \"negation\" then \n gpio.write(RelayPin,-gpio.read(RelayPin)) \n gpio.mode(RelayPin,gpio.OUTPUT) \n print(\"negation\") \n end \n end \n end \n end) \n function DisposeData(label) \n if regularoption[label] == \"on\" then \n gpio.write(RelayPin,) \n gpio.mode(RelayPin,gpio.OUTPUT) \n print(\"on\") \n elseif regularoption[label] == \"off\" then \n gpio.write(RelayPin,) \n gpio.mode(RelayPin,gpio.OUTPUT) \n print(\"off\") \n elseif regularoption[label] == \"negation\" then \n gpio.write(RelayPin,-gpio.read(RelayPin)) \n gpio.mode(RelayPin,gpio.OUTPUT) \n print(\"negation\") \n end \n print(\"pin=\"..gpio.read(RelayPin)) \n end \n </string>
上面的不方便看,给大家一个直接可以下载用的
前面是路由器的和MQTT的信息,屏蔽了
--configwifissid = ""; --configwifipwd=""; --MqttUserString = ""; --MqttPwdString = ""; --MqttIPString = ""; --MqttPort = ; if configwifipwd == "nil" then configwifipwd = nil end globalSendData ="nil"; globalSendData1="nil"; globalSendData2="nil"; MemoryRelayState = "; regulartime={}; regularoption={}; regularrepetition={}; DisposeOnceTime=""; RegularTimeLabel=; RegularTimeData=""; RegularOptionLabel=; RegularOptionData=""; RegularRepetitionLabel=; RegularRepetitionData=""; RegularCustom={} RegularCustomLabel=; RegularCustomData=""; DelayData={}; DelayTime={}; DelayOption={}; DelayUnixTime={}; DelayunixTime=; DelayIndex=; DelayTimeLabel=; DelayTimeData=""; DelayTimeDataNumber=; RelayNowState= RelayNowStateCopy= UsartReceiveData=""; UsartReceiveDataCnt=; UsartReceiveDataCntCopy=; , do if file.open("regular="..i..".lua", "r") then local list = split(file.read(), ';') for _, s in ipairs(list) do local mlist = split(s, '=') ],"time") then regulartime[i] = mlist[];print(regulartime[i]) elseif ],"option") then regularoption[i] = mlist[];print(regularoption[i]) elseif ],"repetition") then regularrepetition[i] = mlist[];print(regularrepetition[i]) end end file.close() end if file.open("delay="..i..".lua", "r") then local list = split(file.read(), ';') for _, s in ipairs(list) do local mlist = split(s, '=') ],"data") then DelayData[i] = mlist[];print(DelayData[i]) elseif ],"time") then DelayTime[i] = mlist[];print(DelayTime[i]) elseif ],"option") then DelayOption[i] = mlist[];print(DelayOption[i]) elseif ],"unixTime") then DelayUnixTime[i] = mlist[];print(DelayUnixTime[i]) end end file.close() end end if file.open("initpower.lua","r") then end if file.open("switch=1.lua", "r") then if file.read() == "relay=1" then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) RelayNowState= RelayNowStateCopy= print("relay=1") end if file.read() == "relay=0" then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) RelayNowState= RelayNowStateCopy= print("relay=0") end file.close() else print("open RelayState.lua faild") end apcfg={} apcfg.ssid=configwifissid apcfg.pwd=configwifipwd wifi.sta.config(apcfg) --wifi.sta.connect() wifi.sta.autoconnect() Mymqtt = mqtt.Client(clientid, ,MqttUserString, MqttPwdString); tmr.alarm(, , , function() Mymqtt:connect(MqttIPString, MqttPort, ,ConnectSuccess,ConnectFailed) end) function ConnectSuccess(client) client:subscribe(SubscribeTopic, , subscribeSuccess) print("connected") mqttClient = client; tmr.stop(); if sntpAddress == "nil" then sntpAddress="ntp2.aliyun.com"; end mqttConnectedFlage = ; end function ConnectFailed(client,reason) mqttConnectedFlage = ; print("failed reason: " .. reason) tmr.start() end function subscribeSuccess(client) print("subscribe success") end Mymqtt:on("message", function(client, topic, data) local list = split(data, ';') ControlRelayFlage = -; uart.write(,data) ],"regular") ~= nil then ]..".lua", "w+") then file.write(data) file.close() for _, s in ipairs(list) do local mlist = split(s, '=') local aa = ],"%d"); ],"time") then regulartime[tonumber(aa)] = mlist[];print(regulartime[tonumber(aa)]) elseif ],"option") then regularoption[tonumber(aa)] = mlist[];print(regularoption[tonumber(aa)]) elseif ],"repetition") then regularrepetition[tonumber(aa)] = mlist[];print(regularrepetition[tonumber(aa)]) end end globalSendData1 = data end elseif ],"delay") ~= nil then ]..".lua", "w+") then file.write(data) file.close() for _, s in ipairs(list) do local mlist = split(s, '=') local aa = ],"%d"); ],"data") then DelayIndex = tonumber(aa); DelayData[tonumber(aa)] = mlist[];print(DelayData[tonumber(aa)]) elseif ],"time") then DelayTime[tonumber(aa)] = mlist[];print(DelayTime[tonumber(aa)]) elseif ],"option") then DelayOption[tonumber(aa)] = mlist[];print(DelayOption[tonumber(aa)]) elseif ],"unixTime") then DelayUnixTime[tonumber(aa)] = mlist[];print(DelayUnixTime[tonumber(aa)]) DelayunixTime = tonumber(mlist[]); end end and DelayunixTime ~= then globalSendData1 = "delayerror="..DelayIndex..";data"..DelayIndex.."=".. NodeMcuDataString..";".."time"..DelayIndex.."="..NodeMcuTimeString else globalSendData1 = data; end DelayunixTime=; print(globalSendData1) end elseif ],"switch") ~= nil then ]..".lua", "w+") then file.write(list[]) file.close() for _, s in ipairs(list) do if string.find(s,"relay=0") ~= nil then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) globalSendData1 = data end if string.find(s,"relay=1") ~= nil then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) globalSendData1 = data end end end elseif ],"initpower") ~= nil then ]..".lua", "w+") then file.write(list[]) file.close() globalSendData1 = data end elseif ],"SWStatus") ~= nil then globalSendData1 = "switch=1;relay="..RelayNowState end end) --[[The Send Msg]] tmr.alarm(, , , function() then RelayNowState = gpio.read(RelayPin) if RelayNowState ~= RelayNowStateCopy then RelayNowStateCopy = RelayNowState globalSendData1 = "switch=1;relay="..RelayNowState end if globalSendData1~="nil" then globalSendData=globalSendData1; globalSendData1="nil" elseif globalSendData2 ~="nil" then globalSendData=globalSendData2; globalSendData2="nil" else globalSendData="nil"; end if globalSendData ~= "nil" then mqttClient:publish(PublishTopic,globalSendData, , , function(client) end) end end then if UsartReceiveDataCntCopy == UsartReceiveDataCnt then UsartReceiveDataCnt=; UsartReceiveDataCntCopy = ; globalSendData2 = UsartReceiveData; UsartReceiveData=""; else UsartReceiveDataCntCopy = UsartReceiveDataCnt; end end end) uart.setup(, , , uart.PARITY_NONE, uart.STOPBITS_1) uart.on(,function(data) UsartReceiveData = UsartReceiveData..data; UsartReceiveDataCnt = UsartReceiveDataCnt + ; end, ) tmr.alarm(, , , function() for RegularTimeLabel, RegularTimeData in pairs (regulartime) do if RegularTimeData == NodeMcuTimeString and DisposeOnceTime ~= NodeMcuTimeString then DisposeOnceTime = NodeMcuTimeString; if regularrepetition[RegularTimeLabel] == "everyday" then print("everyday") DisposeData(RegularTimeLabel); elseif regularrepetition[RegularTimeLabel] == "work" then " then print("work") DisposeData(RegularTimeLabel); end else RegularCustom={} RegularCustom = split(regularrepetition[RegularTimeLabel], ','); for RegularCustomLabel, RegularCustomData in ipairs (RegularCustom) do if RegularCustomData == NodeMcuWeekdayString then print("custom") DisposeData(RegularTimeLabel); end end end else negationOnceTime=""; end end for DelayTimeLabel, DelayTimeData in pairs (DelayUnixTime) do --DelayTimeDataNumber = tonumber(DelayTimeData); if DelayTimeData == NodeMcuTimeInSecond.."" then if DelayOption[DelayTimeLabel] == "on" then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) print("on") elseif DelayOption[DelayTimeLabel] == "off" then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) print("off") elseif DelayOption[DelayTimeLabel] == "negation" then gpio.write(RelayPin,-gpio.read(RelayPin)) gpio.mode(RelayPin,gpio.OUTPUT) print("negation") end end end end) function DisposeData(label) if regularoption[label] == "on" then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) print("on") elseif regularoption[label] == "off" then gpio.write(RelayPin,) gpio.mode(RelayPin,gpio.OUTPUT) print("off") elseif regularoption[label] == "negation" then gpio.write(RelayPin,-gpio.read(RelayPin)) gpio.mode(RelayPin,gpio.OUTPUT) print("negation") end print("pin="..gpio.read(RelayPin)) end
后期一点一点做的时候就明白了,一下子这么多实在让人受不了..............
其实只要会基本的功能了,其余的都是看个人的发挥了
3-51单片机WIFI学习(开发板8266底层源码介绍)的更多相关文章
- 1-51单片机WIFI学习(开发板介绍)
源码链接都在后面 前面的都是介绍单独的WIFI,没有和单片机结合起来,因为做项目很少会只用WIFI模块.大多数都是WIFI模块作为中转数据的桥梁,单片机负责 数据采集,控制等等,所以自己准备出一套51 ...
- 4-51单片机WIFI学习(开发板51单片机自动冷启动下载原理)
上一篇链接 http://www.cnblogs.com/yangfengwu/p/8743936.html 这一篇说一下自己板子的51单片机自动冷启动下载原理,我挥舞着键盘和鼠标,发誓要把世界写个明 ...
- 2-51单片机WIFI学习(开发板测试远程通信详细介绍)
前一篇链接(最后有APP安装包下载地址) http://www.cnblogs.com/yangfengwu/p/8720148.html 由于自己别的贴片的板子还没到,所以用自己的8266最小系统板 ...
- 迅为4412开发板QtE系统源码-屏幕横竖屏切换修改方法
迅为4412开发板QtE系统源码-屏幕横竖屏切换修改方法 详情了解:http://topeetboard.com 更多了解:https://arm-board.taobao.com/ 用户在开发板上运 ...
- GuavaCache学习笔记三:底层源码阅读
申明:转载自 https://www.cnblogs.com/dennyzhangdd/p/8981982.html 感谢原博主的分享,看到这个写的真好,直接转载来,学习了. 另外也推荐另外一篇Gua ...
- 如何选择单片机和Android-LInux-ARM开发板?
源: 如何选择单片机和Android-LInux-ARM开发板?
- Java学习-039-源码 jar 包的二次开发扩展实例(源码修改)
最近在使用已有的一些 jar 包时,发现有些 jar 包中的一些方法无法满足自己的一些需求,例如返回固定的格式,字符串处理等等,因而需要对原有 jar 文件中对应的 class 文件进行二次开发扩展, ...
- Spring学习之——手写Spring源码V2.0(实现IOC、D、MVC、AOP)
前言 在上一篇<Spring学习之——手写Spring源码(V1.0)>中,我实现了一个Mini版本的Spring框架,在这几天,博主又看了不少关于Spring源码解析的视频,受益匪浅,也 ...
- H5类似易企秀/编辑器/页面制作/开发/生成工具/软件/源码/授权
代码地址如下:http://www.demodashi.com/demo/14960.html 项目简介 H5DS (HTML5 Design software) 这是一款基于WEB的 H5制作工具. ...
随机推荐
- struts_自定义日期类型转换器
1.问题:struts默认的日期类型是 xxxx-mm-dd,不能接收xxxx/mm//dd类型的日期 2.解决方案(继承DefaultTypeConverter,覆盖convertValue(Obj ...
- Prototype模式
浅克隆:对值类型的成员变量进行值的复制,对引用类型的成员变量只复制引用,不复制引用的对象.深克隆:对值类型的成员变量进行值的复制,对引用类型的成员变量也进行引用对象的复制. /** * Created ...
- jquery ajax 返回的json对象 新增属性值(干货)
$.ajax({ type:"GEt'; url:"你的地址", data:{"你的字段","字段值"} success:funt ...
- 针对微信的一篇推送附有的数据链接进行MapReduce统计
原推送引用:https://mp.weixin.qq.com/s/3qQqN6qzQ3a8_Au2qfZnVg 版权归原作者所有,如有侵权请及时联系本人,见谅! 原文采用Excel进行统计数据,这里采 ...
- python web开发-flask中消息闪现flash的应用
Flash中的消息闪现,在官方的解释是用来给用户做出反馈.不过实际上这个功能只是一个记录消息的方法,在某一个请求中记录消息,在下一个请求中获取消息,然后做相应的处理,也就是说flask只存在于两个相邻 ...
- [模拟赛] T1 无线通讯网
Description 国防部计划用无线网络连接若干个边防哨所.2种不同的通讯技术用来搭建无线网络: 每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫星电话线路的 ...
- linux --> vimrc的配置
vimrc的配置 .vimrc文件: " 去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 set nocompatible "代码补全 set completeopt ...
- Dom属性方法
一.javascript的三大核心 1.ECMAScript js的语法标准 2.DOM Document object Model 文档对象模型,提供的方法可以让js操作html标签 3.BOM B ...
- 接口登录CSDN发布博客---封装方法,使用unittest框架
一个简单的跑接口流程:登录后发表带图片的博客.这里涉及到的知识点: 1.登录时通过cookies去保持登录状态,把cookies添加到一个session中,这样可以保持长时间登录状态: 2.我们通过爬 ...
- 2017年PHP程序员未来路在何方——韩天峰
PHP 从诞生到现在已经有20多年历史,从Web时代兴起到移动互联网退潮,互联网领域各种编程语言和技术层出不穷, Node.js . GO . Python 不断地在挑战 PHP 的地位.这些技术的推 ...