van7 发表于 2016-8-22 11:14 AM

04.[bluebanboom]温湿度记录服务器

最简单的智能家居功能了,记录家里的温湿度变化。<br />
大概讲一下涉及到的技术python,sqlite3,web.py等等。<br />
思路是这样的,创建一个每小时执行一次的定时任务,通过dht11获取温湿度,然后存进sqlite的数据库。<br />
使用web.py建立一个web服务,创建获取温湿度的接口以及界面显示。<br />
<br />
完整代码地址:https://github.com/bluebanboom/thserver<br />
<br />
部署非常简单首先必须clone代码。<br />
<br />
<div class="blockcode"><div id="code_YZx"><ol><li>$ git clone https://github.com/bluebanboom/thserver.git<br />
<li>$ cd thserver<br />
<li>$ git submodule update --init --recursive</ol></div><em onclick="copycode($('code_YZx'));">复制代码</em></div><br />
<br />
<p style="line-height:24px;text-indent:nullem;text-align:left"><font style="color:rgb(51, 51, 51)"><font face="-apple-system, BlinkMacSystemFont, &amp;quot"><font style="font-size:16px">这样代码才完整。</font></font></font></p><p style="line-height:24px;text-indent:nullem;text-align:left"><font style="color:rgb(51, 51, 51)"><font face="-apple-system, BlinkMacSystemFont, &amp;quot"><font style="font-size:16px">将DHT11的data连接到M2+的11号引脚。</font></font></font></p><p style="line-height:24px;text-indent:nullem;text-align:left"><font style="color:rgb(51, 51, 51)"><font face="-apple-system, BlinkMacSystemFont, &amp;quot"><font style="font-size:16px">然后执行</font></font></font></p><div class="blockcode"><div id="code_Y7a"><ol><li>./bootstrap</ol></div><em onclick="copycode($('code_Y7a'));">复制代码</em></div><p style="line-height:24px;text-indent:nullem;text-align:left"><font style="color:rgb(51, 51, 51)"><font face="-apple-system, BlinkMacSystemFont, &amp;quot"><font style="font-size:16px">这个脚本会创建数据库,编译dht11,创建定时任务,启动web服务等。</font></font></font></p><p style="line-height:24px;text-indent:nullem;text-align:left"><font style="color:rgb(51, 51, 51)"><font face="-apple-system, BlinkMacSystemFont, &amp;quot"><font style="font-size:16px">命令完成后,访问<font style="color:rgb(64, 120, 192)"><font style="background-color:transparent">http://localhost:8080/status</font></font>查看服务器运行状态。如果页面显示`Server running...`, 则表示执行正常。</font></font></font></p><p style="line-height:24px;text-indent:nullem;text-align:left"><font style="color:rgb(51, 51, 51)"><font face="-apple-system, BlinkMacSystemFont, &amp;quot"><font style="font-size:16px">bootstrap脚本创建了一个每小时执行一次的定时任务用来获取当前温度。待到收集到一定数据后可以打开<font style="color:rgb(64, 120, 192)"><font style="background-color:transparent">http://localhost:8080/static/index.html</font></font>来查看当日的温湿度曲线。</font></font></font></p><br />
<p style="line-height:24px;text-indent:nullem;text-align:left"><font style="color:rgb(51, 51, 51)"><font face="-apple-system, BlinkMacSystemFont, &amp;quot"><font style="font-size:16px">另外,web服务还提供了一个获取某日温湿度的接口,返回json数据,这样就可以通过该接口为app或者其他设备提供数据了。</font></font></font></p><div align="left"><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol"><font color="#333333">比如要获取8月20日的数据使用该地址http://localhost:8080/day/2016-08-20</font></font></div><div align="left"><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol"><font color="#333333">获取7月19日的使用</font></font>http://localhost:8080/day/2016-07-19</div><div align="left"><br />
</div><div align="left"><font face="-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol"><font color="#333333"><br />
</font></font></div><br />
页: [1]
查看完整版本: 04.[bluebanboom]温湿度记录服务器