{"id":257351,"date":"2015-05-17T18:59:02","date_gmt":"2015-05-17T14:59:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=257351"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=257351","title":{"rendered":"Wi-Fi \u0438\u0437\u043c\u0435\u0440\u0438\u0442\u0435\u043b\u044c CO2 \u043d\u0430 ESP8266 + K-30"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/77c\/d58\/ba7\/77cd58ba757d4ff6a4a307fa16cc63a2.jpg\"\/><br \/>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u0441 Wi-Fi \u043c\u043e\u0434\u0443\u043b\u0435\u043c ESP8266 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u043e\u0441 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 CO2 K-30 \u0447\u0435\u0440\u0435\u0437 MODBUS.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412 <a href=\"http:\/\/habrahabr.ru\/post\/252481\/\">\u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u043f\u0440\u043e\u0448\u0438\u043b\u0438 \u0432 ESP8266 NodeMCU, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 DS18b20 \u0438 \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0435 \u0432 \u043e\u0431\u043b\u0430\u043a\u043e. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0440\u043e\u0441 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 CO2.<br \/>  \u0421\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432 ESP8266 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/p>\n<p>  <b><i>Hardware \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/i><\/b><br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0443 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0434\u0430\u0442\u0447\u0438\u043a <a href=\"http:\/\/www.co2meter.com\/products\/k-30-co2-sensor-module\">K-30<\/a>.<br \/>  \u0421\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c UART RX, UART TX \u0438 GND \u0443 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 K-30 \u0438 ESP8266. \u041f\u0438\u0442\u0430\u043d\u0438\u0435 \u0443 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043d\u043e\u0435.<br \/>  \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e UART \u0443 ESP8266 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d, \u0442\u0430\u043a \u0447\u0442\u043e \u043b\u0438\u0431\u043e \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0430, \u043b\u0438\u0431\u043e K-30<br \/>  <b>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041f\u0438\u0442\u0430\u043d\u0438\u0435 \u0443 K-30 5-14\u0412, \u0443 ESP8266 \u2014 3.3\u0412.<\/b> <br \/>  \u042f \u0440\u0435\u0448\u0438\u043b \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0432 <a href=\"http:\/\/www.aliexpress.com\/item\/Mini-DC-to-DC-Converter-3A-Adjustable-Step-down-Power-Supply-Module-replace-LM2596s\/32331104866.html\">\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c<\/a> 5-&gt;3.3\u0412 <br \/>  <img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/baf\/1aa\/7e2\/baf1aa7e24474325bda320e250f268c8.webp\"\/><\/p>\n<p>  <b><i>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/i><\/b><\/p>\n<p>  1) init.lua \u2014 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f  <\/p>\n<pre><code class=\"lua\">--init.lua print(&quot;Setting up WIFI...&quot;) wifi.setmode(wifi.STATION) --modify according your wireless router settings wifi.sta.config(&quot;YOUR_SSID&quot;,&quot;YOUR_PASSWD&quot;) wifi.sta.connect() tmr.alarm(1, 1000, 1, function()  \tif wifi.sta.getip()== nil then  \t\tprint(&quot;IP unavaiable, Waiting...&quot;)  \telse  \t\ttmr.stop(1) \t\tprint(&quot;Config done, IP is &quot;..wifi.sta.getip()) \t\tdofile(&quot;all.lua&quot;) \tend  end) <\/code><\/pre>\n<p>  2) all.lua \u2014 \u043a\u043e\u0434 \u043e\u043f\u0440\u043e\u0441\u0430 \u0434\u0430\u0442\u0447\u0438\u043a\u043e\u0432 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440  <\/p>\n<pre><code class=\"lua\">pin = 6 t = 0  function read(addr, unit)   ow.setup(pin)   result = nil   flag = false   if(addr == nil) then     ow.reset_search(pin)     count = 0     repeat       count = count + 1       addr = ow.search(pin)       tmr.wdclr()     until((addr ~= nil) or (count &gt; 100))     ow.reset_search(pin)   end   if(addr == nil) then     return result   end   crc = ow.crc8(string.sub(addr,1,7))   if (crc == addr:byte(8)) then     if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then       ow.reset(pin)       ow.select(pin, addr)       ow.write(pin, 0x44, 1)       present = ow.reset(pin)       ow.select(pin, addr)       ow.write(pin,0xBE,1)       data = nil       data = string.char(ow.read(pin))       for i = 1, 8 do         data = data .. string.char(ow.read(pin))       end       crc = ow.crc8(string.sub(data,1,8))       if (crc == data:byte(9)) then          t = (data:byte(1) + data:byte(2) * 256) * 625          t = t \/ 10000         return t       end       tmr.wdclr()     else     end   else   end   return result end    function sendt(t,co,key)  print(&quot;Temp:&quot;..t..&quot; C\\n&quot;) conn=net.createConnection(net.TCP, 0)  conn:on(&quot;receive&quot;, function(conn, payload) print(payload) end) conn:connect(80,'184.106.153.149')  conn:send(&quot;GET \/update?key=&quot;..key..&quot;&field1=&quot;..t..&quot;&field2=&quot;..co..&quot; HTTP\/1.1\\r\\n&quot;)  conn:send(&quot;Host: api.thingspeak.com\\r\\n&quot;)  conn:send(&quot;Accept: *\/*\\r\\n&quot;)  conn:send(&quot;User-Agent: Mozilla\/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\\r\\n&quot;) conn:send(&quot;\\r\\n&quot;)  conn:on(&quot;sent&quot;,function(conn)                     print(&quot;Closing connection&quot;)                       conn:close()                   end) conn:on(&quot;disconnection&quot;, function(conn)                               print(&quot;Got disconnection...&quot;)   end) end   uart.setup(0,9600,8,0,1,0) uart.on(&quot;data&quot;, 0,      function(data) \t--print(&quot;receive from uart:&quot;, data) \t\tif string.len(data) == 7 then \t\t\tresult = string.byte(data,4)*256 + string.byte(data,5) \t\t\tprint (result) \t\t\tsendt(t,result,&quot;YOUR_KEY&quot;) \t\tend     end, 0)   function sendData() t = read() uart.write(0,0xFE,0x04,0x00,0x03,0x00,0x01,0xD5,0xC5) end  tmr.alarm(0, 60000, 1, function() sendData() end )  <\/code><\/pre>\n<p>  \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0431\u043e\u0442\u044b:  <\/p>\n<ul>\n<li>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c UART \u043d\u0430 9600<\/li>\n<li>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c callback \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 UART. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430 \u0438\u0437 7 \u0431\u0430\u0439\u0442(\u043e\u0442\u0432\u0435\u0442 K-30 \u043f\u043e MODBUS) \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 thingspeak.com<\/li>\n<li>\u041a\u0430\u0436\u0434\u0443\u044e \u043c\u0438\u043d\u0443\u0442\u0443 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u0442\u0447\u0438\u043a \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b DS18b20 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0432 UART \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e CO2. \u0417\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u0439\u0434\u0435\u043d \u0432 <a href=\"http:\/\/co2meters.com\/Documentation\/Other\/SenseAirCommGuide.zip\">\u0434\u0430\u0442\u0430\u0448\u0438\u0442\u0435<\/a><\/li>\n<\/ul>\n<p>  \u0420\u0430\u0441\u043a\u0438\u0434\u0430\u0442\u044c \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043a\u0430\u043a \u0441\u043c\u043e\u0433. Lua \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0442\u0451\u043c\u043d\u044b\u0439 \u043b\u0435\u0441.<\/p>\n<p>  <b><i>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/i><\/b><br \/>  <img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/9e1\/7b4\/196\/9e17b4196f6142a1a5c7b3b629885d56.png\"\/><\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e. \u041f\u0438\u0442\u0430\u043d\u0438\u0435 \u0441\u0434\u0435\u043b\u0430\u043b \u043e\u0442 USB, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u043a\u0443\u0434\u0430 \u0443\u0433\u043e\u0434\u043d\u043e. PowerBank \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0435\u0441\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e. \u041f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 Wi-Fi \u2014 \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u043d\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0435 \u0438 \u043d\u0430\u0448 \u0434\u0430\u0442\u0447\u0438\u043a \u0441\u043d\u043e\u0432\u0430 \u0432 \u0441\u0435\u0442\u0438.<\/p>\n<p>  \u041f\u043e \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u044f\u043c \u2014 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0438\u0441\u043a\u043e\u043c\u0444\u043e\u0440\u0442 \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 CO2 \u0443\u0440\u043e\u0432\u043d\u044f \u0432 800-1000 ppm.     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/258137\/\"> http:\/\/habrahabr.ru\/post\/258137\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/77c\/d58\/ba7\/77cd58ba757d4ff6a4a307fa16cc63a2.jpg\"\/><br \/>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u0441 Wi-Fi \u043c\u043e\u0434\u0443\u043b\u0435\u043c ESP8266 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u043e\u0441 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 CO2 K-30 \u0447\u0435\u0440\u0435\u0437 MODBUS.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-257351","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=257351"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257351\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}