123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta http-equiv="Content-Style-Type" content="text/css" />
- <meta name="generator" content="pandoc" />
- <title></title>
- <style type="text/css">code{white-space: pre;}</style>
- <style type="text/css">
- div.sourceCode { overflow-x: auto; }
- table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
- margin: 0; padding: 0; vertical-align: baseline; border: none; }
- table.sourceCode { width: 100%; line-height: 100%; }
- td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
- td.sourceCode { padding-left: 5px; }
- code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
- code > span.dt { color: #902000; } /* DataType */
- code > span.dv { color: #40a070; } /* DecVal */
- code > span.bn { color: #40a070; } /* BaseN */
- code > span.fl { color: #40a070; } /* Float */
- code > span.ch { color: #4070a0; } /* Char */
- code > span.st { color: #4070a0; } /* String */
- code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
- code > span.ot { color: #007020; } /* Other */
- code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
- code > span.fu { color: #06287e; } /* Function */
- code > span.er { color: #ff0000; font-weight: bold; } /* Error */
- code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
- code > span.cn { color: #880000; } /* Constant */
- code > span.sc { color: #4070a0; } /* SpecialChar */
- code > span.vs { color: #4070a0; } /* VerbatimString */
- code > span.ss { color: #bb6688; } /* SpecialString */
- code > span.im { } /* Import */
- code > span.va { color: #19177c; } /* Variable */
- code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
- code > span.op { color: #666666; } /* Operator */
- code > span.bu { } /* BuiltIn */
- code > span.ex { } /* Extension */
- code > span.pp { color: #bc7a00; } /* Preprocessor */
- code > span.at { color: #7d9029; } /* Attribute */
- code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
- code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
- code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
- code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
- </style>
- <link rel="stylesheet" href="css/vendor.css" type="text/css" />
- </head>
- <body>
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wb="http://open.weibo.com/wb" >
- <head>
- <title>一步步搭建物联网系统(教你设计物联网系统)</title>
- <meta name="keywords" content="设计物联网系统,物联网系统设计">
- <meta name="description" content="一份关于如何设计物联网系统的文档">
- <link rel="stylesheet" href="../css/vendor.css" />
- </head>
- <body class="container inner wrap">
- <h1>一步步搭建物联网系统(教你设计物联网系统)</h1>
- </body>
- </html>
- <div id="TOC">
- <ul>
- <li><a href="#使用iot-coap构建物联网"><span class="toc-section-number">0.1</span> 使用IoT-CoAP构建物联网</a></li>
- </ul>
- </div>
- <h2 id="使用iot-coap构建物联网"><span class="header-section-number">0.1</span> 使用IoT-CoAP构建物联网</h2>
- <p>(<code>注意</code>:windows系统npm install失败时,需要自己建立一个C:and Settings[USERNAME]Data文件)</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">npm</span> install iot-coap</code></pre></div>
- <p>1.新建<strong>index.js</strong></p>
- <p><code>注意</code>: 如果已经存在一个index.js文件,请将下面内容添加到文件末尾(create index.js, and add)</p>
- <div class="sourceCode"><pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="kw">var</span> iotcoap <span class="op">=</span> <span class="at">require</span>(<span class="st">'iot-coap'</span>)<span class="op">;</span>
- <span class="va">iotcoap</span>.<span class="at">run</span>()<span class="op">;</span>
- <span class="va">iotcoap</span>.<span class="va">rest</span>.<span class="at">run</span>()<span class="op">;</span></code></pre></div>
- <p><code>注意</code>:在db配置可以选择mongodb和sqlite3,替换所需要的数据库即可。(you can choice db on iot.js with ‘sqlite’ or ‘mongodb’)</p>
- <p>2.创建<strong>iot.js</strong></p>
- <div class="sourceCode"><pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="va">exports</span>.<span class="at">config</span> <span class="op">=</span> <span class="op">{</span>
- <span class="st">"db_name"</span><span class="op">:</span> <span class="st">"iot.db"</span><span class="op">,</span>
- <span class="st">"mongodb_name"</span><span class="op">:</span> <span class="st">"iot"</span><span class="op">,</span>
- <span class="st">"mongodb_documents"</span><span class="op">:</span> <span class="st">"iot"</span><span class="op">,</span>
- <span class="st">"db"</span><span class="op">:</span> <span class="st">"mongodb"</span><span class="op">,</span>
- <span class="st">"table_name"</span><span class="op">:</span> <span class="st">"basic"</span><span class="op">,</span>
- <span class="st">"keys"</span><span class="op">:</span>[
- <span class="st">"id"</span><span class="op">,</span>
- <span class="st">"value"</span><span class="op">,</span>
- <span class="st">"sensors1"</span><span class="op">,</span>
- <span class="st">"sensors2"</span>
- ]<span class="op">,</span>
- <span class="st">"db_table"</span><span class="op">:</span> <span class="st">"id integer primary key, value text, sensors1 float, sensors2 float"</span><span class="op">,</span>
- <span class="st">"mongodb_init"</span><span class="op">:</span>[
- <span class="op">{</span>
- <span class="dt">id</span><span class="op">:</span> <span class="dv">1</span><span class="op">,</span>
- <span class="dt">value</span><span class="op">:</span> <span class="st">"is id 1"</span><span class="op">,</span>
- <span class="dt">sensors1</span><span class="op">:</span> <span class="dv">19</span><span class="op">,</span>
- <span class="dt">sensors2</span><span class="op">:</span> <span class="dv">20</span>
- <span class="op">},</span>
- <span class="op">{</span>
- <span class="dt">id</span><span class="op">:</span> <span class="dv">2</span><span class="op">,</span>
- <span class="dt">value</span><span class="op">:</span> <span class="st">"is id 2"</span><span class="op">,</span>
- <span class="dt">sensors1</span><span class="op">:</span> <span class="dv">20</span><span class="op">,</span>
- <span class="dt">sensors2</span><span class="op">:</span> <span class="dv">21</span>
- <span class="op">}</span>
- ]<span class="op">,</span>
- <span class="st">"init_table"</span><span class="op">:</span>[
- <span class="st">"insert or replace into basic (id,value,sensors1,sensors2) VALUES (1, 'is id 1', 19, 20);"</span><span class="op">,</span>
- <span class="st">"insert or replace into basic (id,value,sensors1,sensors2) VALUES (2, 'is id 2', 20, 21);"</span>
- ]<span class="op">,</span>
- <span class="st">"query_table"</span><span class="op">:</span><span class="st">"select * from basic;"</span><span class="op">,</span>
- <span class="st">"rest_url"</span><span class="op">:</span> <span class="st">"/id/:id"</span><span class="op">,</span>
- <span class="st">"rest_post_url"</span><span class="op">:</span> <span class="st">"/"</span><span class="op">,</span>
- <span class="st">"rest_port"</span><span class="op">:</span> <span class="dv">8848</span>
- <span class="op">};</span></code></pre></div>
- <p>3.运行(run)</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">node</span> index.js</code></pre></div>
- <p>show:</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">coap</span> listening at coap://0.0.0.0:5683
- <span class="kw">restify</span> listening at http://0.0.0.0:8848</code></pre></div>
- </body>
- </html>
|