<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[Node.js扩展读取发到上位机Raspberry pi的串口温度数据]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[系统架构与硬件]]></category>
<pubDate>Sun, 24 Feb 2013 01:52:17 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	画图Html5包：http://www.rgraph.net/docs/updating-charts-dynamically.html<br/>if (document.all &amp;&amp; RGraph.isIE8()) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&#039;[MSIE] Sorry, Internet Explorer 8 is not fast enough to support animated charts&#039;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/><br/>注意：不支持IE8，经测试FF,Chrome都支持。<br/>sudo apt-get install nodejs npm //npm 才能安装nodejs的扩展<br/>sudo npm install serialport<br/><textarea name="code" class="JS" rows="15" cols="100">
&quot;use strict&quot;;
//2012-06-23 http://alexandre.alapetite.fr

var arduinoSerialPort = &#039;/dev/ttyACM0&#039;;&nbsp;&nbsp;//Serial port over USB connection between the Raspberry Pi and the Arduino

var fs = require(&#039;fs&#039;);
function writeFile(text)
&#123;
&nbsp;&nbsp;fs.writeFile(&#039;temperature.json&#039;, text, function(err)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;if (err) console.warn(err);
&nbsp;&nbsp;&#125;);
&#125;

var os = require(&#039;os&#039;);
var serverSignature = &#039;Node.js / Debian &#039; + os.type() + &#039; &#039; + os.release() + &#039; &#039; + os.arch() + &#039; / Raspberry Pi B + Arduino Uno R3&#039;;

var postOptions =
&#123;
&nbsp;&nbsp;host: &#039;alexandre.alapetite.fr&#039;,&nbsp;&nbsp;//Change to your own server&nbsp;&nbsp;posttestserver.com
&nbsp;&nbsp;path: &#039;/doc-alex/temperature/post.php&#039;,&nbsp;&nbsp;//&nbsp;&nbsp;/post.php
&nbsp;&nbsp;method: &#039;POST&#039;,
&nbsp;&nbsp;headers:
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,
&nbsp;&nbsp;&nbsp;&nbsp;&#039;Connection&#039;: &#039;close&#039;,
&nbsp;&nbsp;&nbsp;&nbsp;&#039;User-Agent&#039;: serverSignature
&nbsp;&nbsp;&#125;
&#125;;

var http = require(&#039;http&#039;);
function postData(s)
&#123;//Standard HTTP POST request
&nbsp;&nbsp;var myOptions = postOptions;
&nbsp;&nbsp;postOptions.headers[&#039;Content-Length&#039;] = s.length;

&nbsp;&nbsp;var requestPost = http.request(myOptions, function(res)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;res.setEncoding(&#039;utf8&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;/*res.on(&#039;data&#039;, function (chunk)
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(chunk);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;);*/
&nbsp;&nbsp;&#125;);

&nbsp;&nbsp;requestPost.on(&#039;error&#039;, function(e)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;console.warn(e);
&nbsp;&nbsp;&#125;);

&nbsp;&nbsp;requestPost.write(s);
&nbsp;&nbsp;requestPost.end();
&#125;

var serialport = require(&#039;serialport&#039;);
var serialPort = new serialport.SerialPort(arduinoSerialPort,
&#123;//Listening on the serial port for data coming from Arduino over USB
&nbsp;&nbsp;parser: serialport.parsers.readline(&#039;&#92;n&#039;)
&#125;);

var lastTemperatureIndoor = NaN;
var lastTemperatureOutoor = NaN;
var dateLastInfo = new Date(0);

var querystring = require(&#039;querystring&#039;);
serialPort.on(&#039;data&#039;, function (data)
&#123;//When a new line of text is received from Arduino over USB
&nbsp;&nbsp;try
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;var j = JSON.parse(data);
&nbsp;&nbsp;&nbsp;&nbsp;lastTemperatureOutoor = j.celsius / 100.0;
&nbsp;&nbsp;&nbsp;&nbsp;lastTemperatureIndoor = j.celsius2 / 100.0;
&nbsp;&nbsp;&nbsp;&nbsp;dateLastInfo = new Date();
&nbsp;&nbsp;&nbsp;&nbsp;writeFile(&#039;&#123;&quot;outdoor&quot;:&quot;&#039; + lastTemperatureOutoor + &#039;&quot;,&quot;indoor&quot;:&quot;&#039; + lastTemperatureIndoor + &#039;&quot;&#125;&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;postData(querystring.stringify(j));&nbsp;&nbsp;//Forward the Arduino information to another Web server
&nbsp;&nbsp;&#125;
&nbsp;&nbsp;catch (ex)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;console.warn(ex);
&nbsp;&nbsp;&#125;
&#125;);

function colourScale(t)
&#123;//Generate an HTML colour in function of the temperature
&nbsp;&nbsp;if (t &lt;= -25.5) return &#039;0,0,255&#039;;
&nbsp;&nbsp;if (t &lt;= 0) return Math.round(255 + (t * 10)) + &#039;,&#039; + Math.round(255 + (t * 10)) + &#039;,255&#039;;
&nbsp;&nbsp;if (t &lt;= 12.75) return Math.round(255 - (t * 20)) + &#039;,255,&#039; + Math.round(255 - (t * 20));
&nbsp;&nbsp;if (t &lt;= 25.5) return Math.round((t - 12.75) * 20) + &#039;,255,0&#039;;
&nbsp;&nbsp;if (t &lt;= 38.25) return &#039;255,&#039; + Math.round(255 - (t - 25.5) * 20) + &#039;,0&#039;;
&nbsp;&nbsp;return &#039;255,0,0&#039;;
&#125;

function temperatureResponse()
&#123;
&nbsp;&nbsp;return &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&#039;lastTemperatureIndoor&#039;: lastTemperatureIndoor,
&nbsp;&nbsp;&nbsp;&nbsp;&#039;lastTemperatureOutoor&#039;: lastTemperatureOutoor,
&nbsp;&nbsp;&nbsp;&nbsp;&#039;html&#039;: &#039;&lt;!DOCTYPE html&gt;&#92;n&#92;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en-GB&quot; lang=&quot;en-GB&quot;&gt;&#92;n&#92;
&lt;head&gt;&#92;n&#92;
&lt;meta charset=&quot;UTF-8&quot; /&gt;&#92;n&#92;
&lt;meta http-equiv=&quot;refresh&quot; content=&quot;300&quot; /&gt;&#92;n&#92;
&lt;title&gt;Temperature - Arduino - Raspberry Pi&lt;/title&gt;&#92;n&#92;
&lt;meta name=&quot;keywords&quot; content=&quot;Temperature, Arduino, Raspberry Pi&quot; /&gt;&#92;n&#92;
&lt;meta name=&quot;viewport&quot; content=&quot;initial-scale=1.0,width=device-width&quot; /&gt;&#92;n&#92;
&lt;meta name=&quot;geo.position&quot; content=&quot;55.6793;12.4864&quot; /&gt;&#92;n&#92;
&lt;meta name=&quot;geo.region&quot; content=&quot;DK-84&quot; /&gt;&#92;n&#92;
&lt;meta name=&quot;geo.placename&quot; content=&quot;Vanløse&quot; /&gt;&#92;n&#92;
&lt;link rel=&quot;alternate&quot; type=&quot;application/json&quot; href=&quot;temperature.json&quot;/&gt;&#92;n&#92;
&lt;link rel=&quot;author&quot; href=&quot;http://alexandre.alapetite.fr/cv/&quot; title=&quot;Alexandre Alapetite&quot; /&gt;&#92;n&#92;
&lt;meta name=&quot;robots&quot; content=&quot;noindex&quot; /&gt;&#92;n&#92;
&lt;style type=&quot;text/css&quot;&gt;&#92;n&#92;
html, body &#123;background:black; color:white; font-family:sans-serif; text-align:center&#125;&#92;n&#92;
.out &#123;font-size:48pt&#125;&#92;n&#92;
.in &#123;font-size:36pt&#125;&#92;n&#92;
.r, .sb &#123;bottom:0; color:#AAA; position:absolute&#125;&#92;n&#92;
.r &#123;left:0.5em; margin-right:5em; text-align:left&#125;&#92;n&#92;
.sb &#123;right:0.5em&#125;&#92;n&#92;
a &#123;color:#AAA; text-decoration:none&#125;&#92;n&#92;
a:hover &#123;border-bottom:1px dashed&#125;&#92;n&#92;
&lt;/style&gt;&#92;n&#92;
&lt;/head&gt;&#92;n&#92;
&lt;body&gt;&#92;n&#92;
&lt;h1&gt;Temperature at Vanløse&lt;/h1&gt;&#92;n&#92;
&lt;p&gt;Outdoor&lt;br /&gt;&lt;strong class=&quot;out&quot; style=&quot;color:rgb(&#039; + colourScale(lastTemperatureOutoor) + &#039;)&quot;&gt;&#039; + (Math.round(lastTemperatureOutoor * 10) / 10.0) + &#039;°C&lt;/strong&gt;&lt;/p&gt;&#92;n&#92;
&lt;p&gt;Indoor&lt;br /&gt;&lt;strong class=&quot;in&quot; style=&quot;color:rgb(&#039; + colourScale(lastTemperatureIndoor) + &#039;)&quot;&gt;&#039; + (Math.round(lastTemperatureIndoor * 10) / 10.0) + &#039;°C&lt;/strong&gt;&lt;/p&gt;&#92;n&#92;
&lt;p&gt;&#039; + dateLastInfo.toISOString() + &#039;&lt;/p&gt;&#92;n&#92;
&lt;p class=&quot;r&quot;&gt;&lt;a href=&quot;http://alexandre.alapetite.fr/doc-alex/raspberrypi-nodejs-arduino/&quot; title=&quot;Based on&quot;&gt;Arduino + Raspberry Pi&lt;/a&gt;&lt;/p&gt;&#92;n&#92;
&lt;/body&gt;&#92;n&#92;
&lt;/html&gt;&#92;n&#92;
&#039;,
&nbsp;&nbsp;dateLastInfo: dateLastInfo
&nbsp;&nbsp;&#125;;
&#125;

module.exports.temperatureResponse = temperatureResponse;
</textarea><br/><br/>来自：http://alexandre.alapetite.fr/doc-alex/raspberrypi-nodejs-arduino/index.en.html
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] Node.js扩展读取发到上位机Raspberry pi的串口温度数据]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>