<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>润物无声 &#187; 物联网</title>
	<atom:link href="http://blog.zhourunsheng.com/tag/%e7%89%a9%e8%81%94%e7%bd%91/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zhourunsheng.com</link>
	<description>天空一朵雨做的云</description>
	<lastBuildDate>Sat, 08 May 2021 05:17:21 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>搭建基于Flask框架的树莓派服务器</title>
		<link>http://blog.zhourunsheng.com/2013/11/%e6%90%ad%e5%bb%ba%e5%9f%ba%e4%ba%8eflask%e6%a1%86%e6%9e%b6%e7%9a%84%e6%a0%91%e8%8e%93%e6%b4%be%e6%9c%8d%e5%8a%a1%e5%99%a8/</link>
		<comments>http://blog.zhourunsheng.com/2013/11/%e6%90%ad%e5%bb%ba%e5%9f%ba%e4%ba%8eflask%e6%a1%86%e6%9e%b6%e7%9a%84%e6%a0%91%e8%8e%93%e6%b4%be%e6%9c%8d%e5%8a%a1%e5%99%a8/#comments</comments>
		<pubDate>Sat, 09 Nov 2013 02:15:57 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[移动开发]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[树莓派]]></category>
		<category><![CDATA[物联网]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=1868</guid>
		<description><![CDATA[<p>本文展示了怎么样来利用Flask框架来搭建树莓派的服务器，然后通过web方式来控制物理硬件的开关~。背后的实现 [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/11/%e6%90%ad%e5%bb%ba%e5%9f%ba%e4%ba%8eflask%e6%a1%86%e6%9e%b6%e7%9a%84%e6%a0%91%e8%8e%93%e6%b4%be%e6%9c%8d%e5%8a%a1%e5%99%a8/">搭建基于Flask框架的树莓派服务器</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>本文展示了怎么样来利用Flask框架来搭建树莓派的服务器，然后通过web方式来控制物理硬件的开关~。背后的实现原理是，在树莓派的平台上利用python语言开发包，开发IO通信程序，然后通过Flask框架，以web的方式展现出来，那么，这样就可以通过pc的web浏览器或者手持设备的web浏览器来控制实际的硬件开发，实现了物联网的远程控制。<span id="more-1868"></span></p>
<p>The following is an adapted excerpt from <a href="http://www.amazon.com/Getting-Started-Raspberry-Matt-Richardson/dp/1449344216/?tag=mattricha-20">Getting Started with Raspberry Pi</a>. I especially like this section of the book because it shows off one of the strengths of the Pi: its ability to combine modern web frameworks with hardware and electronics.</p>
<p>Not only can you use the Raspberry Pi to get data from servers via the internet, but your Pi can also act as a server itself. There are many different web servers that you can install on the Raspberry Pi. Traditional web servers, like Apache or lighttpd, serve the files from your board to clients. Most of the time, servers like these are sending HTML files and images to make web pages, but they can also serve sound, video, executable programs, and much more.</p>
<p>However, there's a new breed of tools that extend programming languages like Python, Ruby, and JavaScript to create web servers that dynamically generate the HTML when they receive HTTP requests from a web browser. This is a great way to trigger physical events, store data, or check the value of a sensor remotely via a web browser. You can even create your own JSON API for an electronics project!</p>
<h2>Flask Basics</h2>
<p>We're going to use a Python web framework called <a href="http://flask.pocoo.org/">Flask</a> to turn the Raspberry Pi into a dynamic web server. While there's a lot you can do with Flask "out of the box," it also supports many different extensions for doing things such as user authentication, generating forms, and using databases. You also have access to the wide variety of standard Python libraries that are available to you.</p>
<p>In order to install Flask, you'll need to have pip installed. If you haven't already installed pip, it's easy to do:</p>
<pre>pi@raspberrypi ~ $ sudo apt-get install python-pip</pre>
<p>After pip is installed, you can use it to install Flask and its dependencies:</p>
<pre>pi@raspberrypi ~ $ sudo pip install flask</pre>
<p>To test the installation, create a new file called <strong>hello-flask.py</strong> with the code from below.</p>
<h3>hello-flask.py</h3>
<pre>from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80, debug=True)</pre>
<p>Here's a breakdown of each line of code:</p>
<pre>from flask import Flask</pre>
<p>Load the Flask module into your Python script</p>
<pre>app = Flask(__name__)</pre>
<p>Create a Flask object called app</p>
<pre>@app.route("/")
    def hello():</pre>
<p>Run the code below this function when someone accesses the root URL of the server</p>
<pre>return "Hello World!"</pre>
<p>Send the text "Hello World!" to the client's web browser</p>
<pre>if __name__ == "__main__":</pre>
<p>If this script was run directly from the command line</p>
<pre>app.run(host='0.0.0.0', port=80, debug=True)</pre>
<p>Have the server listen on port 80 and report any errors.</p>
<p>NOTE: Before you run the script, you need to know your Raspberry Pi's IP address. You can run <strong>ifconfig</strong> to find it. An alternative is to install avahi-daemon (run <strong>sudo apt-get install avahi-daemon</strong> from the command line). This lets you access the Pi on your local network through the address http://raspberrypi.local. If you're accessing the Raspberry Pi web server from a Windows machine, you may need to put <a href="http://support.apple.com/kb/DL999">Bonjour Services</a> on it for this to work.</p>
<p>Now you're ready to run the server, which you'll have to do as root:</p>
<pre>pi@raspberrypi ~ $ sudo python hello-flask.py
 * Running on http://0.0.0.0:80/
 * Restarting with reloader</pre>
<p>From another computer on the same network as the Raspberry Pi, type your Raspberry Pi's IP address into a web browser. If your browser displays "Hello World!", you know you've got it configured correctly. You may also notice that a few lines appear in the terminal of the Raspberry Pi:</p>
<pre>10.0.1.100 - - [19/Nov/2012 00:31:31] "GET / HTTP/1.1" 200 -
10.0.1.100 - - [19/Nov/2012 00:31:31] "GET /favicon.ico HTTP/1.1" 404 -</pre>
<p>The first line shows that the web browser requested the root URL and our server returned HTTP status code 200 for "OK." The second line is a request that many web browsers send automatically to get a small icon called a <em>favicon</em> to display next to the URL in the browser's address bar. Our server doesn't have a <strong>favicon.ico</strong> file, so it returned HTTP status code 404 to indicate that the URL was not found.</p>
<h2>Templates</h2>
<p>If you want to send the browser a site formatted in proper HTML, it doesn't make a lot of sense to put all the HTML into your Python script. Flask uses a template engine called <a href="http://jinja.pocoo.org/docs/templates/">Jinja2</a> so that you can use separate HTML files with placeholders for spots where you want dynamic data to be inserted.</p>
<p>If you've still got <strong>hello-flask.py</strong> running, press Control-C to kill it.</p>
<p>To make a template, create a new file called <strong>hello-template.py</strong> with the code from below. In the same directory with <strong>hello-template.py</strong>, create a subdirectory called <strong>templates</strong>. In the<strong>templates</strong> subdirectory, create a file called <strong>main.html</strong> and insert the code from below. Anything in double curly braces within the HTML template is interpreted as a variable that would be passed to it from the Python script via the <strong>render_template</strong> function.</p>
<h3>hello-template.py</h3>
<pre>from flask import Flask, render_template
import datetime
app = Flask(__name__)

@app.route("/")
def hello():
   now = datetime.datetime.now()
   timeString = now.strftime("%Y-%m-%d %H:%M")
   templateData = {
      'title' : 'HELLO!',
      'time': timeString
      }
   return render_template('main.html', **templateData)

if __name__ == "__main__":
   app.run(host='0.0.0.0', port=80, debug=True)</pre>
<p>Let's take a look at some of the important lines of code.</p>
<pre>now = datetime.datetime.now()</pre>
<p>Get the current time and store it in the object <strong>now</strong></p>
<pre>timeString = now.strftime("%Y-%m-%d %H:%M")</pre>
<p>Create a formatted string using the date and time from the <strong>now</strong> object</p>
<pre>templateData = {
   'title' : 'HELLO!',
   'time': timeString
   }</pre>
<p>Create a <em>dictionary</em> of variables (a set of <em>keys</em>, such as <strong>title</strong> that are associated with values, such as <strong>HELLO!</strong>) to pass into the template</p>
<pre>return render_template('main.html', **templateData)</pre>
<p>Return the <strong>main.html</strong> template to the web browser using the variables in the <strong>templateData</strong>dictionary</p>
<h3>main.html</h3>
<pre>&lt;!DOCTYPE html&gt;
   &lt;head&gt;
      &lt;title&gt;{{ title }}&lt;/title&gt;
   &lt;/head&gt;

   &lt;body&gt;
      &lt;h1&gt;Hello, World!&lt;/h1&gt;
      &lt;h2&gt;The date and time on the server is: {{ time }}&lt;/h2&gt;
   &lt;/body&gt;
&lt;/html&gt;</pre>
<p>In <strong>main.html</strong>, any time you see a word within double curly braces, it'll be replaced with the matching key's value from the <strong>templateData</strong> dictionary in <strong>hello-template.py</strong>.</p>
<p>Now, when you run <strong>hello-template.py</strong> (as before, you need to use <strong>sudo</strong> to run it) and pull up your Raspberry Pi's address in your web browser, you should see a formatted HTML page with the title "HELLO!" and the Raspberry Pi's current date and time.</p>
<p>NOTE: While it's dependent on how your network is set up, it's unlikely that this page is accessible from outside your local network via the Internet. If you'd like to make the page available from outside your local network, you'll need to configure your router for port forwarding. Refer to your router's documentation for more information about how to do this.</p>
<h2>Connecting the Web to the Real World</h2>
<p>You can use Flask with other Python libraries to bring additional functionality to your site. For example, with the <a href="https://pypi.python.org/pypi/RPi.GPIO">RPi.GPIO</a> Python module you can create a website that interfaces with the physical world. To try it out, hook up a three buttons or switches to pins 23, 24, and 25 as shown in this graphic:</p>
<p><img alt="Connecting three buttons to Raspberry Pi" src="http://mattrichardson.com/images/Raspi-Buttons.png" /></p>
<p>The following code expands the functionality of <strong>hello-template.py</strong>, so copy it to a new file called <strong>hello-gpio.py</strong>. Add the RPi.GPIO module and a new <em>route</em> for reading the buttons, as I've done in the code below. The new route will take a variable from the requested URL and use that to determine which pin to read.</p>
<h3>hello-gpio.py</h3>
<pre>from flask import Flask, render_template
import datetime
import RPi.GPIO as GPIO
app = Flask(__name__)

GPIO.setmode(GPIO.BCM)

@app.route("/")
def hello():
   now = datetime.datetime.now()
   timeString = now.strftime("%Y-%m-%d %H:%M")
   templateData = {
      'title' : 'HELLO!',
      'time': timeString
      }
   return render_template('main.html', **templateData)

@app.route("/readPin/&lt;pin&gt;")
def readPin(pin):
   try:
      GPIO.setup(int(pin), GPIO.IN)
      if GPIO.input(int(pin)) == True:
         response = "Pin number " + pin + " is high!"
      else:
         response = "Pin number " + pin + " is low!"
   except:
      response = "There was an error reading pin " + pin + "."

   templateData = {
      'title' : 'Status of Pin' + pin,
      'response' : response
      }

   return render_template('pin.html', **templateData)

if __name__ == "__main__":
   app.run(host='0.0.0.0', port=80, debug=True)</pre>
<p>Here are the highlights:</p>
<pre>@app.route("/readPin/&lt;pin&gt;")</pre>
<p>Add a dynamic route with pin number as a variable.</p>
<pre>   try:
      GPIO.setup(int(pin), GPIO.IN)
      if GPIO.input(int(pin)) == True:
         response = "Pin number " + pin + " is high!"
      else:
         response = "Pin number " + pin + " is low!"
   except:
      response = "There was an error reading pin " + pin + "."</pre>
<p>If the code indented below <strong>try</strong> raises an exception (that is, there's an error), run the code in the <strong>except</strong> block.</p>
<pre>GPIO.setup(int(pin), GPIO.IN)</pre>
<p>Take the pin number from the URL, convert it into an integer and set it as an input</p>
<pre>if GPIO.input(int(pin)) == True:
    response = "Pin number " + pin + " is high!"</pre>
<p>If the pin is high, set the response text to say that it's high</p>
<pre>else:
    response = "Pin number " + pin + " is low!"</pre>
<p>Otherwise, set the response text to say that it's low</p>
<pre>except:
    response = "There was an error reading pin " + pin + "."</pre>
<p>If there was an error reading the pin, set the response to indicate that</p>
<p>You'll also need to create a new template called <strong>pin.html</strong>. It's not very different from <strong>main.html</strong>, so you may want to copy <strong>main.html</strong> to <strong>pin.html</strong> and make the appropriate changes as shown</p>
<h3>pin.html</h3>
<pre>&lt;!DOCTYPE html&gt;
   &lt;head&gt;
      &lt;title&gt;{{ title }}&lt;/title&gt;
   &lt;/head&gt;

   &lt;body&gt;
      &lt;h1&gt;Pin Status&lt;/h1&gt;
      &lt;h2&gt;{{ response }}&lt;/h2&gt;
   &lt;/body&gt;
&lt;/html&gt;</pre>
<p>With <strong>hello-gpio.py</strong> running, when you point your web browser to your Raspberry Pi's IP address, you should see the standard "Hello World!" page we created before. But add<strong>/readPin/24</strong> to the end of the URL, so that it looks something like<strong>http://10.0.1.103/readPin/24</strong>. A page should display showing that the pin is being read as low. Now hold down the button connected to pin 24 and refresh the page; it should now show up as high!</p>
<p>Try the other buttons as well by changing the URL. The great part about this code is that we only had to write the function to read the pin once and create the HTML page once, but it's almost as though there are separate webpages for each of the pins!</p>
<h2>Project: WebLamp</h2>
<p>In chapter 7 of <a href="http://www.amazon.com/Getting-Started-Raspberry-Matt-Richardson/dp/1449344216/?tag=mattricha-20">Getting Started with Raspberry Pi</a>, Shawn and I show you how to use Raspberry Pi as a simple AC outlet timer using the Linux job scheduler, <strong>cron</strong>. Now that you know how to use Python and Flask, you can now control the state of a lamp over the web. This basic project is simply a starting point for creating Internet-connected devices with the Raspberry Pi.</p>
<p>And just like how the previous Flask example showed how you can have the same code work on multiple pins, you'll set up this project so that if you want to control more devices in the future, it's easy to add.</p>
<p>Connect a Power Switch Tail II to pin 25 of the Raspberry Pi, as shown in the illustration below. If you don't have a Power Switch Tail, you can connect an LED to the pin to try this out for now.</p>
<p><img alt="Conencting Power Switch Tail to Raspberry Pi" src="http://mattrichardson.com/images/raspi-power-tail.jpg" /></p>
<p>If you have another PowerSwitch Tail II relay, connect it to pin 24 to control a second AC device. Otherwise, just connect an LED to pin 24. We're simply using it to demonstrate how multiple devices can be controlled with the same code.</p>
<p>Create a new directory in your home directory called <strong>WebLamp</strong>.</p>
<p>In <strong>WebLamp</strong>, create a file called <strong>weblamp.py</strong> and put in the code from below:</p>
<h3>weblamp.py</h3>
<pre>import RPi.GPIO as GPIO
from flask import Flask, render_template, request
app = Flask(__name__)

GPIO.setmode(GPIO.BCM)

# Create a dictionary called pins to store the pin number, name, and pin state:
pins = {
   24 : {'name' : 'coffee maker', 'state' : GPIO.LOW},
   25 : {'name' : 'lamp', 'state' : GPIO.LOW}
   }

# Set each pin as an output and make it low:
for pin in pins:
   GPIO.setup(pin, GPIO.OUT)
   GPIO.output(pin, GPIO.LOW)

@app.route("/")
def main():
   # For each pin, read the pin state and store it in the pins dictionary:
   for pin in pins:
      pins[pin]['state'] = GPIO.input(pin)
   # Put the pin dictionary into the template data dictionary:
   templateData = {
      'pins' : pins
      }
   # Pass the template data into the template main.html and return it to the user
   return render_template('main.html', **templateData)

# The function below is executed when someone requests a URL with the pin number and action in it:
@app.route("/&lt;changePin&gt;/&lt;action&gt;")
def action(changePin, action):
   # Convert the pin from the URL into an integer:
   changePin = int(changePin)
   # Get the device name for the pin being changed:
   deviceName = pins[changePin]['name']
   # If the action part of the URL is "on," execute the code indented below:
   if action == "on":
      # Set the pin high:
      GPIO.output(changePin, GPIO.HIGH)
      # Save the status message to be passed into the template:
      message = "Turned " + deviceName + " on."
   if action == "off":
      GPIO.output(changePin, GPIO.LOW)
      message = "Turned " + deviceName + " off."
   if action == "toggle":
      # Read the pin and set it to whatever it isn't (that is, toggle it):
      GPIO.output(changePin, not GPIO.input(changePin))
      message = "Toggled " + deviceName + "."

   # For each pin, read the pin state and store it in the pins dictionary:
   for pin in pins:
      pins[pin]['state'] = GPIO.input(pin)

   # Along with the pin dictionary, put the message into the template data dictionary:
   templateData = {
      'message' : message,
      'pins' : pins
   }

   return render_template('main.html', **templateData)

if __name__ == "__main__":
   app.run(host='0.0.0.0', port=80, debug=True)</pre>
<p>Since there's a lot going on in this code, I've placed on the explanations inline, as comments.</p>
<p>Create a new directory within <strong>WebLamp</strong> called <strong>templates</strong>.</p>
<p>Inside <strong>templates</strong>, create the file <strong>main.html</strong>:</p>
<h3>main.html</h3>
<pre>&lt;!DOCTYPE html&gt;
&lt;head&gt;
   &lt;title&gt;Current Status&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
   &lt;h1&gt;Device Listing and Status&lt;/h1&gt;

   {% for pin in pins %}
   &lt;p&gt;The {{ pins[pin].name }}
   {% if pins[pin].state == true %}
      is currently on (&lt;a href="/{{pin}}/off"&gt;turn off&lt;/a&gt;)
   {% else %}
      is currently off (&lt;a href="/{{pin}}/on"&gt;turn on&lt;/a&gt;)
   {% endif %}
   &lt;/p&gt;
   {% endfor %}

   {% if message %}
   &lt;h2&gt;{{ message }}&lt;/h2&gt;
   {% endif %}

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>There are two templating concepts being illustrated in this file. First:</p>
<pre>{% for pin in pins %}
&lt;p&gt;The {{ pins[pin].name }}
{% if pins[pin].state == true %}
   is currently on (&lt;a href="/{{pin}}/off"&gt;turn off&lt;/a&gt;)
{% else %}
   is currently off (&lt;a href="/{{pin}}/on"&gt;turn on&lt;/a&gt;)
{% endif %}
&lt;/p&gt;
{% endfor %}</pre>
<p>This sets up a for loop to cycle through each pin, print its name and its state. It then gives the option to change its state, based on its current state. Second:</p>
<pre>   {% if message %}
   &lt;h2&gt;{{ message }}&lt;/h2&gt;
   {% endif %}</pre>
<p>This if statement will print a message passed from your Python script if there's a message set (that is, a change happened).</p>
<p>In terminal, navigate to the <strong>WebLamp</strong> directory and start the server (be sure to use Control-C to kill any other Flask server you have running first):</p>
<pre>pi@raspberrypi ~/WebLamp $ sudo python weblamp.py</pre>
<p><img alt="The device interface, as viewed through a phone's web browser" src="http://mattrichardson.com/images/Flask-phone.png" /></p>
<p>The best part about writing the code in this way is that you can very easily add as many devices that the hardware will support. Simply add the information about the device to the pins dictionary. When you restart the server, the new device will appear in the status list and its control URLs will work automatically.</p>
<p>There's another great feature built in: if you want to be able to flip the switch on a device with a single tap on your phone, you can create a bookmark to the address<strong>http://ipaddress/pin/toggle</strong>. That URL will check the pin's current state and switch it.</p>
<p>For more information about using Raspberry Pi, check out <a href="http://www.amazon.com/Getting-Started-Raspberry-Matt-Richardson/dp/1449344216/?tag=mattricha-20">Getting Started with Raspberry Pi</a>.</p>
<p>文章节选：<a href="http://mattrichardson.com/Raspberry-Pi-Flask/" target="_blank">http://mattrichardson.com/Raspberry-Pi-Flask/</a></p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/11/%e6%90%ad%e5%bb%ba%e5%9f%ba%e4%ba%8eflask%e6%a1%86%e6%9e%b6%e7%9a%84%e6%a0%91%e8%8e%93%e6%b4%be%e6%9c%8d%e5%8a%a1%e5%99%a8/">搭建基于Flask框架的树莓派服务器</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2013/11/%e6%90%ad%e5%bb%ba%e5%9f%ba%e4%ba%8eflask%e6%a1%86%e6%9e%b6%e7%9a%84%e6%a0%91%e8%8e%93%e6%b4%be%e6%9c%8d%e5%8a%a1%e5%99%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>体验物联网</title>
		<link>http://blog.zhourunsheng.com/2013/09/%e4%bd%93%e9%aa%8c%e7%89%a9%e8%81%94%e7%bd%91/</link>
		<comments>http://blog.zhourunsheng.com/2013/09/%e4%bd%93%e9%aa%8c%e7%89%a9%e8%81%94%e7%bd%91/#comments</comments>
		<pubDate>Mon, 16 Sep 2013 01:47:15 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[云计算]]></category>
		<category><![CDATA[OpenSCADA]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Weixin]]></category>
		<category><![CDATA[物联网]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=1847</guid>
		<description><![CDATA[<p>上个星期初步接触了物联网，正好工作手头有这些基本的器件，可以打造一个最简单的物联网环境，体验一下。本文的目的是 [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/09/%e4%bd%93%e9%aa%8c%e7%89%a9%e8%81%94%e7%bd%91/">体验物联网</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>上个星期初步接触了物联网，正好工作手头有这些基本的器件，可以打造一个最简单的物联网环境，体验一下。本文的目的是展示一个基于温湿度数据采集的报警系统，当温度或者湿度达到一定的临界值，自动打开报警器，并且微信通知系统管理员，系统管理员也可以通过微信查询当前环境的实时温湿度数据。</p>
<p>【系统整体架构】</p>
<p><img class="alignnone" alt="" src="http://farm8.staticflickr.com/7443/9766709544_5761c66bd3_o.png" width="542" height="442" /><br />
1. PC端本地通过OpenScada系统采集温湿度的数据<br />
2. PC端本地将采集到的温湿度数据定时上报到云端，供PAD查询<br />
3. PC端本地检测温湿度的阀值，启动或者关闭报警设备<br />
4. PC端本地检测到报警信息，及时给云端报告告警信息，云端通过微信系统推送到系统管理员账号上<br />
5. 系统管理员通道PAD微信系统，查询当前环境的数据<span id="more-1847"></span></p>
<p>【硬件环境】<br />
1. 工作PC，ubuntu系统，运行openscada数据采集系统<br />
2. PAD一台，手机也可以，模拟器也行，能跑微信就行<br />
3. USB-485 转接器，PC上没有485端口，需要转换成USB通信协议<br />
3. FT-02RL开关量输入输出模块(MODBUS-RTU协议)，软件控制继电器开关<br />
4. 温湿度传感器，基于485 modbus的数据传输协议</p>
<p>【硬件布线】<br />
1. 注意一下电源的正负极，不要接反了<br />
2. 注意485的A B数据端口，不要接反了<br />
3. 其他的没啥问题了</p>
<p><img class="alignnone" alt="" src="http://farm4.staticflickr.com/3771/9766710004_edcff96ea4_z.jpg" width="480" height="640" /></p>
<p><img class="alignnone" alt="" src="http://farm4.staticflickr.com/3674/9766812174_e66c67d61c_z.jpg" width="640" height="480" /><br />
【软件环境】<br />
1. 本地PC运行Ubuntu 12.04 OS<br />
2. 本地实现OpenScada数据采集系统，可以采集Modbus协议的数据，和基于Modbus协议控制外设<br />
3. 远端的PHP服务器，采用的我博客（http://blog.zhourunsheng.com）的后台，基于wordpress + 插件<br />
4. 微信公众号的接入，像我下面的微信号是专门为博客服务的</p>
<p>【演示数据查询】<br />
1. 加入公众微信号，查询关键字“zhou_runsheng”，或者扫描如下的二维码，添加</p>
<p><img class="alignnone" alt="" src="http://blog.zhourunsheng.com/wp-content/uploads/2013/04/qrcode_runsheng_blog.jpg" width="430" height="430" /><br />
2. 发送查询指令，例如“查询温湿度”，返回当前环境温湿度数据<br />
&lt;&lt;&lt; 查询温湿度<br />
&gt;&gt;&gt; 温湿度数据：<br />
温度：33.5 度<br />
湿度：88.7%<br />
露点：18.7 度</p>
<p>3. 其他的指令还没有加入，如果输入其他的查询信息，默认会按照该关键词来搜索相关的博文展示</p>
<p><img class="alignnone" alt="" src="http://farm3.staticflickr.com/2809/9766669722_bb9fb18613_z.jpg" width="640" height="480" /></p>
<p>【演示报警】<br />
1. 加热温湿度采集器（O(∩_∩)O，用火烤烤，甭烧毁仪器就行）<br />
2. 加湿温湿度采集器（最简单的办法，对着仪器哈口气，湿度立马上升到99.99%）<br />
3. 当温湿度达到管理员配置的临界阀值（比如温度超过33摄氏度），产生报警<br />
4. 报警产生，报警器响铃，微信推送通知系统管理员</p>
<p><img class="alignnone" alt="" src="http://farm3.staticflickr.com/2814/9766609931_e7046c61bb_z.jpg" width="640" height="480" /></p>
<p>5. 湿度报警, 继电器开关打开,左数第一个亮起来的红灯</p>
<p><img class="alignnone" alt="" src="http://farm3.staticflickr.com/2870/9766709664_e8c524555d_z.jpg" width="640" height="480" /></p>
<p>【未来】<br />
目前仅仅实现了简单的数据采集+报警应急处理，推广到其他地方，比如智能家居，智能农田灌溉，智能监控系统等等，O(∩_∩)O哈哈~，先想想怎么样打造一套智能的家居吧~~~，把家里联网的东西全控制了。</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/09/%e4%bd%93%e9%aa%8c%e7%89%a9%e8%81%94%e7%bd%91/">体验物联网</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2013/09/%e4%bd%93%e9%aa%8c%e7%89%a9%e8%81%94%e7%bd%91/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
