source: rtos_arduino/trunk/arduino_lib/libraries/ESP8266/doc/API-html/_h_t_t_p_g_e_t_8ino-example.html@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 9.2 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6<meta name="generator" content="Doxygen 1.8.7"/>
7<title>API: HTTPGET.ino</title>
8<link href="tabs.css" rel="stylesheet" type="text/css"/>
9<script type="text/javascript" src="jquery.js"></script>
10<script type="text/javascript" src="dynsections.js"></script>
11<link href="doxygen.css" rel="stylesheet" type="text/css" />
12</head>
13<body>
14<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
15<div id="titlearea">
16<table cellspacing="0" cellpadding="0">
17 <tbody>
18 <tr style="height: 56px;">
19 <td id="projectlogo"><img alt="Logo" src="ITEAD-logo.JPG"/></td>
20 <td style="padding-left: 0.5em;">
21 <div id="projectname">API
22 </div>
23 <div id="projectbrief">For Arduino developers</div>
24 </td>
25 </tr>
26 </tbody>
27</table>
28</div>
29<!-- end header part -->
30<!-- Generated by Doxygen 1.8.7 -->
31 <div id="navrow1" class="tabs">
32 <ul class="tablist">
33 <li><a href="index.html"><span>Main&#160;Page</span></a></li>
34 <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
35 <li><a href="annotated.html"><span>Classes</span></a></li>
36 <li><a href="files.html"><span>Files</span></a></li>
37 <li><a href="examples.html"><span>Examples</span></a></li>
38 </ul>
39 </div>
40</div><!-- top -->
41<div class="header">
42 <div class="headertitle">
43<div class="title">HTTPGET.ino</div> </div>
44</div><!--header-->
45<div class="contents">
46<p>The HTTPGET demo of library WeeESP8266.</p><dl class="section author"><dt>Author</dt><dd>Wu Pengfei<a href="#" onclick="location.href='mai'+'lto:'+'pen'+'gf'+'ei.'+'wu'+'@it'+'ea'+'d.c'+'c'; return false;">pengf<span style="display: none;">.nosp@m.</span>ei.w<span style="display: none;">.nosp@m.</span>u@ite<span style="display: none;">.nosp@m.</span>ad.c<span style="display: none;">.nosp@m.</span>c</a> </dd></dl>
47<dl class="section date"><dt>Date</dt><dd>2015.03</dd></dl>
48<dl class="section user"><dt>Copyright:</dt><dd>Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. <br />
49<br />
50This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. <br />
51<br />
52THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</dd></dl>
53<div class="fragment"><div class="line"></div>
54<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="_e_s_p8266_8h.html">ESP8266.h</a>&quot;</span></div>
55<div class="line"></div>
56<div class="line"><span class="preprocessor">#define SSID &quot;ITEAD&quot;</span></div>
57<div class="line"><span class="preprocessor">#define PASSWORD &quot;12345678&quot;</span></div>
58<div class="line"><span class="preprocessor">#define HOST_NAME &quot;www.baidu.com&quot;</span></div>
59<div class="line"><span class="preprocessor">#define HOST_PORT (80)</span></div>
60<div class="line"></div>
61<div class="line"><a name="_a0"></a><a class="code" href="class_e_s_p8266.html">ESP8266</a> wifi(Serial1);</div>
62<div class="line"></div>
63<div class="line"><span class="keywordtype">void</span> setup(<span class="keywordtype">void</span>)</div>
64<div class="line">{</div>
65<div class="line"> Serial.begin(9600);</div>
66<div class="line"> Serial.print(<span class="stringliteral">&quot;setup begin\r\n&quot;</span>);</div>
67<div class="line"></div>
68<div class="line"> Serial.print(<span class="stringliteral">&quot;FW Version:&quot;</span>);</div>
69<div class="line"> Serial.println(wifi.<a name="a1"></a><a class="code" href="class_e_s_p8266.html#a4e2d8a0637b437d4b03209cebfa5b750">getVersion</a>().c_str());</div>
70<div class="line"></div>
71<div class="line"> <span class="keywordflow">if</span> (wifi.<a name="a2"></a><a class="code" href="class_e_s_p8266.html#ac179183a46b218609a481747bcfd5a61">setOprToStationSoftAP</a>()) {</div>
72<div class="line"> Serial.print(<span class="stringliteral">&quot;to station + softap ok\r\n&quot;</span>);</div>
73<div class="line"> } <span class="keywordflow">else</span> {</div>
74<div class="line"> Serial.print(<span class="stringliteral">&quot;to station + softap err\r\n&quot;</span>);</div>
75<div class="line"> }</div>
76<div class="line"></div>
77<div class="line"> <span class="keywordflow">if</span> (wifi.<a name="a3"></a><a class="code" href="class_e_s_p8266.html#a300535b4b5f001b74058ebcc694a749f">joinAP</a>(SSID, PASSWORD)) {</div>
78<div class="line"> Serial.print(<span class="stringliteral">&quot;Join AP success\r\n&quot;</span>);</div>
79<div class="line"></div>
80<div class="line"> Serial.print(<span class="stringliteral">&quot;IP:&quot;</span>);</div>
81<div class="line"> Serial.println( wifi.<a name="a4"></a><a class="code" href="class_e_s_p8266.html#a20819d4dabf19fed6e3dcb3fd04ee49d">getLocalIP</a>().c_str()); </div>
82<div class="line"> } <span class="keywordflow">else</span> {</div>
83<div class="line"> Serial.print(<span class="stringliteral">&quot;Join AP failure\r\n&quot;</span>);</div>
84<div class="line"> }</div>
85<div class="line"> </div>
86<div class="line"> <span class="keywordflow">if</span> (wifi.<a name="a5"></a><a class="code" href="class_e_s_p8266.html#a2bc64145329ea45018e956b97ced030a">disableMUX</a>()) {</div>
87<div class="line"> Serial.print(<span class="stringliteral">&quot;single ok\r\n&quot;</span>);</div>
88<div class="line"> } <span class="keywordflow">else</span> {</div>
89<div class="line"> Serial.print(<span class="stringliteral">&quot;single err\r\n&quot;</span>);</div>
90<div class="line"> }</div>
91<div class="line"> </div>
92<div class="line"> Serial.print(<span class="stringliteral">&quot;setup end\r\n&quot;</span>);</div>
93<div class="line">}</div>
94<div class="line"> </div>
95<div class="line"><span class="keywordtype">void</span> loop(<span class="keywordtype">void</span>)</div>
96<div class="line">{</div>
97<div class="line"> uint8_t buffer[1024] = {0};</div>
98<div class="line"></div>
99<div class="line"> <span class="keywordflow">if</span> (wifi.<a name="a6"></a><a class="code" href="class_e_s_p8266.html#aa927b7b8aaef163011015c22da1f07e2">createTCP</a>(HOST_NAME, HOST_PORT)) {</div>
100<div class="line"> Serial.print(<span class="stringliteral">&quot;create tcp ok\r\n&quot;</span>);</div>
101<div class="line"> } <span class="keywordflow">else</span> {</div>
102<div class="line"> Serial.print(<span class="stringliteral">&quot;create tcp err\r\n&quot;</span>);</div>
103<div class="line"> }</div>
104<div class="line"></div>
105<div class="line"> <span class="keywordtype">char</span> *hello = <span class="stringliteral">&quot;GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n&quot;</span>;</div>
106<div class="line"> wifi.<a name="a7"></a><a class="code" href="class_e_s_p8266.html#a6ba21b921a7afc79a36d0e41c20d59bc">send</a>((<span class="keyword">const</span> uint8_t*)hello, strlen(hello));</div>
107<div class="line"></div>
108<div class="line"> uint32_t len = wifi.<a name="a8"></a><a class="code" href="class_e_s_p8266.html#af8ce40bd14556bcfb5d4c521047fc821">recv</a>(buffer, <span class="keyword">sizeof</span>(buffer), 10000);</div>
109<div class="line"> <span class="keywordflow">if</span> (len &gt; 0) {</div>
110<div class="line"> Serial.print(<span class="stringliteral">&quot;Received:[&quot;</span>);</div>
111<div class="line"> <span class="keywordflow">for</span>(uint32_t i = 0; i &lt; len; i++) {</div>
112<div class="line"> Serial.print((<span class="keywordtype">char</span>)buffer[i]);</div>
113<div class="line"> }</div>
114<div class="line"> Serial.print(<span class="stringliteral">&quot;]\r\n&quot;</span>);</div>
115<div class="line"> }</div>
116<div class="line"></div>
117<div class="line"> <span class="keywordflow">if</span> (wifi.<a name="a9"></a><a class="code" href="class_e_s_p8266.html#ac15ce9df69dc566c37b3fa2c3c869337">releaseTCP</a>()) {</div>
118<div class="line"> Serial.print(<span class="stringliteral">&quot;release tcp ok\r\n&quot;</span>);</div>
119<div class="line"> } <span class="keywordflow">else</span> {</div>
120<div class="line"> Serial.print(<span class="stringliteral">&quot;release tcp err\r\n&quot;</span>);</div>
121<div class="line"> }</div>
122<div class="line"> </div>
123<div class="line"> <span class="keywordflow">while</span>(1);</div>
124<div class="line"> </div>
125<div class="line">}</div>
126<div class="line"> </div>
127</div><!-- fragment --> </div><!-- contents -->
128<!-- start footer part -->
129<hr class="footer"/><address class="footer"><small>
130Generated on Tue Mar 17 2015 10:34:17 for API by &#160;<a href="http://www.doxygen.org/index.html">
131<img class="footer" src="doxygen.png" alt="doxygen"/>
132</a> 1.8.7
133</small></address>
134</body>
135</html>
Note: See TracBrowser for help on using the repository browser.