123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <!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="#环境准备"><span class="toc-section-number">1</span> 环境准备</a><ul>
- <li><a href="#laravel"><span class="toc-section-number">1.1</span> Laravel</a><ul>
- <li><a href="#为什么是-laravel"><span class="toc-section-number">1.1.1</span> 为什么是 Laravel</a></li>
- </ul></li>
- <li><a href="#安装-laravel"><span class="toc-section-number">1.2</span> 安装 Laravel</a><ul>
- <li><a href="#gnulinux安装composer"><span class="toc-section-number">1.2.1</span> GNU/Linux安装Composer</a></li>
- </ul></li>
- <li><a href="#mysql"><span class="toc-section-number">1.3</span> MySQL</a><ul>
- <li><a href="#安装mysql"><span class="toc-section-number">1.3.1</span> 安装MySQL</a></li>
- <li><a href="#配置mysql"><span class="toc-section-number">1.3.2</span> 配置MySQL</a></li>
- </ul></li>
- </ul></li>
- </ul>
- </div>
- <h1 id="环境准备"><span class="header-section-number">1</span> 环境准备</h1>
- <h2 id="laravel"><span class="header-section-number">1.1</span> Laravel</h2>
- <blockquote>
- <p>Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。</p>
- </blockquote>
- <ul>
- <li>RESTful 路由: 通过简单的闭包就能响应HTTP请求。帮你快速开始构建非凡的应用。</li>
- <li>强大的数据操纵能力: Laravel自带了强大的Eloquent ORM 和迁移工具。能够完美的与MySQL、Postgres、SQL Server 和 SQLite协同工作。</li>
- <li>优雅的模版引擎: PHP代码或轻量级的Blade模版引擎都可无缝融合。Blade模版可以继承,并且拥有极快的解析速度。相信你会喜欢它的。</li>
- <li>为明天做准备: 构建大型的企业级应用或者只是提供简单的JSON API;书写强大的控制器或轻巧的RESTful路由,Laravel适应所有级别的开发工作。</li>
- <li>可靠的基石: Laravel 的基石是数个Symfony组件,这些经过千锤百炼、可靠的组件为你的应用提供坚实的基础。</li>
- <li>基于Composer管理器: Composer 是一套帮你管理第三方扩展包的工具。能够让你迅速在 Packagist 中找到需要的扩展包。</li>
- <li>强大的社区支持: 无论你是一个PHP新手还是经验丰富的架构师,都能在社区中找到需要的知识。你可以在IRC中讨论Idea,或者在论坛中发布问题。</li>
- <li>测试、重构: Laravel 从开始就将测试作为重点功能。我们提供了灵活的IoC容器,集成了PHPUnit 测试工具。不用担心,这些都很容易上手。</li>
- </ul>
- <h3 id="为什么是-laravel"><span class="header-section-number">1.1.1</span> 为什么是 Laravel</h3>
- <ul>
- <li>因为个人喜爱,你也可以用 Ruby On Rails来搭建这样一个功能,或者是Java。</li>
- <li>PHP在我的服务器上运行得挺不错的,而且我又不需要重新去写配置那些配置。</li>
- <li>Laravel 可以简单的开发我们所需要的功能,换句话说他是 PHP 世界的 Ruby On Rails。</li>
- </ul>
- <p>这里不会再重述之前的问题,这里只是将需要的步骤一个个写下来,然后丢到这里好好说一下。至于RESTful是什么,前面已经介绍了,就不再重复了。那么下面,我们就用Laravel来搭建一个平台给物联网用的。</p>
- <h2 id="安装-laravel"><span class="header-section-number">1.2</span> 安装 Laravel</h2>
- <h3 id="gnulinux安装composer"><span class="header-section-number">1.2.1</span> GNU/Linux安装Composer</h3>
- <p>GNU/Linux Ubuntu/OpenSUSE下可以执行</p>
- <pre><code>$ curl -sS https://getcomposer.org/installer | php</code></pre>
- <h4 id="windows安装composer"><span class="header-section-number">1.2.1.1</span> Windows安装Composer</h4>
- <p>请直接下载</p>
- <p><a href="https://getcomposer.org/Composer-Setup.exe">Composer-Setup</a></p>
- <h4 id="mac-os"><span class="header-section-number">1.2.1.2</span> Mac OS</h4>
- <p>1.安装Composer</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">brew</span> install homebrew/php/composer</code></pre></div>
- <p>2.安装Laravel</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">composer</span> global require <span class="st">"laravel/installer=~1.1"</span></code></pre></div>
- <p>3.创建Laravel工程</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">composer</span> create-project laravel/laravel your-project-name --prefer-dist </code></pre></div>
- <h4 id="mac-os-1"><span class="header-section-number">1.2.1.3</span> Mac OS</h4>
- <p>1.下载laravel.phar</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">wget</span> http://laravel.com/laravel.phar</code></pre></div>
- <p>2.重命名</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">mv</span> laravel.phar laravel</code></pre></div>
- <p>3.移动到bin中</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">sudo</span> mv laravel /usr/local/bin</code></pre></div>
- <p>4.创建项目</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">laravel</span> new blog</code></pre></div>
- <h2 id="mysql"><span class="header-section-number">1.3</span> MySQL</h2>
- <h3 id="安装mysql"><span class="header-section-number">1.3.1</span> 安装MySQL</h3>
- <p><code>出于某些原因,我建议用MariaDB替换MySQL,如果你"真正"需要mysql,将mariadb替换为mysql</code></p>
- <p>ps: 在下文中我会继续用MySQL,而不是MariaDB,MairaDB是MySQL的一个分支,真正的开源分支。</p>
- <p>Ubuntu/Debian/Mint</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> apt-get install mariadb-server</code></pre></div>
- <p>Fedora/Centos</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> yum install mariadb-server </code></pre></div>
- <p>openSUSE</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">sudo</span> zypper install mariadb-server</code></pre></div>
- <p>Mac OS</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">brew</span> install mariadb</code></pre></div>
- <h3 id="配置mysql"><span class="header-section-number">1.3.2</span> 配置MySQL</h3>
- <p>修改database.php</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="kw">app/config/database.php</span></code></pre></div>
- <p>要修改的就是这个</p>
- <div class="sourceCode"><pre class="sourceCode php"><code class="sourceCode php"><span class="st">'mysql'</span> => <span class="fu">array</span><span class="ot">(</span>
- <span class="st">'driver'</span> => <span class="st">'mysql'</span><span class="ot">,</span>
- <span class="st">'host'</span> => <span class="st">'localhost'</span><span class="ot">,</span>
- <span class="st">'database'</span> => <span class="st">'iot'</span><span class="ot">,</span>
- <span class="st">'username'</span> => <span class="st">'root'</span><span class="ot">,</span>
- <span class="st">'password'</span> => <span class="st">'940217'</span><span class="ot">,</span>
- <span class="st">'charset'</span> => <span class="st">'utf8'</span><span class="ot">,</span>
- <span class="st">'collation'</span> => <span class="st">'utf8_unicode_ci'</span><span class="ot">,</span>
- <span class="st">'prefix'</span> => <span class="st">''</span><span class="ot">,</span>
- <span class="ot">),</span></code></pre></div>
- <p>如果你已经有phpmyadmin,似乎对你来说已经很简单了,如果没有的话,就直接用</p>
- <div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">mysql</span> -uroot -p</code></pre></div>
- <p>来创建一个新的</p>
- <div class="sourceCode"><pre class="sourceCode sql"><code class="sourceCode sql"><span class="kw">CREATE</span> <span class="kw">DATABASE</span> <span class="kw">IF</span> <span class="kw">NOT</span> <span class="kw">EXISTS</span> iot <span class="kw">default</span> charset utf8 COLLATE utf8_general_ci;</code></pre></div>
- <p>数据库的目的在于存储数据等等的闲话这里就不多说了,创建一个RESTful的目的在于产生下面的JSON格式数据,以便于我们在Android、Java、Python、jQuery等语言框架或者平台上可以调用,最主要的是可以直接用Ajax来产生更炫目的效果。</p>
- <div class="sourceCode"><pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="op">{</span>
- <span class="st">"id"</span><span class="op">:</span> <span class="dv">1</span><span class="op">,</span>
- <span class="st">"temperature"</span><span class="op">:</span> <span class="dv">14</span><span class="op">,</span>
- <span class="st">"sensors1"</span><span class="op">:</span> <span class="dv">12</span><span class="op">,</span>
- <span class="st">"sensors2"</span><span class="op">:</span> <span class="dv">12</span><span class="op">,</span>
- <span class="st">"led1"</span><span class="op">:</span> <span class="dv">0</span>
- <span class="op">}</span></code></pre></div>
- </body>
- </html>
|