1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Add 2.1.0-rc2

This commit is contained in:
Ivan Grokhotkov 2016-01-24 22:41:20 +03:00
parent 81afdf8618
commit 22261cf2c4
62 changed files with 7713 additions and 0 deletions

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="139" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="139" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h56v20H0z"/><path fill="#007ec6" d="M56 0h83v20H56z"/><path fill="url(#b)" d="M0 0h139v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="28" y="15" fill="#010101" fill-opacity=".3">updated</text><text x="28" y="14">updated</text><text x="96.5" y="15" fill="#010101" fill-opacity=".3">Jan 24, 2016</text><text x="96.5" y="14">Jan 24, 2016</text></g></svg>

After

Width:  |  Height:  |  Size: 752 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -0,0 +1,360 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
Debugging &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#introduction">Introduction</a>
<ul>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#Usage">Usage</a></li>
</ul></li>
<li><a href="#Informations">Informations</a>
<ul>
<li><a href="#for-developers">For Developers</a></li>
</ul></li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>Since 2.1.0-rc1 the core includes a Debugging feature that is controllable over the IDE menu.</p>
<p>The new menu points manage the real-time Debug messages.</p>
<h3 id="requirements">Requirements</h3>
<p>For usage of the debugging a Serial connection is required (Serial or Serial1).</p>
<p>The Serial Interface need to be initialized in the <code>setup()</code>.</p>
<p>Set the Serial baud rate as high as possible for your Hardware setup.</p>
<p>Minimum sketch to use debugging:
```cpp
void setup() {
Serial.begin(115200);
}</p>
<p>void loop() {
}
```</p>
<h3 id="usage">Usage</h3>
<ol>
<li><p>Select the Serial interface for the Debugging messages:
<img src="debug_port.png" alt="Debug-Port"></p></li>
<li><p>Select which type / level you want debug messages for:
<img src="debug_level.png" alt="Debug-Level"></p></li>
<li><p>Check if the Serial interface is initialized in <code>setup()</code> (see <a href="#requirements">Requirements</a>)</p></li>
<li><p>Flash sketch</p></li>
<li><p>Check the Serial Output</p></li>
</ol>
<h2 id="informations">Informations</h2>
<p>It work with every sketch that enables the Serial interface that is selected as debug port.</p>
<p>The Serial interface can still be used normal in the Sketch.</p>
<p>The debug output is additional and will not disable any interface from usage in the sketch.</p>
<h3 id="for-developers">For Developers</h3>
<p>For the debug handling uses defines.</p>
<p>The defined are set by command line.</p>
<h4 id="debug-port">Debug Port</h4>
<p>The port has the define <code>DEBUG_ESP_PORT</code> possible value:
- Disabled: define not existing
- Serial: Serial
- Serial1: Serial1</p>
<h4 id="debug-level">Debug Level</h4>
<p>All defines for the different levels starts with <code>DEBUG_ESP_</code></p>
<p>a full list can be found here in the <a href="https://github.com/esp8266/Arduino/blob/master/boards.txt#L180">boards.txt</a></p>
<h4 id="example-for-own-debug-messages">Example for own debug messages</h4>
<p>The debug messages will be only shown when the Debug Port in the IDE menu is set.</p>
<div class="highlight"><pre><code class="language-cpp" data-lang="cpp"><span class="cp">#ifdef DEBUG_ESP_PORT</span>
<span class="cp">#define DEBUG_MSG(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )</span>
<span class="cp">#else</span>
<span class="cp">#define DEBUG_MSG(...) </span>
<span class="cp">#endif</span>
<span class="kt">void</span> <span class="nf">setup</span><span class="p">()</span> <span class="p">{</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">begin</span><span class="p">(</span><span class="mi">115200</span><span class="p">);</span>
<span class="n">delay</span><span class="p">(</span><span class="mi">3000</span><span class="p">);</span>
<span class="n">DEBUG_MSG</span><span class="p">(</span><span class="s">&quot;bootup...</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">loop</span><span class="p">()</span> <span class="p">{</span>
<span class="n">DEBUG_MSG</span><span class="p">(</span><span class="s">&quot;loop %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">millis</span><span class="p">());</span>
<span class="n">delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div>
</div>
</body>
</html>

View File

@ -0,0 +1,732 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
Supported Hardware &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<div id="toc"></div>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="table-of-contents">Table of contents</h2>
<ul>
<li><a href="#adafruit-huzzah-esp8266-esp-12">Adafruit HUZZAH ESP8266 (ESP-12)</a></li>
<li><a href="#nodemcu-09-">NodeMCU 0.9 <a name="user\-content\-nodemcu\-0\-9"></a></a>
<ul>
<li><a href="#pin-mapping">Pin mapping</a></li>
</ul></li>
<li><a href="#nodemcu-10">NodeMCU 1.0</a></li>
<li><a href="#olimex-mod-wifi-esp8266-dev">Olimex MOD-WIFI-ESP8266-DEV</a></li>
<li><a href="#olimex-mod-wifi-esp8266">Olimex MOD-WIFI-ESP8266</a></li>
<li><a href="#sparkfun-esp8266-thing">SparkFun ESP8266 Thing</a></li>
<li><a href="#sweetpea-esp-210">SweetPea ESP-210</a></li>
<li><a href="#espino">ESPino</a></li>
<li><a href="#WifInfo">WifInfo</a></li>
<li><a href="#generic-esp8266-modules">Generic ESP8266 modules</a></li>
<li><a href="#serial-adapter">Serial Adapter</a></li>
<li><a href="#minimal-hardware-setup-for-bootloading-and-usage">Minimal Hardware Setup for Bootloading and Usage</a></li>
<li><a href="#esp-to-serial">ESP to Serial</a>
<ul>
<li><a href="#minimal-hardware-setup-for-bootloading-only">Minimal Hardware Setup for Bootloading only</a></li>
<li><a href="#minimal-hardware-setup-for-running-only">Minimal Hardware Setup for Running only</a></li>
</ul></li>
<li><a href="#minimal">Minimal</a></li>
<li><a href="#improved-stability">Improved Stability</a></li>
<li><a href="#boot-messages-and-modes">Boot Messages and Modes</a>
<ul>
<li><a href="#rst-cause">rst cause</a></li>
<li><a href="#boot-mode">boot mode</a></li>
</ul></li>
<li><a href="#wemos-d1">WeMos D1</a></li>
<li><a href="#wemos-d1-mini">WeMos D1 mini</a></li>
</ul>
<h2 id="adafruit-huzzah-esp8266-esp-12">Adafruit HUZZAH ESP8266 (ESP-12)</h2>
<p><em>TODO: add notes</em></p>
<h2 id="nodemcu-0-9">NodeMCU 0.9</h2>
<h3 id="pin-mapping">Pin mapping</h3>
<p>Pin numbers written on the board itself do not correspond to ESP8266 GPIO pin numbers. Constants are defined to make using this board easier:</p>
<div class="highlight"><pre><code class="language-C++" data-lang="C++"><span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D0</span> <span class="o">=</span> <span class="mi">16</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D1</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D2</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D3</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D4</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D5</span> <span class="o">=</span> <span class="mi">14</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D6</span> <span class="o">=</span> <span class="mi">12</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D7</span> <span class="o">=</span> <span class="mi">13</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D8</span> <span class="o">=</span> <span class="mi">15</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D9</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span>
<span class="k">static</span> <span class="k">const</span> <span class="kt">uint8_t</span> <span class="n">D10</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
</code></pre></div>
<p>If you want to use NodeMCU pin 5, use D5 for pin number, and it will be translated to &#39;real&#39; GPIO pin 14.</p>
<h2 id="nodemcu-1-0">NodeMCU 1.0</h2>
<p>This module is sold under many names for around $6.50 on AliExpress and it&#39;s one of the cheapest, fully integrated ESP8266 solutions.</p>
<p>It&#39;s an open hardware design with an ESP-12E core and 4 MB of SPI flash.</p>
<p>Acording to the manufacturer, &quot;with a micro USB cable, you can connect NodeMCU devkit to your laptop and flash it without any trouble&quot;. This is more or less true: the board comes with a CP2102 onboard USB to serial adapter which just works, well, the majority of the time. Sometimes flashing fails and you have to reset the board by holding down FLASH + RST, then releasing FLASH, then releasing RST. This forces the CP2102 device to power cycle and to be re-numbered by Linux.</p>
<p>The board also features a NCP1117 voltage regulator, a blue LED on GPIO16 and a 220k/100k Ohm voltage divider on the ADC input pin.</p>
<p>Full pinout and PDF schematics can be found <a href="https://github.com/nodemcu/nodemcu-devkit-v1.0">here</a></p>
<h2 id="olimex-mod-wifi-esp8266-dev">Olimex MOD-WIFI-ESP8266-DEV</h2>
<p>This board comes with 2 MB of SPI flash and optional accessories (e.g. evaluation board ESP8266-EVB or BAT-BOX for batteries).</p>
<p>The basic module has three solder jumpers that allow you to switch the operating mode between SDIO, UART and FLASH.</p>
<p>The board is shipped for FLASH operation mode, with jumpers TD0JP=0, IO0JP=1, IO2JP=1.</p>
<p>Since jumper IO0JP is tied to GPIO0, which is PIN 21, you&#39;ll have to ground it before programming with a USB to serial adapter and reset the board by power cycling it.</p>
<p>UART pins for programming and serial I/O are GPIO1 (TXD, pin 3) and GPIO3 (RXD, pin 4).</p>
<p>Get the board schematics <a href="https://github.com/OLIMEX/ESP8266/blob/master/HARDWARE/MOD-WIFI-ESP8266-DEV/MOD-WIFI-ESP8266-DEV_schematic.pdf">here</a></p>
<h2 id="olimex-mod-wifi-esp8266">Olimex MOD-WIFI-ESP8266</h2>
<p>This is a stripped down version of the above. Behaves identically in terms of jumpers but has less pins readily available for I/O. Still 2 MB of SPI flash.</p>
<h2 id="sparkfun-esp8266-thing">SparkFun ESP8266 Thing</h2>
<p>Product page: <a href="https://www.sparkfun.com/products/13231">https://www.sparkfun.com/products/13231</a></p>
<p><em>TODO: add notes</em></p>
<h2 id="sweetpea-esp-210">SweetPea ESP-210</h2>
<p><em>TODO: add notes</em></p>
<h2 id="espino">ESPino</h2>
<p>ESPino integrates the ESP-12 module with a 3.3v regulator, CP2104 USB-Serial bridge and a micro USB connector for easy programming. It is designed for fitting in a breadboard and has an RGB Led and two buttons for easy prototyping.</p>
<p>For more information about the hardware, pinout diagram and programming procedures, please see the <a href="https://github.com/makerlabmx/ESPino-tools/raw/master/Docs/ESPino-Datasheet-EN.pdf">datasheet</a>.</p>
<p>Product page: <a href="http://www.espino.io/en">http://www.espino.io/en</a></p>
<h2 id="wifinfo">WifInfo</h2>
<p>WifInfo integrates the ESP-12 or ESP-07+Ext antenna module with a 3.3v regulator and the hardware to be able to measure French telemetry issue from ERDF powering meter serial output. It has a USB connector for powering, an RGB WS2812 Led, 4 pins I2C connector to fit OLED or sensor, and two buttons + FTDI connector and auto reset feature.</p>
<p>For more information, please see WifInfo related <a href="http://hallard.me/category/wifinfo/">blog</a> entries, <a href="https://github.com/hallard/WifInfo">github</a> and <a href="https://community.hallard.me/category/16/wifinfo">community</a> forum.</p>
<h2 id="generic-esp8266-modules">Generic ESP8266 modules</h2>
<p>These modules come in different form factors and pinouts. See the page at ESP8266 community wiki for more info:
<a href="http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family">ESP8266 Module Family</a>.</p>
<p>Usually these modules have no bootstapping resistors on board, insufficient decoupling capacitors, no voltage regulator, no reset circuit, and no USB-serial adapter. This makes using them somewhat tricky, compared to development boards which add these features.</p>
<p>In order to use these modules, make sure to observe the following:</p>
<ul>
<li><p><strong>Provide sufficient power to the module.</strong> For stable use of the ESP8266 a power supply with 3.3V and &gt;= 250mA is required. Using the power available from USB to Serial adapter is not recommended, these adapters typically do not supply enough current to run ESP8266 reliably in every situation. An external supply or regulator along with filtering capacitors is preferred.</p></li>
<li><p><strong>Connect bootstapping resistors</strong> to GPIO0, GPIO2, GPIO15 according to the schematics below.</p></li>
<li><p><strong>Put ESP8266 into bootloader mode</strong> before uploading code.</p></li>
</ul>
<h2 id="serial-adapter">Serial Adapter</h2>
<p>There are many different USB to Serial adapters / boards.
To be able to put ESP8266 into bootloader mode using serial handshaking lines, you need the adapter which breaks out RTS and DTR outputs. CTS and DSR are not useful for upload (they are inputs). Make sure the adapter can work with 3.3V IO voltage: it should have a jumper or a switch to select between 5V and 3.3V, or be marked as 3.3V only.</p>
<p>Adapters based around the following ICs should work:</p>
<ul>
<li>FT232RL</li>
<li>CP2102</li>
<li>CH340G</li>
</ul>
<p>PL2303-based adapters are known not to work on Mac OS X. See <a href="https://github.com/igrr/esptool-ck/issues/9">https://github.com/igrr/esptool-ck/issues/9</a> for more info.</p>
<h2 id="minimal-hardware-setup-for-bootloading-and-usage">Minimal Hardware Setup for Bootloading and Usage</h2>
<table><thead>
<tr>
<th>PIN</th>
<th>Resistor</th>
<th>Serial Adapter</th>
</tr>
</thead><tbody>
<tr>
<td>VCC</td>
<td></td>
<td>VCC (3.3V)</td>
</tr>
<tr>
<td>GND</td>
<td></td>
<td>GND</td>
</tr>
<tr>
<td>TX or GPIO2*</td>
<td></td>
<td>RX</td>
</tr>
<tr>
<td>RX</td>
<td></td>
<td>TX</td>
</tr>
<tr>
<td>GPIO0</td>
<td>PullUp</td>
<td>DTR</td>
</tr>
<tr>
<td>Reset*</td>
<td>PullUp</td>
<td>RTS</td>
</tr>
<tr>
<td>GPIO15*</td>
<td>PullDown</td>
<td></td>
</tr>
<tr>
<td>CH_PD</td>
<td>PullUp</td>
<td></td>
</tr>
</tbody></table>
<ul>
<li>Note
<ul>
<li>GPIO15 is also named MTDO</li>
<li>Reset is also named RSBT or REST (adding PullUp improves the stability of the module)</li>
<li>GPIO2 is alternative TX for the boot loader mode</li>
<li><strong>Directly connecting a pin to VCC or GND is not a substitute for a PullUp or PullDown resistor, doing this can break upload management and the serial console, instability has also been noted in some cases.</strong></li>
</ul></li>
</ul>
<h2 id="esp-to-serial">ESP to Serial</h2>
<p><img src="ESP_to_serial.png" alt="ESP to Serial"></p>
<h3 id="minimal-hardware-setup-for-bootloading-only">Minimal Hardware Setup for Bootloading only</h3>
<p>ESPxx Hardware</p>
<table><thead>
<tr>
<th>PIN</th>
<th>Resistor</th>
<th>Serial Adapter</th>
</tr>
</thead><tbody>
<tr>
<td>VCC</td>
<td></td>
<td>VCC (3.3V)</td>
</tr>
<tr>
<td>GND</td>
<td></td>
<td>GND</td>
</tr>
<tr>
<td>TX or GPIO2</td>
<td></td>
<td>RX</td>
</tr>
<tr>
<td>RX</td>
<td></td>
<td>TX</td>
</tr>
<tr>
<td>GPIO0</td>
<td></td>
<td>GND</td>
</tr>
<tr>
<td>Reset</td>
<td></td>
<td>RTS*</td>
</tr>
<tr>
<td>GPIO15</td>
<td>PullDown</td>
<td></td>
</tr>
<tr>
<td>CH_PD</td>
<td>PullUp</td>
<td></td>
</tr>
</tbody></table>
<ul>
<li>Note
<ul>
<li>if no RTS is used a manual power toggle is needed</li>
</ul></li>
</ul>
<h3 id="minimal-hardware-setup-for-running-only">Minimal Hardware Setup for Running only</h3>
<p>ESPxx Hardware</p>
<table><thead>
<tr>
<th>PIN</th>
<th>Resistor</th>
<th>Power supply</th>
</tr>
</thead><tbody>
<tr>
<td>VCC</td>
<td></td>
<td>VCC (3.3V)</td>
</tr>
<tr>
<td>GND</td>
<td></td>
<td>GND</td>
</tr>
<tr>
<td>GPIO0</td>
<td>PullUp</td>
<td></td>
</tr>
<tr>
<td>GPIO15</td>
<td>PullDown</td>
<td></td>
</tr>
<tr>
<td>CH_PD</td>
<td>PullUp</td>
<td></td>
</tr>
</tbody></table>
<h2 id="minimal">Minimal</h2>
<p><img src="ESP_min.png" alt="ESP min"></p>
<h2 id="improved-stability">Improved Stability</h2>
<p><img src="ESP_improved_stability.png" alt="ESP improved stability"></p>
<h2 id="boot-messages-and-modes">Boot Messages and Modes</h2>
<p>The ESP module checks at every boot the Pins 0, 2 and 15.
based on them its boots in different modes:</p>
<table><thead>
<tr>
<th>GPIO15</th>
<th>GPIO0</th>
<th>GPIO2</th>
<th>Mode</th>
</tr>
</thead><tbody>
<tr>
<td>0V</td>
<td>0V</td>
<td>3.3V</td>
<td>Uart Bootloader</td>
</tr>
<tr>
<td>0V</td>
<td>3.3V</td>
<td>3.3V</td>
<td>Boot sketch (SPI flash)</td>
</tr>
<tr>
<td>3.3V</td>
<td>x</td>
<td>x</td>
<td>SDIO mode (not used for Arduino)</td>
</tr>
</tbody></table>
<p>at startup the ESP prints out the current boot mode example:
<code>
rst cause:2, boot mode:(3,6)
</code></p>
<p>note:
- GPIO2 is used as TX output and the internal Pullup is enabled on boot.</p>
<h3 id="rst-cause">rst cause</h3>
<table><thead>
<tr>
<th>Number</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr>
<td>0</td>
<td>unknown</td>
</tr>
<tr>
<td>1</td>
<td>normal boot</td>
</tr>
<tr>
<td>2</td>
<td>reset pin</td>
</tr>
<tr>
<td>3</td>
<td>software reset</td>
</tr>
<tr>
<td>4</td>
<td>watchdog reset</td>
</tr>
</tbody></table>
<h3 id="boot-mode">boot mode</h3>
<p>the first value respects the pin setup of the Pins 0, 2 and 15.</p>
<table><thead>
<tr>
<th>Number</th>
<th>GPIO15</th>
<th>GPIO0</th>
<th>GPIO2</th>
<th>Mode</th>
</tr>
</thead><tbody>
<tr>
<td>0</td>
<td>0V</td>
<td>0V</td>
<td>0V</td>
<td>Not valid</td>
</tr>
<tr>
<td>1</td>
<td>0V</td>
<td>0V</td>
<td>3.3V</td>
<td>Uart</td>
</tr>
<tr>
<td>2</td>
<td>0V</td>
<td>3.3V</td>
<td>0V</td>
<td>Not valid</td>
</tr>
<tr>
<td>3</td>
<td>0V</td>
<td>3.3V</td>
<td>3.3V</td>
<td>Flash</td>
</tr>
<tr>
<td>4</td>
<td>3.3V</td>
<td>0V</td>
<td>0V</td>
<td>SDIO</td>
</tr>
<tr>
<td>5</td>
<td>3.3V</td>
<td>0V</td>
<td>3.3V</td>
<td>SDIO</td>
</tr>
<tr>
<td>6</td>
<td>3.3V</td>
<td>3.3V</td>
<td>0V</td>
<td>SDIO</td>
</tr>
<tr>
<td>7</td>
<td>3.3V</td>
<td>3.3V</td>
<td>3.3V</td>
<td>SDIO</td>
</tr>
</tbody></table>
<p>note:
- number = ((GPIO15 &lt;&lt; 2) | (GPIO0 &lt;&lt; 1) | GPIO2);</p>
<h2 id="wemos-d1">WeMos D1</h2>
<p>Product page: <a href="http://wemos.cc">http://wemos.cc</a></p>
<h2 id="wemos-d1-mini">WeMos D1 mini</h2>
<p>Product page: <a href="http://wemos.cc">http://wemos.cc</a></p>
</div>
</body>
</html>

View File

@ -0,0 +1,500 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
Change Log &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
<div id="toc"></div>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="current-version">Current version</h2>
<h3 id="core">Core</h3>
<ul>
<li>Allow control of enabling debug and debug level from IDE</li>
<li>Make HardwareSerial::begin() and end() interrupt safe</li>
<li>Put HardwareSerial and cbuf methods called from interrupt context in RAM</li>
<li>Re-enable interrupts before directly enqueuing characters in the UART FIFO</li>
<li>Add espduino board</li>
<li>Rework StreamString::write to use String internal buffer directly (#1289)</li>
<li>Add function to measure stack high water mark</li>
<li>Fix RAM corruption caused by our hook of register_chipv6_phy(init_data*).</li>
<li>Optimize PWM interrupt handler for better precision</li>
<li>Add warning levels configurable through Preferences</li>
<li>Protect HardwareSerial&#39;s cbuf usage with InterruptLock</li>
<li>SPIFFS: check if path length is valid (#1089)</li>
<li>Set CPU frequency before running setup</li>
<li>Add core_esp8266_features.h to be able to detect the features and libraries included in the ESP core</li>
<li>Added ESPino to supported boards</li>
<li>Fix pwm first step getting skipped</li>
<li>Update SDK to 1.5.1_16_01_08</li>
<li>HardwareSerial: allow mapping of UART0 TX to GPIO2</li>
</ul>
<h3 id="libraries">Libraries</h3>
<ul>
<li>ESP8266HTTPClient: add CHUNKED encoding support (#1324)</li>
<li>Fixed crash bug with mDNS where a string buffer could be used uninitialized</li>
<li>Add WiFi TX power control</li>
<li>Add WiFi sleep management</li>
<li>Allow to hook into WiFi events from sketch</li>
<li>Allow setting TCP timeout</li>
<li>Add setSleepMode + getSleepMode and setPhyMode + getPhyMode to WiFi</li>
<li>Update GDBStub library with the source of esp-gdbstub</li>
<li>Servo: fix detach and attach</li>
<li>ESP8266mDNS: refactoring, add TXT support</li>
<li>Add HTTP Basic Auth to WebServer and libb64 (base64) to core</li>
<li>Fix link-time dependency of ESP8266WebServer on SPIFFS (#862)</li>
<li>Allow setting client side TLS key and certificate</li>
<li>Replace chain of UDP pbufs with a single pbuf before sending (#1009)</li>
<li>Remove bundled OneWire - ESP8266 support has been merged in the official OneWire sources</li>
<li>Unique Built-In libraries library.properties name</li>
<li>Improvements for MD5Builder with Stream</li>
<li>ESP8266SSDP: fixing TTL to 2 per spec</li>
<li>ESP8266WebServer: a content length of zero should also be sent</li>
<li>Use SoftwareSerial version 2.2</li>
<li>EEPROM: optimised _dirty flag</li>
<li>ESP8266mDNS: advertise all hosted services</li>
<li>Removed OneWire library</li>
</ul>
<h3 id="tools">Tools</h3>
<ul>
<li>espota.py: add support for manually selecting ip and port for host side</li>
</ul>
<hr>
<h2 id="2-0-0">2.0.0</h2>
<p>November 30, 2015</p>
<p>Package link: <code>http://arduino.esp8266.com/versions/2.0.0/package_esp8266com_index.json</code>.</p>
<h3 id="core">Core</h3>
<ul>
<li>Add file system APIs and documentation</li>
<li>Add ConfigFile example</li>
<li>Allow user to run code in user_rf_pre_init</li>
<li>Add strtoul and strtol, fix strtod</li>
<li>Update documentation for NodeMCU and Olimex boards</li>
<li>Disable interrupts inside ESP.getVcc (#567)</li>
<li>Erase RTC RAM only if RF mode looks invalid (#619)</li>
<li>Get pin levels at time of interrupt, rather than the time of calling the handler.</li>
<li>Move interrupt handlers to ram.</li>
<li>Improve debug output on critical errors</li>
<li>Add ArduinoOTA library and docs</li>
<li>Add WeMos D1 &amp; D1 mini boards</li>
<li>Add documentation about boot messages and mode meaning</li>
<li>Disable sleep mode before doing OTA (#1005)</li>
<li>Add the ability to be called back when the device is about to reset</li>
<li>Add &quot;Reset Method&quot; menu</li>
<li>Add MD5 to core</li>
<li>I2C: generate STOP in case of NACK (fix #698, #254)</li>
<li>Add libc time functions</li>
<li>Fix linker script for 512k(no SPIFFS) variant (#966)</li>
<li>I2S optimizations</li>
<li>Support Sketch &gt; Export compiled binary</li>
<li>Update SPIFFS wrapper for 0.3.3</li>
<li>Fix placement of code into RAM, enable gc-sections</li>
<li>Make soft wdt reset more obvious</li>
<li>Force disable IOSWAP for UART0 in HardwareSerial initialization (#744)</li>
<li>Add IPAddress::toString()</li>
</ul>
<h3 id="libraries">Libraries</h3>
<ul>
<li>ESP8266WebServer: support for sending of PROGMEM strings</li>
<li>ESP8266WebServer: support for serving files from file system</li>
<li>ESP8266WiFi: fix mode selection (#529)</li>
<li>ESP8266mDNS: allow to work on SoftAP interface</li>
<li>EEPROM: round requested size to 4 bytes (#659)</li>
<li>Add ESP8266AVRISP library</li>
<li>Add ESP8266HTTPUpdate library</li>
<li>Add HTTPClient library</li>
<li>Add WiFiClientSecure</li>
<li>ESP8266WiFi library: add persistent option, fix #1054</li>
<li>Make RequestHandler handle uploads</li>
<li>Add Digest Authentication to OTA and espota.py</li>
<li>Don&#39;t close UDP pcbs when WiFi connection drops (#969)</li>
<li>Add espsoftwareserial library</li>
<li>Add HTTP Updater library</li>
<li>Add Ethernet library for W5100</li>
<li>Add SPIFFS WebServer Example</li>
<li>add dnsIP() to ESP8266WiFi class</li>
<li>OTA support encapsulated to ArduinoOTA class</li>
<li>Add gdb stub library</li>
<li>Extracted the WebUpdate example into a library.</li>
<li>Fix to Servo allowing write() to be called before attach()</li>
<li>ESP8266WiFi: add function <code>begin</code> without any parameters and add <code>psk</code> function to return current PSK form sdk config</li>
<li>Fix a crash due to abort() called from TCP error callback (#428)</li>
<li>Adding support for OPTIONS requests to ESP8266WebServer</li>
<li>Add HTTPS request sample (#43)</li>
<li>Fix _useClientMode &amp; _useApMode in SDK auto connect mode (#754)</li>
<li>Add ESP8266WebServer::sendContent_P with &#39;size_t size&#39; argument for binary content</li>
<li>Fix bug in WiFiClient::write_P when content was binary</li>
<li>Add WiFiClient::write_P to be used with PROGMEM</li>
</ul>
<h3 id="tools">Tools</h3>
<ul>
<li>Update SDK to 1.3.0_15_08_10_p1</li>
<li>Update esptool to 0.4.6</li>
<li>Bump toolchain version to force libm update on Windows</li>
<li>ESP8266FS tool update</li>
</ul>
<hr>
<h2 id="1-6-5-947-g39819f0">1.6.5-947-g39819f0</h2>
<p>July 23, 2015</p>
<p>Package link: <code>http://arduino.esp8266.com/versions/1.6.5-947-g39819f0/package_esp8266com_index.json</code>.</p>
<h3 id="core">Core</h3>
<ul>
<li>I2C library updated to better handle repeated start for certain devices,
improved waveforms, higher frequencies for 160MHz core clock, fix case where
using different pins would not work with libs calling begin internally.</li>
<li>Add Adafruit HUZZAH board</li>
<li>Add SparkFun Thing board</li>
<li>Add SweetPea ESP-210 board</li>
<li>Add eboot bootloader</li>
<li>Timer0 support</li>
<li>Add PWM range and frequency control</li>
<li>Add ESP.eraseConfig method</li>
<li>Fix pin change interrupt handling (#322)</li>
<li>Add SLC and I2S register definitions</li>
<li>Fix math functions calling themselves recursively (#233, #354)</li>
<li>Print stack on exception and soft WDT reset</li>
<li>Add Updater class</li>
<li>Remove implementations of WDT-related functions</li>
<li>Provide selection between A0 and VCC (#443, #338)</li>
</ul>
<h3 id="libraries">Libraries</h3>
<ul>
<li>ESP8266WebServer: add gzip streaming, fix sendContent behaviour,
add setContentSize method.</li>
<li>ESP8266WiFi: add BSSID, channel, isHidden methods, fix AP/STA mode
selection (#28).</li>
<li>Better handling of WiFi disconnect (#231)</li>
<li>Add API to set the beginning of local ports range for WiFiClient.</li>
<li>Add RSSI function</li>
<li>Add function to get the MAC / BSSID as String</li>
<li>Servo library support</li>
<li>Add ESP8266WiFiMesh library</li>
<li>Add ESP8266SSDP library</li>
<li>Add DNS-SD support to ESP8266mDNS library</li>
</ul>
<h3 id="tools">Tools</h3>
<ul>
<li>Update SDK to v1.2.0_15_07_03</li>
<li>Better sketch size reporting (#314)</li>
<li>Update esptool to 0.4.5</li>
</ul>
<hr>
<h2 id="1-6-4-673-g8cd3697">1.6.4-673-g8cd3697</h2>
<p>May 22, 2015</p>
<p>Package link: <code>http://arduino.esp8266.com/versions/1.6.4-673-g8cd3697/package_esp8266com_index.json</code>.</p>
<h3 id="tools">Tools</h3>
<ul>
<li>Add 32-bit Linux toolchain.</li>
<li>Rebuild toolchain and esptool with support for OS X down to 10.6.</li>
</ul>
<h3 id="libraries">Libraries</h3>
<ul>
<li>Better connection handling in ESP8266WebServer.
The server now sends Content-Length and Connection: close headers,
then waits for the client to disconnect. By not closing the connection
actively, server avoids TIME_WAIT TCP state, and TCP stack is able to
release the memory immediately, without waiting for 2xMSL period.
If the client doesn&#39;t disconnect in 2000ms, the server closes the connection
actively.</li>
<li>Add Hash library, which has a function to calculate SHA1 hash.</li>
<li>SD, Adafruit_ILI9341, and OneWire libraries are now bundled.</li>
<li>Fix incorrect sector calculation in EEPROM library.</li>
</ul>
<hr>
<h2 id="1-6-4-628-g545ffde">1.6.4-628-g545ffde</h2>
<p>May 19, 2015</p>
<ul>
<li>Initial release of Boards Manager package for ESP8266 platform.</li>
</ul>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -0,0 +1,38 @@
using Eclipse with Arduino ESP8266
===========================================
### What to Download ###
- [arduino IDE](https://www.arduino.cc/en/Main/Software)
- [Eclipse IDE for C/C++ Developers](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/marsr)
- [Java](http://www.java.com/)
### Setup Arduino ###
see the [Readme](https://github.com/esp8266/Arduino#installing-with-boards-manager)
### Setup Eclipse ###
- [step 1](http://www.baeyens.it/eclipse/how_to.shtml#/c)
- [step 2](http://www.baeyens.it/eclipse/how_to.shtml#/e)
- go to Window --> preferences --> Arduino
- add as private hardware path the Part to the ESP8266
###### example private hardware path
Windows: C:\Users\[username]\AppData\Roaming\Arduino15\packages\esp8266\hardware
Linux: /home/[username]/.arduino15/packages/esp8266/hardware
### Eclipse wont build ###
if eclipse dont find the path to the Compiler add to the platform.txt
after:
```
version=1.6.4
```
this:
```
runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/../../../tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9
runtime.tools.esptool.path={runtime.platform.path}/../../../tools/esptool/0.4.4
```
Note:
- the path may changed, check the current version.
- each update over the Arduino IDE will remove the fix
- may not needed in future if Eclipse Plugin get an Update

View File

@ -0,0 +1,39 @@
vecho := @echo
Q := @
PROJECT_NAME=project_name
OTA_IP=192.168.254.100
OTA_PORT=8266
SERIAL_PORT=COM3
SERIAL_BAUD=230400
ARDUINO_BASE = D:/Coding/avr/Programme/arduino-nightly
ESP8266_BASE = $(ARDUINO_BASE)/hardware/esp8266com/esp8266
ESP8266_TOOLS = $(ESP8266_BASE)/tools
XTENSA_TOOLS_ROOT = $(ESP8266_TOOLS)/xtensa-lx106-elf/bin
PYTHON_BIN = python
ESPTOOL_PY_BIN = $(ESP8266_TOOLS)/esptool.py
ESPOTA_PY_BIN = $(ESP8266_TOOLS)/espota.py
ESPTOOL_BIN = $(ESP8266_TOOLS)/esptool/esptool.exe
ota:
$(vecho) ota...
$(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -f ./$(PROJECT_NAME).bin
ota_spiffs:
$(vecho) ota spiffs...
$(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -s -f ./$(PROJECT_NAME)_spiffs.bin
erase_flash:
$(vecho) "Erase Flash"
$(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) erase_flash
dumpmem:
$(vecho) "Read Flash need some time..."
$(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) read_flash 0 4194304 dump.bin
objdump:
"$(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump" -S $(PROJECT_NAME).elf > $(PROJECT_NAME).dobj

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

View File

@ -0,0 +1,38 @@
Exception Causes (EXCCAUSE)
===========================================
| EXC-CAUSE Code | Cause Name | Cause Description | Required Option | EXC-VADDR Loaded |
|:--------------:|:---------------------------|:------------------------------------------------------------------------------------------------------------|:-------------------------|:----------------:|
| 0 | IllegalInstructionCause | Illegal instruction | Exception | No |
| 1 | SyscallCause | SYSCALL instruction | Exception | No |
| 2 | InstructionFetchErrorCause | Processor internal physical address or data error during instruction fetch | Exception | Yes |
| 3 | LoadStoreErrorCause | Processor internal physical address or data error during load or store | Exception | Yes |
| 4 | Level1InterruptCause | Level-1 interrupt as indicated by set level-1 bits in the INTERRUPT register | Interrupt | No |
| 5 | AllocaCause | MOVSP instruction, if callers registers are not in the register file | Windowed Register | No |
| 6 | IntegerDivideByZeroCause | QUOS, QUOU, REMS, or REMU divisor operand is zero | 32-bit Integer Divide | No |
| 7 | Reserved for Tensilica | | | |
| 8 | PrivilegedCause | Attempt to execute a privileged operation when CRING ? 0 | MMU | No |
| 9 | LoadStoreAlignmentCause | Load or store to an unaligned address | Unaligned Exception | Yes |
| 10..11 | Reserved for Tensilica | | | |
| 12 | InstrPIFDataErrorCause | PIF data error during instruction fetch | Processor Interface | Yes |
| 13 | LoadStorePIFDataErrorCause | Synchronous PIF data error during LoadStore access | Processor Interface | Yes |
| 14 | InstrPIFAddrErrorCause | PIF address error during instruction fetch | Processor Interface | Yes |
| 15 | LoadStorePIFAddrErrorCause | Synchronous PIF address error during LoadStore access | Processor Interface | Yes |
| 16 | InstTLBMissCause | Error during Instruction TLB refill | MMU | Yes |
| 17 | InstTLBMultiHitCause | Multiple instruction TLB entries matched | MMU | Yes |
| 18 | InstFetchPrivilegeCause | An instruction fetch referenced a virtual address at a ring level less than CRING | MMU | Yes |
| 19 | Reserved for Tensilica | | | |
| 20 | InstFetchProhibitedCause | An instruction fetch referenced a page mapped with an attribute that does not permit instruction fetch | Region Protection or MMU | Yes |
| 21..23 | Reserved for Tensilica | | | |
| 24 | LoadStoreTLBMissCause | Error during TLB refill for a load or store | MMU | Yes |
| 25 | LoadStoreTLBMultiHitCause | Multiple TLB entries matched for a load or store | MMU | Yes |
| 26 | LoadStorePrivilegeCause | A load or store referenced a virtual address at a ring level less than CRING | MMU | Yes |
| 27 | Reserved for Tensilica | | | |
| 28 | LoadProhibitedCause | A load referenced a page mapped with an attribute that does not permit loads | Region Protection or MMU | Yes |
| 29 | StoreProhibitedCause | A store referenced a page mapped with an attribute that does not permit stores | Region Protection or MMU | Yes |
| 30..31 | Reserved for Tensilica | | | |
| 32..39 | CoprocessornDisabled | Coprocessor n instruction when cpn disabled. n varies 0..7 as the cause varies 32..39 | Coprocessor | No |
| 40..63 | Reserved | | | |
Infos from Xtensa Instruction Set Architecture (ISA) Reference Manual

View File

@ -0,0 +1,528 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
File System &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<div id="toc"></div>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#flash-layout">Flash layout</a></li>
<li><a href="#uploading-files-to-file-system">Uploading files to file system</a></li>
<li><a href="#file-system-object-spiffs">File system object (SPIFFS)</a>
<ul>
<li><a href="#begin">begin</a></li>
<li><a href="#format">format</a></li>
<li><a href="#open">open</a></li>
<li><a href="#exists">exists</a></li>
<li><a href="#opendir">openDir</a></li>
<li><a href="#remove">remove</a></li>
<li><a href="#rename">rename</a></li>
<li><a href="#info">info</a></li>
</ul></li>
<li><a href="#filesystem-information-structure">Filesystem information structure</a></li>
<li><a href="#directory-object-dir">Directory object (Dir)</a></li>
<li><a href="#file-object">File object</a>
<ul>
<li><a href="#seek">seek</a></li>
<li><a href="#position">position</a></li>
<li><a href="#size">size</a></li>
<li><a href="#name">name</a></li>
<li><a href="#close">close</a></li>
</ul></li>
</ul>
<h2 id="flash-layout">Flash layout</h2>
<p>Even though file system is stored on the same flash chip as the program, programming new sketch will not modify file system contents. This allows to use file system to store sketch data, configuration files, or content for Web server.</p>
<p>The following diagram illustrates flash layout used in Arduino environment:</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">|--------------|-------|---------------|--|--|--|--|--|
^ ^ ^ ^ ^
Sketch OTA update File system EEPROM WiFi config (SDK)
</code></pre></div>
<p>File system size depends on the flash chip size. Depending on the board which is selected in IDE, you have the following options for flash size:</p>
<table><thead>
<tr>
<th>Board</th>
<th>Flash chip size, bytes</th>
<th>File system size, bytes</th>
</tr>
</thead><tbody>
<tr>
<td>Generic module</td>
<td>512k</td>
<td>64k</td>
</tr>
<tr>
<td>Generic module</td>
<td>1M</td>
<td>64k, 128k, 256k, 512k</td>
</tr>
<tr>
<td>Generic module</td>
<td>2M</td>
<td>1M</td>
</tr>
<tr>
<td>Generic module</td>
<td>4M</td>
<td>3M</td>
</tr>
<tr>
<td>Adafruit HUZZAH</td>
<td>4M</td>
<td>1M, 3M</td>
</tr>
<tr>
<td>NodeMCU 0.9</td>
<td>4M</td>
<td>1M, 3M</td>
</tr>
<tr>
<td>NodeMCU 1.0</td>
<td>4M</td>
<td>1M, 3M</td>
</tr>
<tr>
<td>Olimex MOD-WIFI-ESP8266(-DEV)</td>
<td>2M</td>
<td>1M</td>
</tr>
<tr>
<td>SparkFun Thing</td>
<td>512k</td>
<td>64k</td>
</tr>
<tr>
<td>SweetPea ESP-210</td>
<td>4M</td>
<td>1M, 3M</td>
</tr>
<tr>
<td>WeMos D1 &amp; D1 mini</td>
<td>4M</td>
<td>1M, 3M</td>
</tr>
<tr>
<td>ESPDuino</td>
<td>4M</td>
<td>1M, 3M</td>
</tr>
</tbody></table>
<p><strong>Note:</strong> to use any of file system functions in the sketch, add the following include to the sketch:</p>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="cp">#include &quot;FS.h&quot;</span>
</code></pre></div>
<h2 id="uploading-files-to-file-system">Uploading files to file system</h2>
<p><em>ESP8266FS</em> is a tool which integrates into the Arduino IDE. It adds a menu item to <em>Tools</em> menu for uploading the contents of sketch data directory into ESP8266 flash file system.</p>
<ul>
<li>Download the tool: <a href="https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.2.0/ESP8266FS-0.2.0.zip">https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.2.0/ESP8266FS-0.2.0.zip</a>.</li>
<li>In your Arduino sketchbook directory, create <code>tools</code> directory if it doesn&#39;t exist yet</li>
<li>Unpack the tool into <code>tools</code> directory (the path will look like <code>&lt;home_dir&gt;/Arduino/tools/ESP8266FS/tool/esp8266fs.jar</code>)</li>
<li>Restart Arduino IDE</li>
<li>Open a sketch (or create a new one and save it)</li>
<li>Go to sketch directory (choose Sketch &gt; Show Sketch Folder)</li>
<li>Create a directory named <code>data</code> and any files you want in the file system there</li>
<li>Make sure you have selected a board, port, and closed Serial Monitor</li>
<li>Select Tools &gt; ESP8266 Sketch Data Upload. This should start uploading the files into ESP8266 flash file system. When done, IDE status bar will display <code>SPIFFS Image Uploaded</code> message.</li>
</ul>
<h2 id="file-system-object-spiffs">File system object (SPIFFS)</h2>
<h3 id="begin">begin</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">SPIFFS</span><span class="p">.</span><span class="n">begin</span><span class="p">()</span>
</code></pre></div>
<p>This method mounts SPIFFS file system. It must be called before any other
FS APIs are used. Returns <em>true</em> if file system was mounted successfully, false
otherwise.</p>
<h3 id="format">format</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">SPIFFS</span><span class="p">.</span><span class="n">format</span><span class="p">()</span>
</code></pre></div>
<p>Formats the file system. May be called either before or after calling <code>begin</code>.
Returns <em>true</em> if formatting was successful.</p>
<h3 id="open">open</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">SPIFFS</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">mode</span><span class="p">)</span>
</code></pre></div>
<p>Opens a file. <code>path</code> should be an absolute path starting with a slash
(e.g. <code>/dir/filename.txt</code>). <code>mode</code> is a string specifying access mode. It can be
one of &quot;r&quot;, &quot;w&quot;, &quot;a&quot;, &quot;r+&quot;, &quot;w+&quot;, &quot;a+&quot;. Meaning of these modes is the same as
for <code>fopen</code> C function.</p>
<p>Returns <em>File</em> object. To check whether the file was opened successfully, use
the boolean operator.</p>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">File</span> <span class="n">f</span> <span class="o">=</span> <span class="n">SPIFFS</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s">&quot;/f.txt&quot;</span><span class="p">,</span> <span class="s">&quot;w&quot;</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;file open failed&quot;</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div>
<h3 id="exists">exists</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">SPIFFS</span><span class="p">.</span><span class="n">exists</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</code></pre></div>
<p>Returns <em>true</em> if a file with given path exists, <em>false</em> otherwise.</p>
<h3 id="opendir">openDir</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">SPIFFS</span><span class="p">.</span><span class="n">openDir</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</code></pre></div>
<p>Opens a directory given its absolute path. Returns a <em>Dir</em> object.</p>
<h3 id="remove">remove</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">SPIFFS</span><span class="p">.</span><span class="n">remove</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</code></pre></div>
<p>Deletes the file given its absolute path. Returns <em>true</em> if file was deleted successfully.</p>
<h3 id="rename">rename</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">SPIFFS</span><span class="p">.</span><span class="n">rename</span><span class="p">(</span><span class="n">pathFrom</span><span class="p">,</span> <span class="n">pathTo</span><span class="p">)</span>
</code></pre></div>
<p>Renames file from <code>pathFrom</code> to <code>pathTo</code>. Paths must be absolute. Returns <em>true</em>
if file was renamed successfully.</p>
<h3 id="info">info</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">FSInfo</span> <span class="n">fs_info</span><span class="p">;</span>
<span class="n">SPIFFS</span><span class="p">.</span><span class="n">info</span><span class="p">(</span><span class="n">fs_info</span><span class="p">);</span>
</code></pre></div>
<p>Fills <a href="#filesystem-information-structure">FSInfo structure</a> with information about
the file system. Returns <code>true</code> is successful, <code>false</code> otherwise.</p>
<h2 id="filesystem-information-structure">Filesystem information structure</h2>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="k">struct</span> <span class="n">FSInfo</span> <span class="p">{</span>
<span class="kt">size_t</span> <span class="n">totalBytes</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">usedBytes</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">blockSize</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">pageSize</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">maxOpenFiles</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">maxPathLength</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></div>
<p>This is the structure which may be filled using FS::info method.
- <code>totalBytes</code> — total size of useful data on the file system
- <code>usedBytes</code> — number of bytes used by files
- <code>blockSize</code> — SPIFFS block size
- <code>pageSize</code> — SPIFFS logical page size
- <code>maxOpenFiles</code> — max number of files which may be open simultaneously
- <code>maxPathLength</code> — max file name length (including one byte for zero termination)</p>
<h2 id="directory-object-dir">Directory object (Dir)</h2>
<p>The purpose of <em>Dir</em> object is to iterate over files inside a directory.
It provides three methods: <code>next()</code>, <code>fileName()</code>, and <code>openFile(mode)</code>.</p>
<p>The following example shows how it should be used:</p>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">Dir</span> <span class="n">dir</span> <span class="o">=</span> <span class="n">SPIFFS</span><span class="p">.</span><span class="n">openDir</span><span class="p">(</span><span class="s">&quot;/data&quot;</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">dir</span><span class="p">.</span><span class="n">next</span><span class="p">())</span> <span class="p">{</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">dir</span><span class="p">.</span><span class="n">fileName</span><span class="p">());</span>
<span class="n">File</span> <span class="n">f</span> <span class="o">=</span> <span class="n">dir</span><span class="p">.</span><span class="n">openFile</span><span class="p">(</span><span class="s">&quot;r&quot;</span><span class="p">);</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="n">f</span><span class="p">.</span><span class="n">size</span><span class="p">());</span>
<span class="p">}</span>
</code></pre></div>
<p><code>dir.next()</code> returns true while there are files in the directory to iterate over.
It must be called before calling <code>fileName</code> and <code>openFile</code> functions.</p>
<p><code>openFile</code> method takes <em>mode</em> argument which has the same meaning as for <code>SPIFFS.open</code> function.</p>
<h2 id="file-object">File object</h2>
<p><code>SPIFFS.open</code> and <code>dir.openFile</code> functions return a <em>File</em> object. This object
supports all the functions of <em>Stream</em>, so you can use <code>readBytes</code>, <code>findUntil</code>,
<code>parseInt</code>, <code>println</code>, and all other <em>Stream</em> methods.</p>
<p>There are also some functions which are specific to <em>File</em> object.</p>
<h3 id="seek">seek</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">file</span><span class="p">.</span><span class="n">seek</span><span class="p">(</span><span class="n">offset</span><span class="p">,</span> <span class="n">mode</span><span class="p">)</span>
</code></pre></div>
<p>This function behaves like <code>fseek</code> C function. Depending on the value of <code>mode</code>,
it moves current position in a file as follows:</p>
<ul>
<li>if <code>mode</code> is <code>SeekSet</code>, position is set to <code>offset</code> bytes from the beginning.</li>
<li>if <code>mode</code> is <code>SeekCur</code>, current position is moved by <code>offset</code> bytes.</li>
<li>if <code>mode</code> is <code>SeekEnd</code>, position is set to <code>offset</code> bytes from the end of the
file.</li>
</ul>
<p>Returns <em>true</em> if position was set successfully.</p>
<h3 id="position">position</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">file</span><span class="p">.</span><span class="n">position</span><span class="p">()</span>
</code></pre></div>
<p>Returns the current position inside the file, in bytes.</p>
<h3 id="size">size</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">file</span><span class="p">.</span><span class="n">size</span><span class="p">()</span>
</code></pre></div>
<p>Returns file size, in bytes.</p>
<h3 id="name">name</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">String</span> <span class="n">name</span> <span class="o">=</span> <span class="n">file</span><span class="p">.</span><span class="n">name</span><span class="p">();</span>
</code></pre></div>
<p>Returns file name, as <code>const char*</code>. Convert it to <em>String</em> for storage.</p>
<h3 id="close">close</h3>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
</code></pre></div>
<p>Close the file. No other operations should be performed on <em>File</em> object after <code>close</code> function was called.</p>
</div>
</body>
</html>

View File

@ -0,0 +1,341 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
Installation &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<div id="toc"></div>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="boards-manager">Boards Manager</h2>
<p>This is the suggested installation method for end users.</p>
<h3 id="prerequisites">Prerequisites</h3>
<ul>
<li>Arduino 1.6.5, get it from <a href="https://www.arduino.cc/en/Main/OldSoftwareReleases#previous">Arduino website</a>. Arduino 1.6.6 has several issues, so we recommend to stick with 1.6.5 for now.</li>
<li>Internet connection</li>
</ul>
<h3 id="instructions">Instructions</h3>
<ul>
<li>Start Arduino and open Preferences window.</li>
<li>Enter <code>http://arduino.esp8266.com/stable/package_esp8266com_index.json</code> into <em>Additional Board Manager URLs</em> field. You can add multiple URLs, separating them with commas.</li>
<li>Open Boards Manager from Tools &gt; Board menu and find <em>esp8266</em> platform.</li>
<li>Select the version you need from a drop-down box.</li>
<li>Click <em>install</em> button.</li>
<li>Don&#39;t forget to select your ESP8266 board from Tools &gt; Board menu after installation.</li>
</ul>
<p>You may optionally use <em>staging</em> boards manager package link:
<code>http://arduino.esp8266.com/staging/package_esp8266com_index.json</code>. This may contain some new features, but at the same time, some things might be broken.</p>
<h2 id="using-git-version">Using git version</h2>
<p>This is the suggested installation method for contributors and library developers.</p>
<h3 id="prerequisites">Prerequisites</h3>
<ul>
<li>Arduino 1.6.5 (or newer, if you know what you are doing)</li>
<li>git</li>
<li>python 2.7</li>
<li>terminal, console, or command prompt (depending on you OS)</li>
<li>Internet connection</li>
</ul>
<h3 id="instructions">Instructions</h3>
<ul>
<li>Open the console and go to Arduino directory. This can be either your <em>sketchbook</em> directory (usually <code>&lt;Documents&gt;/Arduino</code>), or the directory of Arduino application itself, the choice is up to you.</li>
<li><p>Clone this repository into hardware/esp8266com/esp8266 directory. Alternatively, clone it elsewhere and create a symlink, if your OS supports them.</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">cd </span>hardware
mkdir esp8266com
<span class="nb">cd </span>esp8266com
git clone https://github.com/esp8266/Arduino.git esp8266
</code></pre></div>
<p>You should end up with the following directory structure:</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash">Arduino
<span class="p">|</span>
--- hardware
<span class="p">|</span>
--- esp8266com
<span class="p">|</span>
--- esp8266
<span class="p">|</span>
--- bootloaders
--- cores
--- doc
--- libraries
--- package
--- tests
--- tools
--- variants
--- platform.txt
--- programmers.txt
--- README.md
--- boards.txt
--- LICENSE
</code></pre></div></li>
<li><p>Download binary tools</p>
<div class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">cd </span>esp8266/tools
python get.py
</code></pre></div></li>
<li><p>Restart Arduino</p></li>
</ul>
</div>
</body>
</html>

View File

@ -0,0 +1,413 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
Libraries &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<div id="toc"></div>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#wifiesp8266wifi-library">WiFi(ESP8266WiFi library)</a></li>
<li><a href="#ticker">Ticker</a></li>
<li><a href="#eeprom">EEPROM</a></li>
<li><a href="#i2c-wire-library">I2C (Wire library)</a></li>
<li><a href="#spi">SPI</a></li>
<li><a href="#softwareserial">SoftwareSerial</a></li>
<li><a href="#esp-specific-apis">ESP-specific APIs</a></li>
<li><a href="#mdns-and-dns-sd-responder-esp8266mdns-library">mDNS and DNS-SD responder (ESP8266mDNS library)</a></li>
<li><a href="#ssdp-responder-esp8266ssdp">SSDP responder (ESP8266SSDP)</a></li>
<li><a href="#dns-server-dnsserver-library">DNS server (DNSServer library)</a></li>
<li><a href="#servo">Servo</a></li>
<li><a href="#other-libraries-not-included-with-the-ide">Other libraries (not included with the IDE)</a></li>
</ul>
<h2 id="wifi-esp8266wifi-library">WiFi(ESP8266WiFi library)</h2>
<p>This is mostly similar to WiFi shield library. Differences include:</p>
<ul>
<li><code>WiFi.mode(m)</code>: set mode to <code>WIFI_AP</code>, <code>WIFI_STA</code>, <code>WIFI_AP_STA</code> or <code>WIFI_OFF</code>.</li>
<li>call <code>WiFi.softAP(ssid)</code> to set up an open network</li>
<li>call <code>WiFi.softAP(ssid, password)</code> to set up a WPA2-PSK network (password should be at least 8 characters)</li>
<li><code>WiFi.macAddress(mac)</code> is for STA, <code>WiFi.softAPmacAddress(mac)</code> is for AP.</li>
<li><code>WiFi.localIP()</code> is for STA, <code>WiFi.softAPIP()</code> is for AP.</li>
<li><code>WiFi.printDiag(Serial)</code> will print out some diagnostic info</li>
<li><code>WiFiUDP</code> class supports sending and receiving multicast packets on STA interface.
When sending a multicast packet, replace <code>udp.beginPacket(addr, port)</code> with
<code>udp.beginPacketMulticast(addr, port, WiFi.localIP())</code>.
When listening to multicast packets, replace <code>udp.begin(port)</code> with
<code>udp.beginMulticast(WiFi.localIP(), multicast_ip_addr, port)</code>.
You can use <code>udp.destinationIP()</code> to tell whether the packet received was
sent to the multicast or unicast address.</li>
</ul>
<p><code>WiFiServer</code>, <code>WiFiClient</code>, and <code>WiFiUDP</code> behave mostly the same way as with WiFi shield library.
Four samples are provided for this library.
You can see more commands here: <a href="http://www.arduino.cc/en/Reference/WiFi">http://www.arduino.cc/en/Reference/WiFi</a></p>
<h2 id="ticker">Ticker</h2>
<p>Library for calling functions repeatedly with a certain period. Two examples included.</p>
<p>It is currently not recommended to do blocking IO operations (network, serial, file) from Ticker
callback functions. Instead, set a flag inside the ticker callback and check for that flag inside the loop function.</p>
<h2 id="eeprom">EEPROM</h2>
<p>This is a bit different from standard EEPROM class. You need to call <code>EEPROM.begin(size)</code>
before you start reading or writing, size being the number of bytes you want to use.
Size can be anywhere between 4 and 4096 bytes.</p>
<p><code>EEPROM.write</code> does not write to flash immediately, instead you must call <code>EEPROM.commit()</code>
whenever you wish to save changes to flash. <code>EEPROM.end()</code> will also commit, and will
release the RAM copy of EEPROM contents.</p>
<p>EEPROM library uses one sector of flash located just after the SPIFFS.</p>
<p>Three examples included.</p>
<h2 id="i2c-wire-library">I2C (Wire library)</h2>
<p>Wire library currently supports master mode up to approximately 450KHz.
Before using I2C, pins for SDA and SCL need to be set by calling
<code>Wire.begin(int sda, int scl)</code>, i.e. <code>Wire.begin(0, 2)</code> on ESP-01,
else they default to pins 4(SDA) and 5(SCL).</p>
<h2 id="spi">SPI</h2>
<p>SPI library supports the entire Arduino SPI API including transactions, including setting phase (CPHA).
Setting the Clock polarity (CPOL) is not supported, yet (SPI_MODE2 and SPI_MODE3 not working).</p>
<h2 id="softwareserial">SoftwareSerial</h2>
<p>An ESP8266 port of SoftwareSerial library done by Peter Lerup (@plerup) supports baud rate up to 115200 and multiples SoftwareSerial instances. See <a href="https://github.com/plerup/espsoftwareserial">https://github.com/plerup/espsoftwareserial</a> if you want to suggest an improvement or open an issue related to SoftwareSerial.</p>
<h2 id="esp-specific-apis">ESP-specific APIs</h2>
<p>APIs related to deep sleep and watchdog timer are available in the <code>ESP</code> object, only available in Alpha version.</p>
<p><code>ESP.deepSleep(microseconds, mode)</code> will put the chip into deep sleep. <code>mode</code> is one of <code>WAKE_RF_DEFAULT</code>, <code>WAKE_RFCAL</code>, <code>WAKE_NO_RFCAL</code>, <code>WAKE_RF_DISABLED</code>. (GPIO16 needs to be tied to RST to wake from deepSleep.)</p>
<p><code>ESP.restart()</code> restarts the CPU.</p>
<p><code>ESP.getFreeHeap()</code> returns the free heap size.</p>
<p><code>ESP.getChipId()</code> returns the ESP8266 chip ID as a 32-bit integer.</p>
<p>Several APIs may be used to get flash chip info:</p>
<p><code>ESP.getFlashChipId()</code> returns the flash chip ID as a 32-bit integer.</p>
<p><code>ESP.getFlashChipSize()</code> returns the flash chip size, in bytes, as seen by the SDK (may be less than actual size).</p>
<p><code>ESP.getFlashChipSpeed(void)</code> returns the flash chip frequency, in Hz.</p>
<p><code>ESP.getCycleCount()</code> returns the cpu instruction cycle count since start as an unsigned 32-bit. This is useful for accurate timing of very short actions like bit banging.</p>
<p><code>ESP.getVcc()</code> may be used to measure supply voltage. ESP needs to reconfigure the ADC
at startup in order for this feature to be available. Add the following line to the top
of your sketch to use <code>getVcc</code>:</p>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">ADC_MODE</span><span class="p">(</span><span class="n">ADC_VCC</span><span class="p">);</span>
</code></pre></div>
<p>TOUT pin has to be disconnected in this mode.</p>
<p>Note that by default ADC is configured to read from TOUT pin using <code>analogRead(A0)</code>, and
<code>ESP.getVCC()</code> is not available.</p>
<h2 id="mdns-and-dns-sd-responder-esp8266mdns-library">mDNS and DNS-SD responder (ESP8266mDNS library)</h2>
<p>Allows the sketch to respond to multicast DNS queries for domain names like &quot;foo.local&quot;, and DNS-SD (service dicovery) queries.
See attached example for details.</p>
<h2 id="ssdp-responder-esp8266ssdp">SSDP responder (ESP8266SSDP)</h2>
<p>SSDP is another service discovery protocol, supported on Windows out of the box. See attached example for reference.</p>
<h2 id="dns-server-dnsserver-library">DNS server (DNSServer library)</h2>
<p>Implements a simple DNS server that can be used in both STA and AP modes. The DNS server currently supports only one domain (for all other domains it will reply with NXDOMAIN or custom status code). With it clients can open a web server running on ESP8266 using a domain name, not an IP address.
See attached example for details.</p>
<h2 id="servo">Servo</h2>
<p>This library exposes the ability to control RC (hobby) servo motors. It will support upto 24 servos on any available output pin. By defualt the first 12 servos will use Timer0 and currently this will not interfere with any other support. Servo counts above 12 will use Timer1 and features that use it will be effected.
While many RC servo motors will accept the 3.3V IO data pin from a ESP8266, most will not be able to run off 3.3v and will require another power source that matches their specifications. Make sure to connect the grounds between the ESP8266 and the servo motor power supply.</p>
<h2 id="other-libraries-not-included-with-the-ide">Other libraries (not included with the IDE)</h2>
<p>Libraries that don&#39;t rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work:</p>
<ul>
<li><a href="https://github.com/Links2004/Adafruit_ILI9341">Adafruit_ILI9341</a> - Port of the Adafruit ILI9341 for the ESP8266 </li>
<li><a href="https://github.com/Links2004/arduinoVNC">arduinoVNC</a> - VNC Client for Arduino</li>
<li><a href="https://github.com/Links2004/arduinoWebSockets">arduinoWebSockets</a> - WebSocket Server and Client compatible with ESP8266 (RFC6455)</li>
<li><a href="https://github.com/marcoschwartz/aREST">aREST</a> - REST API handler library.</li>
<li><a href="https://github.com/blynkkk/blynk-library">Blynk</a> - easy IoT framework for Makers (check out the <a href="http://tiny.cc/blynk-kick">Kickstarter page</a>).</li>
<li><a href="https://github.com/milesburton/Arduino-Temperature-Control-Library.git">DallasTemperature</a></li>
<li><a href="https://github.com/adafruit/DHT-sensor-library">DHT-sensor-library</a> - Arduino library for the DHT11/DHT22 temperature and humidity sensors. Download latest v1.1.1 library and no changes are necessary. Older versions should initialize DHT as follows: <code>DHT dht(DHTPIN, DHTTYPE, 15)</code></li>
<li><a href="https://github.com/adafruit/Adafruit_NeoPixel">NeoPixel</a> - Adafruit&#39;s NeoPixel library, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino&#39;s library manager).</li>
<li><a href="https://github.com/Makuna/NeoPixelBus">NeoPixelBus</a> - Arduino NeoPixel library compatible with ESP8266. Use the &quot;NeoPixelAnimator&quot; branch for ESP8266 to get HSL color support and more.</li>
<li><a href="https://github.com/Imroy/pubsubclient">PubSubClient</a> - MQTT library by @Imroy.</li>
<li><a href="https://github.com/Makuna/Rtc">RTC</a> - Arduino Library for Ds1307 &amp; Ds3231 compatible with ESP8266.</li>
<li><a href="https://github.com/souliss/souliss">Souliss, Smart Home</a> - Framework for Smart Home based on Arduino, Android and openHAB.</li>
<li><a href="https://github.com/nzmichaelh/Adafruit-ST7735-Library">ST7735</a> - Adafruit&#39;s ST7735 library modified to be compatible with ESP8266. Just make sure to modify the pins in the examples as they are still AVR specific.</li>
<li><a href="https://github.com/gnulabis/UTFT-ESP8266">UTFT-ESP8266</a> - UTFT display library with support for ESP8266. Only serial interface (SPI) displays are supported for now (no 8-bit parallel mode, etc). Also includes support for the hardware SPI controller of the ESP8266.</li>
<li><a href="https://github.com/tzapu/WiFiManager">WiFiManager</a> - WiFi Connection manager with web captive portal. If it can&#39;t connect, it starts AP mode and a configuration portal so you can choose and enter WiFi credentials.</li>
</ul>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,781 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
OTA Update &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<div id="toc"></div>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#introduction">Introduction</a>
<ul>
<li><a href="#security">Security</a></li>
<li><a href="#safety">Safety</a></li>
<li><a href="#basic-requirements">Basic Requirements</a></li>
</ul></li>
<li><a href="#arduino-ide">Arduino IDE</a>
<ul>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#application-example">Application Example</a>
<ul>
<li><a href="#classic-ota">Classic OTA</a></li>
<li><a href="#arduinoota">ArduinoOTA</a></li>
<li><a href="#troubleshooting">Troubleshooting</a></li>
</ul></li>
</ul></li>
<li><a href="#web-browser">Web Browser</a>
<ul>
<li><a href="#requirements-1">Requirements</a></li>
<li><a href="#implementation-overview">Implementation Overview</a></li>
<li><a href="#application-example-1">Application Example</a></li>
</ul></li>
<li><a href="#http-server">HTTP Server</a>
<ul>
<li><a href="#requirements-2">Requirements</a></li>
<li><a href="#arduino-code">Arduino code</a>
<ul>
<li><a href="#simple-updater">Simple updater</a></li>
<li><a href="#advanced-updater">Advanced updater</a></li>
</ul></li>
<li><a href="#server-request-handling">Server request handling</a>
<ul>
<li><a href="#simple-updater-1">Simple updater</a></li>
<li><a href="#advanced-updater-1">Advanced updater</a></li>
</ul></li>
</ul></li>
<li><a href="#stream-interface">Stream Interface</a></li>
<li><a href="#updater-class">Updater class</a></li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>OTA (Over the Air) update is the process of loading the firmware to ESP module using Wi-Fi connection rather that a serial port. Such functionality became extremely useful in case of limited or no physical access to the module.</p>
<p>OTA may be done using:</p>
<ul>
<li><a href="#arduino-ide">Arduino IDE</a></li>
<li><a href="#web-browser">Web Browser</a></li>
<li><a href="#http-server">HTTP Server</a></li>
</ul>
<p>Arduino IDE option is intended primarily for software development phase. The two other options would be more useful after deployment, to provide module with application updates manually with a web browser or automatically using a http server.</p>
<p>In any case first firmware upload have to be done over a serial port. If OTA routines are correctly implemented in a sketch, then all subsequent uploads may be done over the air.</p>
<p>There is no imposed security on OTA process from being hacked. It is up to developer to ensure that updates are allowed only from legitimate / trusted source. Once update is complete, module restarts and new code is executed. Developer should ensure that application running on module is shut down and restarted in a safe manner. Chapters below provide additional information regarding security and safety of OTA process.</p>
<h3 id="security">Security</h3>
<p>Module has to be exposed wirelessly to get it updated with a new sketch. That poses chances of module being violently hacked and loaded with some other code. To reduce likelihood of being hacked consider protecting your uploads with a password, selecting certain OTA port, etc.</p>
<p>Check functionality provided with <a href="https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA">ArduinoOTA</a> library that may improve security:</p>
<div class="highlight"><pre><code class="language-cpp" data-lang="cpp"><span class="kt">void</span> <span class="nf">setPort</span><span class="p">(</span><span class="kt">uint16_t</span> <span class="n">port</span><span class="p">);</span>
<span class="kt">void</span> <span class="nf">setHostname</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">hostname</span><span class="p">);</span>
<span class="kt">void</span> <span class="nf">setPassword</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">password</span><span class="p">);</span>
</code></pre></div>
<p>Certain protection functionality is already built in and do not require any additional coding by developer. <a href="https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA">ArduinoOTA</a> and espota.py use <a href="https://en.wikipedia.org/wiki/Digest_access_authentication">Digest-MD5</a> to authenticate upload. Integrity of transferred data is verified on ESP side using <a href="https://en.wikipedia.org/wiki/MD5">MD5</a> checksum.</p>
<p>Make your own risk analysis and depending on application decide what library functions to implement. If required consider implementation of other means of protection from being hacked, e.g. exposing module for uploads only according to specific schedule, trigger OTA only be user pressing dedicated “Update” button, etc.</p>
<h3 id="safety">Safety</h3>
<p>OTA process takes ESPs resources and bandwidth during upload. Then module is restarted and a new sketch executed. Analyse and test how it affects functionality of your existing and new sketch.</p>
<p>If ESP is placed in remote location and controlling some equipment, you should put additional attention what happens if operation of this equipment is suddenly interrupted by update process. Therefore decide how to put this equipment into safe state before starting the update. For instance your module may be controlling a garden watering system in a sequence. If this sequence is not properly shut down and a water valve left open, your garden may be flooded if this valve is not closed after OTA is finished and module restarts. </p>
<p>The following functions are provided with <a href="https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA">ArduinoOTA</a> library and intended to handle functionality of your application during specific stages of OTA or on an OTA error:</p>
<div class="highlight"><pre><code class="language-cpp" data-lang="cpp"><span class="kt">void</span> <span class="nf">onStart</span><span class="p">(</span><span class="n">OTA_CALLBACK</span><span class="p">(</span><span class="n">fn</span><span class="p">));</span>
<span class="kt">void</span> <span class="nf">onEnd</span><span class="p">(</span><span class="n">OTA_CALLBACK</span><span class="p">(</span><span class="n">fn</span><span class="p">));</span>
<span class="kt">void</span> <span class="nf">onProgress</span><span class="p">(</span><span class="n">OTA_CALLBACK_PROGRESS</span><span class="p">(</span><span class="n">fn</span><span class="p">));</span>
<span class="kt">void</span> <span class="nf">onError</span><span class="p">(</span><span class="n">OTA_CALLBACK_ERROR</span> <span class="p">(</span><span class="n">fn</span><span class="p">));</span>
</code></pre></div>
<h3 id="basic-requirements">Basic Requirements</h3>
<p>Flash chip size needs a size that is able to hold the old sketch (currently running) and the new sketch (OTA) at the same time.
Keep in mind that the File system and EEPROM for example needs space too (one time) see <a href="../filesystem.md#flash-layout">flash layout</a>.
<code>cpp
ESP.getFreeSketchSpace();
</code>
can be used for checking the free space for the new sketch.</p>
<p>For overview of memory layout, where new sketch is stored and how it is copied during OTA process see <a href="#update-process---memory-view">Update process - memory view</a>.</p>
<p>The following chapters provide more details and specific methods of doing OTA.</p>
<h2 id="arduino-ide">Arduino IDE</h2>
<p>Uploading modules wirelessly from Arduino IDE is intended for the following typical scenarios:
- during firmware development as a quicker alternative to loading over a serial
- for updating small quantity of modules
- only if modules are available on the same network as the computer with Arduino IDE</p>
<h3 id="requirements">Requirements</h3>
<ul>
<li>The ESP and the computer must be connected to the same network.</li>
</ul>
<h3 id="application-example">Application Example</h3>
<p>Currently there are two software configurations that support OTA updates.</p>
<ul>
<li><p><a href="#classic-ota-configuration">Classic OTA</a>: Arduino IDE 1.6.5 and 1.6.5-947-g39819f0 (of July 23, 2015) version of ESP8266 board support platform package that provides first OTA implementation, yet without support for <a href="https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA">ArduinoOTA</a> library. This particular configuration soon will be depreciated in favor of new implementation described below.</p></li>
<li><p><a href="#arduinoota-configuration">ArduinoOTA</a>: Arduino IDE 1.6.7 and 2.0.0 version of platform package. Arduino IDE 1.6.7 is the first release that provides support for <a href="https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA">ArduinoOTA</a> library.</p></li>
</ul>
<p>For information how to install ESP8266 board support in Arduino IDE please refer to <a href="https://github.com/esp8266/Arduino#installing-with-boards-manager">https://github.com/esp8266/Arduino#installing-with-boards-manager</a>. Once installed, it is possible to switch between available versions of platform package using Boards Manager:</p>
<p><img src="selection-of-package-version.png" alt="Selecion of ESP8266 package version"></p>
<p>Instructions below demonstrate how to configure both <a href="#classic-ota-configuration">Classic OTA</a> and <a href="#arduinoota-configuration">ArduinoOTA</a> using NodeMCU 1.0 (ESP-12E Module) board. You can use other boards assuming that they meet <a href="#basic-requirements">requirements</a> described above.</p>
<h4 id="classic-ota">Classic OTA</h4>
<ol>
<li><p>Before you begin, please make sure that you have the following installed:</p>
<ul>
<li>Arduino IDE 1.6.5 and 1.6.5-947-g39819f0 version of platform package,</li>
<li><a href="https://www.python.org/">Python</a> 2.7 (do not install Python 3.5 that is not supported).</li>
</ul></li>
<li><p>Now prepare the sketch and configuration for the upload over a serial port.</p>
<ul>
<li><p>Start Arduino IDE and load sketch DNS_SD_Arduino_OTA.ino available under File &gt; Examples &gt; ESP8266mDNS
<img src="ota-ide-sketch-selection.png" alt="OTA sketch selection"></p>
<p><strong>Note:</strong> This sketch is available only for 1.6.5-947-g39819f0 (of July 23, 2015) platform package. It was removed in <a href="https://github.com/esp8266/Arduino/pull/980">#980</a> from GitHub repository.</p></li>
<li><p>Update SSID and password in the sketch so the module can join your Wi-Fi network
<img src="ota-ide-ssid-pass-entry.png" alt="SSID and password entry"></p></li>
</ul></li>
</ol>
<div class="highlight"><pre><code class="language-text" data-lang="text">- Configure upload parameters as below (you may need to adjust configuration if you are using a different module):
![configuration of serial upload](ota-ide-serial-upload-configuration.png)
</code></pre></div>
<ol>
<li><p>Upload the sketch (Ctrl+U). Once done, open Serial Monitor (Ctrl+Shift+M) and check if module has joined your Wi-Fi network.</p>
<p><img src="ota-ide-module-joined-wifi.png" alt="check if module joined network"></p></li>
<li><p>Only if module is connected to network, after a couple of seconds, the esp8266-ota port will show up in Arduino IDE:</p>
<p><img src="ota-ide-ota-port-selection.png" alt="selection of OTA port"></p></li>
<li><p>Now get ready for your first OTA upload by changing configuration settings as follows:</p>
<p><img src="ota-ide-ota-upload-configuration.png" alt="configuration of OTA upload"></p>
<p><strong>Note:</strong> If you do not see “Upload Using: OTA” option available for “NodeMCU 1.0 (ESP-12E Module)” board, please upload the latest <a href="https://github.com/esp8266/Arduino/blob/master/boards.txt">boards.txt</a> file from GitHub repository, replace existing file and restart Arduino IDE.</p></li>
<li><p>If you have successfully completed all the above steps, you can upload (Ctrl+U) the same (or any other) sketch over OTA:</p>
<p><img src="ota-ide-ota-upload-complete.png" alt="OTA upload complete"></p></li>
</ol>
<p><strong>Note:</strong> To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use DNS_SD_Arduino_OTA.ino as an example.</p>
<p>In case of issues please refer to information provided in section <a href="#troubleshooting">Troubleshooting</a>. Successful OTA process looks like below on serial terminal:</p>
<div class="highlight"><pre><code class="language-text" data-lang="text">Arduino OTA Test
Sketch size: 346664
Free size: 700416
IP address: 192.168.1.100
Update Start: ip:192.168.1.10, port:48266, size:346672
Update Success: 6113
Rebooting...
ets Jan 8 2013,rst cause:1, boot mode:(3,7)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
@cp:0
ld
Arduino OTA Test
Sketch size: 346664
Free size: 700416
IP address: 192.168.1.100
</code></pre></div>
<p><strong>Note:</strong> Sketch and free memory sizes as well as IP addresses depend on your particular s/w and h/w configuration.</p>
<h4 id="arduinoota">ArduinoOTA</h4>
<ol>
<li><p>Before you begin, please make sure that you have the following installed:</p>
<ul>
<li>Arduino IDE 1.6.7 and 2.0.0 version of platform package following the process described under <a href="https://github.com/esp8266/Arduino#installing-with-boards-manager">https://github.com/esp8266/Arduino#installing-with-boards-manager</a></li>
<li><p><a href="https://www.python.org/">Python</a> 2.7 (do not install Python 3.5 that is not supported):</p>
<p><strong>Note:</strong> Windows users should select “Add python.exe to Path” (see below this option is not selected by default).</p>
<p><img src="ota-ide-python-configuration.png" alt="Python installation set up"></p></li>
</ul></li>
<li><p>Now prepare the sketch and configuration for the upload over a serial port.</p>
<ul>
<li>Start Arduino IDE and load sketch BasicOTA.ino available under File &gt; Examples &gt; ArduinoOTA
<img src="a-ota-sketch-selection.png" alt="selection of example OTA sketch"></li>
</ul></li>
</ol>
<div class="highlight"><pre><code class="language-text" data-lang="text">- Update SSID and password in the sketch so the module can join your Wi-Fi network
![SSID and password entry](a-ota-ssid-pass-entry.png)
- Configure upload parameters as below (you may need to adjust configuration if you are using a different module):
![configuration of serial upload](a-ota-serial-upload-configuration.png)
</code></pre></div>
<ol>
<li><p>Upload the sketch (Ctrl+U). Once done, open Serial Monitor (Ctrl+Shift+M) and check if module has joined your Wi-Fi network:</p>
<p><img src="a-ota-upload-complete-and-joined-wifi.png" alt="check if module joined network"></p></li>
<li><p>Only if module is connected to network, after a couple of seconds, the esp8266-ota port will show up in Arduino IDE:</p>
<p><img src="a-ota-ota-port-selection.png" alt="selection of OTA port"></p>
<p><strong>Note:</strong> If OTA port does not show up, try to exit Arduino IDE, open it again and check if port is there.</p></li>
<li><p>Now get ready for your first OTA upload by selecting the OTA port:</p>
<p><img src="a-ota-ota-upload-configuration.png" alt="configuration of OTA upload"></p>
<p>There is no need to change <code>Upload Using:</code> or <code>Upload Speed:</code>.</p></li>
<li><p>If you have successfully completed all the above steps, you can upload (Ctrl+U) the same (or any other) sketch over OTA:</p>
<p><img src="a-ota-ota-upload-complete.png" alt="OTA upload complete"></p></li>
</ol>
<p><strong>Note:</strong> To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use BasicOTA.ino as an example.</p>
<h4 id="troubleshooting">Troubleshooting</h4>
<p>If OTA update fails, first step is to check for error messages that may be shown in upload window of Arduino IDE. If this is not providing any useful hints try to upload again while checking what is shown by ESP on serial port. Serial Monitor from IDE will not be useful in that case. When attempting to open it, you will likely see the following:</p>
<p><img src="ota-ide-network-terminal.png" alt="Arduino IDE network terminal window"></p>
<p>This window is for Arduino Yún and not yet implemented for esp8266/Arduino. It shows up because IDE is attempting to open Serial Monitor using network port you have selected for OTA upload.</p>
<p>Instead you need an external serial monitor. If you are a Windows user check out <a href="http://www.compuphase.com/software_termite.htm">Termite</a>. This is handy, slick and simple RS232 terminal that does not impose RTS or DTR flow control. Such flow control may cause issues if you are using respective lines to toggle GPIO0 and RESET pins on ESP for upload. </p>
<p>Select COM port and baud rate on external terminal program as if you were using Arduino Serial Monitor. Please see typical settings for <a href="http://www.compuphase.com/software_termite.htm">Termite</a> below:</p>
<p><img src="termite-configuration.png" alt="Termite settings"></p>
<p>Then run OTA from IDE and look what is displayed on terminal. Successful <a href="#arduinoota">ArduinoOTA</a> process using BasicOTA.ino sketch looks like below (IP address depends on your network configuration):</p>
<p><img src="a-ota-external-serial-terminal-output.png" alt="OTA upload successful - output on an external serial terminal"></p>
<p>If upload fails you will likely see errors caught by the uploader, exception and the stack dump, or both. </p>
<p>The most common causes of OTA failure are as follows:
* not enough physical memory on the chip (e.g. ESP01 with 512K flash memory is not enough for OTA),
* too much memory declared for SPIFFS so new sketch will not fit between existing sketch and SPIFFS see <a href="https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/ota_updates.md#update-process---memory-view">Update process - memory view</a>,
* too little memory declared in Arduino IDE for your selected board (i.e. less than physical size). </p>
<p>For more details regarding flash memory layout please check <a href="https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md">File system</a>.
For overview where new sketch is stored, how it is copied and how memory is organized for the purpose of OTA see <a href="https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/ota_updates.md#update-process---memory-view">Update process - memory view</a>.</p>
<h2 id="web-browser">Web Browser</h2>
<p>Updates described in this chapter are done with a web browser that can be useful in the following typical scenarios:</p>
<ul>
<li>after application deployment if loading directly from Arduino IDE is inconvenient or not possible</li>
<li>after deployment if user is unable to expose module for OTA from external update server</li>
<li>to provide updates after deployment to small quantity of modules when setting an update server is not practicable</li>
</ul>
<h3 id="requirements">Requirements</h3>
<ul>
<li>The ESP and the computer must be connected to the same network.</li>
</ul>
<h3 id="implementation-overview">Implementation Overview</h3>
<p>Updates with a web browser are implemented using <code>ESP8266HTTPUpdateServer</code> class together with <code>ESP8266WebServer</code> and <code>ESP8266mDNS</code> classes. The following code is required to get it work:</p>
<p>setup()</p>
<div class="highlight"><pre><code class="language-cpp" data-lang="cpp"> <span class="n">MDNS</span><span class="p">.</span><span class="n">begin</span><span class="p">(</span><span class="n">host</span><span class="p">);</span>
<span class="n">httpUpdater</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="o">&amp;</span><span class="n">httpServer</span><span class="p">);</span>
<span class="n">httpServer</span><span class="p">.</span><span class="n">begin</span><span class="p">();</span>
<span class="n">MDNS</span><span class="p">.</span><span class="n">addService</span><span class="p">(</span><span class="s">&quot;http&quot;</span><span class="p">,</span> <span class="s">&quot;tcp&quot;</span><span class="p">,</span> <span class="mi">80</span><span class="p">);</span>
</code></pre></div>
<p>loop()</p>
<div class="highlight"><pre><code class="language-cpp" data-lang="cpp"> <span class="n">httpServer</span><span class="p">.</span><span class="n">handleClient</span><span class="p">();</span>
</code></pre></div>
<h3 id="application-example">Application Example</h3>
<p>The sample implementation provided below has been done using:</p>
<ul>
<li>example sketch WebUpdater.ino available in <code>ESP8266HTTPUpdateServer</code> library</li>
<li>NodeMCU 1.0 (ESP-12E Module)</li>
</ul>
<p>You can use another module if it meets previously desribed <a href="#basic-requirements">requirements</a>.</p>
<ol>
<li><p>Before you begin, please make sure that you have the following software installed:</p>
<ul>
<li>Arduino IDE and 2.0.0-rc1 (of Nov 17, 2015) version of platform package as described under <a href="https://github.com/esp8266/Arduino#installing-with-boards-manager">https://github.com/esp8266/Arduino#installing-with-boards-manager</a></li>
<li>Host software depending on O/S you use:
<ol>
<li>Avahi <a href="http://avahi.org/">http://avahi.org/</a> for Linux</li>
<li>Bonjour <a href="http://www.apple.com/support/bonjour/">http://www.apple.com/support/bonjour/</a> for Windows</li>
<li>Mac OSX and iOS - support is already built in / no any extra s/w is required</li>
</ol></li>
</ul></li>
<li><p>Prepare the sketch and configuration for initial upload with a serial port.</p>
<ul>
<li>Start Arduino IDE and load sketch WebUpdater.ino available under File &gt; Examples &gt; ESP8266HTTPUpdateServer.</li>
<li>Update SSID and password in the sketch so the module can join your Wi-Fi network.</li>
<li><p>Open File &gt; Preferences, look for “Show verbose output during:” and check out “compilation” option.</p>
<p><img src="ota-web-show-verbose-compilation.png" alt="Preferences - enabling verbose output during compilation"></p>
<p><strong>Note:</strong> This setting will be required in step 5 below. You can uncheck this setting afterwards.</p></li>
</ul></li>
<li><p>Upload sketch (Ctrl+U). Once done open Serial Monitor (Ctrl+Shift+M) and check if you see the following message displayed, that contains url for OTA update.</p>
<p><img src="ota-web-serial-monitor-ready.png" alt="Serial Monitor - after first load using serial"></p>
<p><strong>Note:</strong> Such message will be shown only after module successfully joins network and is ready for an OTA upload.</p></li>
<li><p>Now open web browser and enter the url provided on Serial Monitor, i.e. <a href="http://esp8266-webupdate.local/update">http://esp8266-webupdate.local/update</a>. Once entered, browser should display a form like below that has been served by your module. The form invites you to choose a file for update.</p>
<p><img src="ota-web-browser-form.png" alt="OTA update form in web browser"></p>
<p><strong>Note:</strong> If entering <code>http://esp8266-webupdate.local/update</code> does not work, try replacing <code>esp8266-webupdate</code> with modules IP address. For example, if your module IP is <code>192.168.1.100</code> then url should be <code>http://192.168.1.100/update</code>. This workaround is useful in case the host software installed in step 2 does not work. If still nothing works and there are no clues on Serial Monitor, try to diagnose issue by opening provided url in Google Chrome, pressing F12 and checking contents of “Console” and “Network” tabs. Chrome provides some advanced logging on these tabs.</p></li>
<li><p>To obtain the file navigate to directory used by Arduino IDE to store results of compilation. You can check the path to this file in compilation log shown in IDE debug window as marked below.</p>
<p><img src="ota-web-path-to-binary.png" alt="Compilation complete - path to binary file"></p></li>
<li><p>Now press “Choose File” in web browser, go to directory identified in step 5 above, find the file “WebUpdater.cpp.bin” and upload it. If upload is successful you will see “OK” on web browser like below.</p>
<p><img src="ota-web-browser-form-ok.png" alt="OTA update complete"></p>
<p>Module will reboot that should be visible on Serial Monitor:</p>
<p><img src="ota-web-serial-monitor-reboot.png" alt="Serial Monitor - after OTA update"></p>
<p>Just after reboot you should see exactly the same message <code>HTTPUpdateServer ready! Open http:// esp8266-webupdate.local /update in your browser</code> like in step 3. This is because module has been loaded again with the same code first using serial port, and then using OTA.</p></li>
</ol>
<p>Once you are comfortable with this procedure go ahead and modify WebUpdater.ino sketch to print some additional messages, compile it, locate new binary file and upload it using web browser to see entered changes on a Serial Monitor.</p>
<p>You can also add OTA routines to your own sketch following guidelines in <a href="#implementation-overview">Implementation Overview</a> above. If this is done correctly you should be always able to upload new sketch over the previous one using a web browser.</p>
<p>In case OTA update fails dead after entering modifications in your sketch, you can always recover module by loading it over a serial port. Then diagnose the issue with sketch using Serial Monitor. Once the issue is fixed try OTA again.</p>
<h2 id="http-server">HTTP Server</h2>
<p><code>ESPhttpUpdate</code> class can check for updates and download a binary file from HTTP web server.
It is possible to download updates from every IP or domain address on the network or Internet.</p>
<h4 id="requirements">Requirements</h4>
<ul>
<li>web server</li>
</ul>
<h4 id="arduino-code">Arduino code</h4>
<h5 id="simple-updater">Simple updater</h5>
<p>Simple updater downloads the file every time the function is called.</p>
<div class="highlight"><pre><code class="language-cpp" data-lang="cpp"><span class="n">ESPhttpUpdate</span><span class="p">.</span><span class="n">update</span><span class="p">(</span><span class="s">&quot;192.168.0.2&quot;</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="s">&quot;/arduino.bin&quot;</span><span class="p">);</span>
</code></pre></div>
<h5 id="advanced-updater">Advanced updater</h5>
<p>Its possible to point update function to a script at the server.
If version string argument is given, it will be sent to the server.
Server side script can use this to check if update should be performed.</p>
<p>Server side script can respond as follows:
- response code 200, and send the firmware image,
- or response code 304 to notify ESP that no update is required.</p>
<div class="highlight"><pre><code class="language-cpp" data-lang="cpp"><span class="n">t_httpUpdate_return</span> <span class="n">ret</span> <span class="o">=</span> <span class="n">ESPhttpUpdate</span><span class="p">.</span><span class="n">update</span><span class="p">(</span><span class="s">&quot;192.168.0.2&quot;</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="s">&quot;/esp/update/arduino.php&quot;</span><span class="p">,</span> <span class="s">&quot;optional current version string here&quot;</span><span class="p">);</span>
<span class="k">switch</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span> <span class="p">{</span>
<span class="k">case</span> <span class="nl">HTTP_UPDATE_FAILED</span><span class="p">:</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;[update] Update failed.&quot;</span><span class="p">);</span>
<span class="k">break</span><span class="p">;</span>
<span class="k">case</span> <span class="nl">HTTP_UPDATE_NO_UPDATES</span><span class="p">:</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;[update] Update no Update.&quot;</span><span class="p">);</span>
<span class="k">break</span><span class="p">;</span>
<span class="k">case</span> <span class="nl">HTTP_UPDATE_OK</span><span class="p">:</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="s">&quot;[update] Update ok.&quot;</span><span class="p">);</span> <span class="c1">// may not called we reboot the ESP</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div>
<h4 id="server-request-handling">Server request handling</h4>
<h5 id="simple-updater">Simple updater</h5>
<p>For the simple updater the server only needs to deliver the binary file for update.</p>
<h5 id="advanced-updater">Advanced updater</h5>
<p>For advanced update management a script needs to run at the server side, for example a PHP script.
At every update request the ESP sends some information in HTTP headers to the server.</p>
<p>Example header data:
<code>
[HTTP_USER_AGENT] =&gt; ESP8266-http-Update
[HTTP_X_ESP8266_STA_MAC] =&gt; 18:FE:AA:AA:AA:AA
[HTTP_X_ESP8266_AP_MAC] =&gt; 1A:FE:AA:AA:AA:AA
[HTTP_X_ESP8266_FREE_SPACE] =&gt; 671744
[HTTP_X_ESP8266_SKETCH_SIZE] =&gt; 373940
[HTTP_X_ESP8266_CHIP_SIZE] =&gt; 4194304
[HTTP_X_ESP8266_SDK_VERSION] =&gt; 1.3.0
[HTTP_X_ESP8266_VERSION] =&gt; DOOR-7-g14f53a19
</code></p>
<p>With this information the script now can check if an update is needed. It is also possible to deliver different binaries based on the MAC address for example.</p>
<p>Script example:</p>
<div class="highlight"><pre><code class="language-php" data-lang="php"><span class="cp">&lt;?PHP</span>
<span class="nb">header</span><span class="p">(</span><span class="s1">&#39;Content-type: text/plain; charset=utf8&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span>
<span class="k">function</span> <span class="nf">check_header</span><span class="p">(</span><span class="nv">$name</span><span class="p">,</span> <span class="nv">$value</span> <span class="o">=</span> <span class="k">false</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="nv">$name</span><span class="p">]))</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span><span class="p">(</span><span class="nv">$value</span> <span class="o">&amp;&amp;</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="nv">$name</span><span class="p">]</span> <span class="o">!=</span> <span class="nv">$value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="k">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">function</span> <span class="nf">sendFile</span><span class="p">(</span><span class="nv">$path</span><span class="p">)</span> <span class="p">{</span>
<span class="nb">header</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_PROTOCOL&quot;</span><span class="p">]</span><span class="o">.</span><span class="s1">&#39; 200 OK&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="mi">200</span><span class="p">);</span>
<span class="nb">header</span><span class="p">(</span><span class="s1">&#39;Content-Type: application/octet-stream&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">);</span>
<span class="nb">header</span><span class="p">(</span><span class="s1">&#39;Content-Disposition: attachment; filename=&#39;</span><span class="o">.</span><span class="nb">basename</span><span class="p">(</span><span class="nv">$path</span><span class="p">));</span>
<span class="nb">header</span><span class="p">(</span><span class="s1">&#39;Content-Length: &#39;</span><span class="o">.</span><span class="nb">filesize</span><span class="p">(</span><span class="nv">$path</span><span class="p">),</span> <span class="k">true</span><span class="p">);</span>
<span class="nb">header</span><span class="p">(</span><span class="s1">&#39;x-MD5: &#39;</span><span class="o">.</span><span class="nb">md5_file</span><span class="p">(</span><span class="nv">$path</span><span class="p">),</span> <span class="k">true</span><span class="p">);</span>
<span class="nb">readfile</span><span class="p">(</span><span class="nv">$path</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_USER_AGENT&#39;</span><span class="p">,</span> <span class="s1">&#39;ESP8266-http-Update&#39;</span><span class="p">))</span> <span class="p">{</span>
<span class="nb">header</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_PROTOCOL&quot;</span><span class="p">]</span><span class="o">.</span><span class="s1">&#39; 403 Forbidden&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="mi">403</span><span class="p">);</span>
<span class="k">echo</span> <span class="s2">&quot;only for ESP8266 updater!</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>
<span class="k">exit</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">if</span><span class="p">(</span>
<span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_X_ESP8266_STA_MAC&#39;</span><span class="p">)</span> <span class="o">||</span>
<span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_X_ESP8266_AP_MAC&#39;</span><span class="p">)</span> <span class="o">||</span>
<span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_X_ESP8266_FREE_SPACE&#39;</span><span class="p">)</span> <span class="o">||</span>
<span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_X_ESP8266_SKETCH_SIZE&#39;</span><span class="p">)</span> <span class="o">||</span>
<span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_X_ESP8266_CHIP_SIZE&#39;</span><span class="p">)</span> <span class="o">||</span>
<span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_X_ESP8266_SDK_VERSION&#39;</span><span class="p">)</span> <span class="o">||</span>
<span class="o">!</span><span class="nx">check_header</span><span class="p">(</span><span class="s1">&#39;HTTP_X_ESP8266_VERSION&#39;</span><span class="p">)</span>
<span class="p">)</span> <span class="p">{</span>
<span class="nb">header</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_PROTOCOL&quot;</span><span class="p">]</span><span class="o">.</span><span class="s1">&#39; 403 Forbidden&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="mi">403</span><span class="p">);</span>
<span class="k">echo</span> <span class="s2">&quot;only for ESP8266 updater! (header)</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span>
<span class="k">exit</span><span class="p">();</span>
<span class="p">}</span>
<span class="nv">$db</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
<span class="s2">&quot;18:FE:AA:AA:AA:AA&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;DOOR-7-g14f53a19&quot;</span><span class="p">,</span>
<span class="s2">&quot;18:FE:AA:AA:AA:BB&quot;</span> <span class="o">=&gt;</span> <span class="s2">&quot;TEMP-1.0.0&quot;</span>
<span class="p">);</span>
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$db</span><span class="p">[</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;HTTP_X_ESP8266_STA_MAC&#39;</span><span class="p">]]))</span> <span class="p">{</span>
<span class="k">if</span><span class="p">(</span><span class="nv">$db</span><span class="p">[</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;HTTP_X_ESP8266_STA_MAC&#39;</span><span class="p">]]</span> <span class="o">!=</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;HTTP_X_ESP8266_VERSION&#39;</span><span class="p">])</span> <span class="p">)</span> <span class="p">{</span>
<span class="nx">sendFile</span><span class="p">(</span><span class="s2">&quot;./bin/&quot;</span><span class="o">.</span><span class="nv">$db</span><span class="p">[</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;HTTP_X_ESP8266_STA_MAC&#39;</span><span class="p">]]</span><span class="o">.</span><span class="s2">&quot;bin&quot;</span><span class="p">);</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="nb">header</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_PROTOCOL&quot;</span><span class="p">]</span><span class="o">.</span><span class="s1">&#39; 304 Not Modified&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="mi">304</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">exit</span><span class="p">();</span>
<span class="p">}</span>
<span class="nb">header</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s2">&quot;SERVER_PROTOCOL&quot;</span><span class="p">]</span><span class="o">.</span><span class="s1">&#39; 500 no version for ESP MAC&#39;</span><span class="p">,</span> <span class="k">true</span><span class="p">,</span> <span class="mi">500</span><span class="p">);</span>
</code></pre></div>
<h2 id="stream-interface">Stream Interface</h2>
<p>TODO describe Stream Interface</p>
<p>The Stream Interface is the base for all other update modes like OTA, http Server / client.</p>
<h2 id="updater-class">Updater class</h2>
<p>Updater is in the Core and deals with writing the firmware to the flash,
checking its integrity and telling the bootloader to load the new firmware on the next boot.</p>
<h3 id="update-process-memory-view">Update process - memory view</h3>
<ul>
<li>The new sketch will be stored in the space between the old sketch and the spiff.</li>
<li>on the next reboot the &quot;eboot&quot; bootloader check for commands.</li>
<li>the new sketch is now copied &quot;over&quot; the old one.</li>
<li>the new sketch is started.</li>
</ul>
<p><img src="update_memory_copy.png" alt="Memory Copy"></p>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

View File

@ -0,0 +1,78 @@
## Using PlatformIO
- Install [PlatformIO](http://platformio.org)
- Initialise new project
```bash
#
# Create empty directory
#
mkdir myproject
cd myproject
#
# Find type of supported boards
#
platformio boards espressif
# Platform: espressif
# --------------------------------------------------------------------------------------------------------
# Type MCU Frequency Flash RAM Name
# --------------------------------------------------------------------------------------------------------
# huzzah esp8266 80Mhz 4096Kb 80Kb Adafruit HUZZAH ESP8266
# espino esp8266 80Mhz 4096Kb 80Kb ESPino
# esp12e esp8266 80Mhz 4096Kb 80Kb Espressif ESP8266 ESP-12E
# esp01_1m esp8266 80Mhz 1024Kb 80Kb Espressif Generic ESP8266 ESP-01 1M
# esp01 esp8266 80Mhz 512Kb 80Kb Espressif Generic ESP8266 ESP-01 512k
# nodemcu esp8266 80Mhz 4096Kb 80Kb NodeMCU 0.9 & 1.0
# modwifi esp8266 80Mhz 2048Kb 80Kb Olimex MOD-WIFI-ESP8266(-DEV)
# thing esp8266 80Mhz 512Kb 80Kb SparkFun ESP8266 Thing
# esp210 esp8266 80Mhz 4096Kb 80Kb SweetPea ESP-210
# d1 esp8266 80Mhz 4096Kb 80Kb WeMos D1
# d1_mini esp8266 80Mhz 4096Kb 80Kb WeMos D1 mini
# ...
#
# The rest of Board/MCU variations with the different Flash/SPIFFS can be customized using extra LD Script.
# PlatformIO contains the popular LD scripts.
# See http://docs.platformio.org/en/latest/platforms/espressif.html#custom-flash-size
#
#
# Initialise base project
#
platformio init --board %TYPE%(see above)
# for example, initialise project for Espressif Generic ESP8266 ESP-01
platformio init --board esp01
# The next files/directories will be created in myproject
# platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
# src - Put your source files here
# lib - Put here project specific (private) libraries
# Do you want to continue? [y/N]: Y
```
- Place your source code to `src` directory
- Build/Upload project
```bash
# process/build project
platformio run
# build+upload firmware
platformio run --target upload
```
## Advanced documentation
- [OTA update](http://docs.platformio.org/en/latest/platforms/espressif.html#ota-update)
* [Authentication and upload options](http://docs.platformio.org/en/latest/platforms/espressif.html#authentication-and-upload-options)
- [Custom CPU Frequency and Upload Speed](http://docs.platformio.org/en/latest/platforms/espressif.html#custom-cpu-frequency-and-upload-speed)
- [Custom Flash Size](http://docs.platformio.org/en/latest/platforms/espressif.html#custom-flash-size)
- [IDE Integration](http://docs.platformio.org/en/latest/ide.html) (Atom, CLion, Eclipse, Qt Creator, Sublime Text, VIM, Visual Studio)
- [Project Examples](http://docs.platformio.org/en/latest/platforms/espressif.html#examples)
## Demo of Over-the-Air (OTA) ESP8266 programming using PlatformIO
http://www.penninkhof.com/2015/12/1610-over-the-air-esp8266-programming-using-platformio/
[![Over-the-Air ESP8266 programming using PlatformIO](http://img.youtube.com/vi/lXchL3hpDO4/0.jpg)](http://www.youtube.com/watch?v=lXchL3hpDO4 "Over-the-Air ESP8266 programming using PlatformIO")

View File

@ -0,0 +1,369 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
Reference &middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<div id="toc"></div>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<h2 id="table-of-contents">Table of Contents</h2>
<ul>
<li><a href="#table-of-contents">Table of Contents</a></li>
<li><a href="#digital-io">Digital IO</a></li>
<li><a href="#analog-input">Analog input</a></li>
<li><a href="#analog-output">Analog output</a></li>
<li><a href="#timing-and-delays">Timing and delays</a></li>
<li><a href="#serial">Serial</a></li>
<li><a href="#progmem">Progmem</a></li>
</ul>
<h2 id="digital-io">Digital IO</h2>
<p>Pin numbers in Arduino correspond directly to the ESP8266 GPIO pin numbers. <code>pinMode</code>, <code>digitalRead</code>, and <code>digitalWrite</code> functions work as usual, so to read GPIO2, call <code>digitalRead(2)</code>.</p>
<p>Digital pins 0—15 can be <code>INPUT</code>, <code>OUTPUT</code>, or <code>INPUT_PULLUP</code>.
Pin 16 can be <code>INPUT</code>, <code>OUTPUT</code> or <code>INPUT_PULLDOWN_16</code>. At startup, pins are configured as <code>INPUT</code>.</p>
<p>Pins may also serve other functions, like Serial, I2C, SPI. These functions are normally activated by the corresponding library. The diagram below shows pin mapping for the popular ESP-12 module.</p>
<p><img src="esp12.png" alt="Pin Functions"></p>
<p>Digital pins 6—11 are not shown on this diagram because they are used to connect flash memory chip on most modules. Trying to use these pins as IOs will likely cause the program to crash.</p>
<p>Note that some boards and modules (ESP-12ED, NodeMCU 1.0) also break out pins 9 and 11. These may be used as IO if flash chip works in DIO mode (as opposed to QIO, which is the default one).</p>
<p>Pin interrupts are supported through <code>attachInterrupt</code>, <code>detachInterrupt</code> functions.
Interrupts may be attached to any GPIO pin, except GPIO16. Standard Arduino interrupt
types are supported: <code>CHANGE</code>, <code>RISING</code>, <code>FALLING</code>.</p>
<h2 id="analog-input">Analog input</h2>
<p>ESP8266 has a single ADC channel available to users. It may be used either to read voltage at ADC pin, or to read module supply voltage (VCC).</p>
<p>To read external voltage applied to ADC pin, use <code>analogRead(A0)</code>. Input voltage range is 0 — 1.0V.</p>
<p>To read VCC voltage, ADC pin must be kept unconnected. Additionally, the following line has to be added to the sketch:</p>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">ADC_MODE</span><span class="p">(</span><span class="n">ADC_VCC</span><span class="p">);</span>
</code></pre></div>
<p>This line has to appear outside of any functions, for instance right after the <code>#include</code> lines of your sketch.</p>
<h2 id="analog-output">Analog output</h2>
<p><code>analogWrite(pin, value)</code> enables software PWM on the given pin. PWM may be used on pins 0 to 16.
Call <code>analogWrite(pin, 0)</code> to disable PWM on the pin. <code>value</code> may be in range from 0 to <code>PWMRANGE</code>, which is equal to 1023 by default. PWM range may be changed by calling <code>analogWriteRange(new_range)</code>.</p>
<p>PWM frequency is 1kHz by default. Call <code>analogWriteFreq(new_frequency)</code> to change the frequency.</p>
<h2 id="timing-and-delays">Timing and delays</h2>
<p><code>millis()</code> and <code>micros()</code> return the number of milliseconds and microseconds elapsed after reset, respectively.</p>
<p><code>delay(ms)</code> pauses the sketch for a given number of milliseconds and allows WiFi and TCP/IP tasks to run.
<code>delayMicroseconds(us)</code> pauses for a given number of microseconds.</p>
<p>Remember that there is a lot of code that needs to run on the chip besides the sketch
when WiFi is connected. WiFi and TCP/IP libraries get a chance to handle any pending
events each time the <code>loop()</code> function completes, OR when <code>delay</code> is called.
If you have a loop somewhere in your sketch that takes a lot of time (&gt;50ms) without
calling <code>delay</code>, you might consider adding a call to <code>delay</code> function to keep the WiFi
stack running smoothly.</p>
<p>There is also a <code>yield()</code> function which is equivalent to <code>delay(0)</code>. The <code>delayMicroseconds</code>
function, on the other hand, does not yield to other tasks, so using it for delays
more than 20 milliseconds is not recommended.</p>
<h2 id="serial">Serial</h2>
<p><code>Serial</code> object works much the same way as on a regular Arduino. Apart from hardware FIFO (128 bytes for TX and RX) HardwareSerial has additional 256-byte TX and RX buffers. Both transmit and receive is interrupt-driven. Write and read functions only block the sketch execution when the respective FIFO/buffers are full/empty.</p>
<p><code>Serial</code> uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling <code>Serial.swap()</code> after <code>Serial.begin</code>. Calling <code>swap</code> again maps UART0 back to GPIO1 and GPIO3.</p>
<p><code>Serial1</code> uses UART1, TX pin is GPIO2. UART1 can not be used to receive data because normally it&#39;s RX pin is occupied for flash chip connection. To use <code>Serial1</code>, call <code>Serial1.begin(baudrate)</code>.</p>
<p>If <code>Serial1</code> is not used and <code>Serial</code> is not swapped - TX for UART0 can be mapped to GPIO2 instead by calling <code>Serial.set_tx(2)</code> after <code>Serial.begin</code> or directly with <code>Serial.begin(baud, config, mode, 2)</code>.</p>
<p>By default the diagnostic output from WiFi libraries is disabled when you call <code>Serial.begin</code>. To enable debug output again, call <code>Serial.setDebugOutput(true)</code>. To redirect debug output to <code>Serial1</code> instead, call <code>Serial1.setDebugOutput(true)</code>.</p>
<p>You also need to use <code>Serial.setDebugOutput(true)</code> to enable output from <code>printf()</code> function.</p>
<p>Both <code>Serial</code> and <code>Serial1</code> objects support 5, 6, 7, 8 data bits, odd (O), even (E), and no (N) parity, and 1 or 2 stop bits. To set the desired mode, call <code>Serial.begin(baudrate, SERIAL_8N1)</code>, <code>Serial.begin(baudrate, SERIAL_6E2)</code>, etc.</p>
<h2 id="progmem">Progmem</h2>
<p>The Program memory features work much the same way as on a regular Arduino; placing read only data and strings in read only memory and freeing heap for your application.
The important difference is that on the ESP8266 the literal strings are not pooled. This means that the same literal string defined inside a <code>F(&quot;&quot;)</code> and/or <code>PSTR(&quot;&quot;)</code> will take up space for each instance in the code. So you will need to manage the duplicate strings yourself.</p>
<p>There is one additional helper macro to make it easier to pass <code>const PROGMEM</code> strings to methods that take a <code>__FlashStringHelper</code> called <code>FPSTR()</code>. The use of this will help make it easier to pool strings.
Not pooling strings...</p>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="n">String</span> <span class="n">response1</span><span class="p">;</span>
<span class="n">response1</span> <span class="o">+=</span> <span class="n">F</span><span class="p">(</span><span class="s">&quot;http:&quot;</span><span class="p">);</span>
<span class="p">...</span>
<span class="n">String</span> <span class="n">response2</span><span class="p">;</span>
<span class="n">response2</span> <span class="o">+=</span> <span class="n">F</span><span class="p">(</span><span class="s">&quot;http:&quot;</span><span class="p">);</span>
</code></pre></div>
<p>using FPSTR would become...</p>
<div class="highlight"><pre><code class="language-c++" data-lang="c++"><span class="k">const</span> <span class="kt">char</span> <span class="n">HTTP</span><span class="p">[]</span> <span class="n">PROGMEM</span> <span class="o">=</span> <span class="s">&quot;http:&quot;</span><span class="p">;</span>
<span class="p">...</span>
<span class="p">{</span>
<span class="n">String</span> <span class="n">response1</span><span class="p">;</span>
<span class="n">response1</span> <span class="o">+=</span> <span class="n">FPSTR</span><span class="p">(</span><span class="n">HTTP</span><span class="p">);</span>
<span class="p">...</span>
<span class="n">String</span> <span class="n">response2</span><span class="p">;</span>
<span class="n">response2</span> <span class="o">+=</span> <span class="n">FPSTR</span><span class="p">(</span><span class="n">HTTP</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,266 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href="http://gmpg.org/xfn/11" rel="profile">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>
&middot; ESP8266 Arduino Core
</title>
<!-- CSS -->
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/poole.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/syntax.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/hyde.css">
<link rel="stylesheet" href="/Arduino/versions/2.1.0-rc2/public/css/icons.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Icons -->
<link rel="shortcut icon" href="/Arduino/versions/2.1.0-rc2/public/favicon.ico">
<!-- RSS -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/Arduino/versions/2.1.0-rc2/public/js/toc.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#toc').toc({ listType: 'ul', showSpeed: 0, title: '', headers: 'h1, h2', minimumHeaders: 2 });
});
</script>
</head>
<body>
<div class="version-bar">
This documentation is for version 2.1.0-rc2. <a href="http://esp8266.github.io/Arduino/versions">Other versions.</a>
</div>
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<h2>
<a href="http://esp8266.github.io/Arduino">
ESP8266 Arduino Core
</a>
</h2>
</div>
<nav class="sidebar-nav">
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/installing.html">Installation</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/reference.html">Reference</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/libraries.html">Libraries</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/filesystem.html">File System</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/ota_updates/ota_updates.html">OTA Update</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/boards.html">Supported Hardware</a>
<a class="sidebar-nav-item" href="/Arduino/versions/2.1.0-rc2/doc/changes.html">Change Log</a>
</nav>
<p>
<a href="https://github.com/esp8266/Arduino"><div id="gh-icon"></div>esp8266/Arduino</a>
</p>
<p class="lead">Documentation for ESP8266 Arduino Core. Installation instructions, functions and classes reference.
</p>
</div>
</div>
<div class="content container">
<p>Welcome to the ESP8266 Arduino core documentation, version 2.1.0-rc2.</p>
<p>Links on the left will take you to various sections.</p>
<p>Source code of this version is available from GitHub: <a href="https://github.com/esp8266/Arduino/archive/2.1.0-rc2.zip">https://github.com/esp8266/Arduino/archive/2.1.0-rc2.zip</a></p>
</div>
</body>
</html>

View File

@ -0,0 +1,265 @@
/*
* __ __
* /\ \ /\ \
* \ \ \___ __ __ \_\ \ __
* \ \ _ `\/\ \/\ \ /'_` \ /'__`\
* \ \ \ \ \ \ \_\ \/\ \_\ \/\ __/
* \ \_\ \_\/`____ \ \___,_\ \____\
* \/_/\/_/`/___/> \/__,_ /\/____/
* /\___/
* \/__/
*
* Designed, built, and released under MIT license by @mdo. Learn more at
* https://github.com/poole/hyde.
*/
/*
* Contents
*
* Global resets
* Sidebar
* Container
* Reverse layout
* Themes
*/
/*
* Global resets
*
* Update the foundational and global aspects of the page.
*/
html {
font-family: "PT Sans", Helvetica, Arial, sans-serif;
}
@media (min-width: 48em) {
html {
font-size: 16px;
}
}
@media (min-width: 58em) {
html {
font-size: 20px;
}
}
/*
* Sidebar
*
* Flexible banner for housing site name, intro, and "footer" content. Starts
* out above content in mobile and later moves to the side with wider viewports.
*/
.sidebar {
text-align: left;
padding: 2rem 1rem;
color: rgba(0,0,0,.5);
background-color: #f8f8f8;
}
@media (min-width: 48em) {
.sidebar {
position: absolute;
top: 0;
left: 0;
width: 18rem;
}
}
.version-bar {
position: fixed;
z-index: 10;
background-color: #f0f0f0;
width: 100%;
padding: 5px;
}
/* Sidebar links */
.sidebar a {
color: #a33;
}
/* About section */
.sidebar-about h1 {
margin-top: 0;
font-family: "Abril Fatface", serif;
font-size: 3.25rem;
}
/* Sidebar nav */
.sidebar-nav {
margin-bottom: 1rem;
}
.sidebar-nav-item {
display: block;
line-height: 1.75;
}
a.sidebar-nav-item:hover,
a.sidebar-nav-item:focus {
text-decoration: underline;
}
.sidebar-nav-item.active {
font-weight: bold;
}
/* Sticky sidebar
*
* Add the `sidebar-sticky` class to the sidebar's container to affix it the
* contents to the bottom of the sidebar in tablets and up.
*/
@media (min-width: 48em) {
.sidebar-sticky {
position: absolute;
right: 1rem;
bottom: 1rem;
left: 1rem;
}
}
/* Container
*
* Align the contents of the site above the proper threshold with some margin-fu
* with a 25%-wide `.sidebar`.
*/
.content {
padding-top: 4rem;
padding-bottom: 4rem;
}
@media (min-width: 48em) {
.content {
max-width: 38rem;
margin-left: 20rem;
margin-right: 2rem;
}
}
@media (min-width: 64em) {
.content {
margin-left: 22rem;
margin-right: 4rem;
}
}
/*
* Reverse layout
*
* Flip the orientation of the page by placing the `.sidebar` on the right.
*/
@media (min-width: 48em) {
.layout-reverse .sidebar {
left: auto;
right: 0;
}
.layout-reverse .content {
margin-left: 2rem;
margin-right: 20rem;
}
}
@media (min-width: 64em) {
.layout-reverse .content {
margin-left: 4rem;
margin-right: 22rem;
}
}
/*
* Themes
*
* As of v1.1, Hyde includes optional themes to color the sidebar and links
* within blog posts. To use, add the class of your choosing to the `body`.
*/
/* Base16 (http://chriskempson.github.io/base16/#default) */
/* Red */
.theme-base-xx .sidebar {
background-color: #ac4142;
}
.theme-base-xx .content a,
.theme-base-xx .related-posts li a:hover {
color: #ac4142;
}
/* Red */
.theme-base-08 .sidebar {
background-color: #ac4142;
}
.theme-base-08 .content a,
.theme-base-08 .related-posts li a:hover {
color: #ac4142;
}
/* Orange */
.theme-base-09 .sidebar {
background-color: #d28445;
}
.theme-base-09 .content a,
.theme-base-09 .related-posts li a:hover {
color: #d28445;
}
/* Yellow */
.theme-base-0a .sidebar {
background-color: #f4bf75;
}
.theme-base-0a .content a,
.theme-base-0a .related-posts li a:hover {
color: #f4bf75;
}
/* Green */
.theme-base-0b .sidebar {
background-color: #90a959;
}
.theme-base-0b .content a,
.theme-base-0b .related-posts li a:hover {
color: #90a959;
}
/* Cyan */
.theme-base-0c .sidebar {
background-color: #75b5aa;
}
.theme-base-0c .content a,
.theme-base-0c .related-posts li a:hover {
color: #75b5aa;
}
/* Blue */
.theme-base-0d .sidebar {
background-color: #6a9fb5;
}
.theme-base-0d .content a,
.theme-base-0d .related-posts li a:hover {
color: #6a9fb5;
}
/* Magenta */
.theme-base-0e .sidebar {
background-color: #aa759f;
}
.theme-base-0e .content a,
.theme-base-0e .related-posts li a:hover {
color: #aa759f;
}
/* Brown */
.theme-base-0f .sidebar {
background-color: #8f5536;
}
.theme-base-0f .content a,
.theme-base-0f .related-posts li a:hover {
color: #8f5536;
}

View File

@ -0,0 +1,32 @@
#gh-icon {
background: url("/Arduino/versions/2.1.0-rc2/public/gh.png") no-repeat top left;
width: 32px;
height: 32px;
display: inline-block;
vertical-align: middle;
margin-right: 5px;
}
@media
(-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
#gh-icon {
background-image: url("/Arduino/versions/2.1.0-rc2/public/gh@2.png");
background-size: 100%;
}
}
.clickable-header {
cursor:pointer;
}
.clickable-header:hover {
text-decoration:underline;
}
.top-level-header {
display:inline;
}
.back-to-top {
margin-left:5px;
cursor:pointer;
vertical-align: top;
}

View File

@ -0,0 +1,430 @@
/*
* ___
* /\_ \
* _____ ___ ___\//\ \ __
* /\ '__`\ / __`\ / __`\\ \ \ /'__`\
* \ \ \_\ \/\ \_\ \/\ \_\ \\_\ \_/\ __/
* \ \ ,__/\ \____/\ \____//\____\ \____\
* \ \ \/ \/___/ \/___/ \/____/\/____/
* \ \_\
* \/_/
*
* Designed, built, and released under MIT license by @mdo. Learn more at
* https://github.com/poole/poole.
*/
/*
* Contents
*
* Body resets
* Custom type
* Messages
* Container
* Masthead
* Posts and pages
* Pagination
* Reverse layout
* Themes
*/
/*
* Body resets
*
* Update the foundational and global aspects of the page.
*/
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
html {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
}
@media (min-width: 38em) {
html {
font-size: 20px;
}
}
body {
color: #515151;
background-color: #fff;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
/* No `:visited` state is required by default (browsers will use `a`) */
a {
color: #b03030;
text-decoration: none;
}
a strong {
color: inherit;
}
/* `:focus` is linked to `:hover` for basic accessibility */
a:hover,
a:focus {
text-decoration: underline;
}
/* Headings */
h1, h2, h3, h4, h5, h6 {
margin-bottom: .5rem;
font-weight: bold;
line-height: 1.25;
color: #313131;
text-rendering: optimizeLegibility;
}
h1 {
font-size: 2rem;
}
h2 {
margin-top: 1rem;
font-size: 1.5rem;
}
h3 {
margin-top: 1.5rem;
font-size: 1.25rem;
}
h4, h5, h6 {
margin-top: 1rem;
font-size: 1rem;
}
/* Body text */
p {
margin-top: 0;
margin-bottom: 1rem;
}
strong {
color: #303030;
}
/* Lists */
ul, ol, dl {
margin-top: 0;
margin-bottom: 1rem;
}
dt {
font-weight: bold;
}
dd {
margin-bottom: .5rem;
}
/* Misc */
hr {
position: relative;
margin: 1.5rem 0;
border: 0;
border-top: 1px solid #eee;
border-bottom: 1px solid #fff;
}
abbr {
font-size: 85%;
font-weight: bold;
color: #555;
text-transform: uppercase;
}
abbr[title] {
cursor: help;
border-bottom: 1px dotted #e5e5e5;
}
/* Code */
code,
pre {
font-family: Menlo, Monaco, "Courier New", monospace;
}
code {
padding: .25em .5em;
font-size: 85%;
color: #000;
background-color: #f8f8f8;
border-radius: 3px;
}
pre {
display: block;
margin-top: 0;
margin-bottom: 1rem;
padding: 1rem;
font-size: .8rem;
line-height: 1.4;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
background-color: #f9f9f9;
}
pre code {
padding: 0;
font-size: 100%;
color: inherit;
background-color: transparent;
}
/* Pygments via Jekyll */
.highlight {
margin-bottom: 1rem;
border-radius: 4px;
}
.highlight pre {
margin-bottom: 0;
}
/* Gist via GitHub Pages */
.gist .gist-file {
font-family: Menlo, Monaco, "Courier New", monospace !important;
}
.gist .markdown-body {
padding: 15px;
}
.gist pre {
padding: 0;
background-color: transparent;
}
.gist .gist-file .gist-data {
font-size: .8rem !important;
line-height: 1.4;
}
.gist code {
padding: 0;
color: inherit;
background-color: transparent;
border-radius: 0;
}
/* Quotes */
blockquote {
padding: .5rem 1rem;
margin: .8rem 0;
color: #7a7a7a;
border-left: .25rem solid #e5e5e5;
}
blockquote p:last-child {
margin-bottom: 0;
}
@media (min-width: 30em) {
blockquote {
padding-right: 5rem;
padding-left: 1.25rem;
}
}
img {
display: block;
max-width: 100%;
margin: 0 0 1rem;
border-radius: 5px;
}
/* Tables */
table {
margin-bottom: 1rem;
width: 100%;
border: 1px solid #e5e5e5;
border-collapse: collapse;
}
td,
th {
padding: .25rem .5rem;
border: 1px solid #e5e5e5;
}
tbody tr:nth-child(odd) td,
tbody tr:nth-child(odd) th {
background-color: #f9f9f9;
}
/*
* Custom type
*
* Extend paragraphs with `.lead` for larger introductory text.
*/
.lead {
font-size: 1.25rem;
font-weight: 300;
}
/*
* Messages
*
* Show alert messages to users. You may add it to single elements like a `<p>`,
* or to a parent if there are multiple elements to show.
*/
.message {
margin-bottom: 1rem;
padding: 1rem;
color: #717171;
background-color: #f9f9f9;
}
/*
* Container
*
* Center the page content.
*/
.container {
max-width: 38rem;
padding-left: 1rem;
padding-right: 1rem;
margin-left: auto;
margin-right: auto;
}
/*
* Masthead
*
* Super small header above the content for site name and short description.
*/
.masthead {
padding-top: 1rem;
padding-bottom: 1rem;
margin-bottom: 3rem;
}
.masthead-title {
margin-top: 0;
margin-bottom: 0;
color: #505050;
}
.masthead-title a {
color: #505050;
}
.masthead-title small {
font-size: 75%;
font-weight: 400;
color: #c0c0c0;
letter-spacing: 0;
}
/*
* Posts and pages
*
* Each post is wrapped in `.post` and is used on default and post layouts. Each
* page is wrapped in `.page` and is only used on the page layout.
*/
.page,
.post {
margin-bottom: 4em;
}
/* Blog post or page title */
.page-title,
.post-title,
.post-title a {
color: #303030;
}
.page-title,
.post-title {
margin-top: 0;
}
/* Meta data line below post title */
.post-date {
display: block;
margin-top: -.5rem;
margin-bottom: 1rem;
color: #9a9a9a;
}
/* Related posts */
.related {
padding-top: 2rem;
padding-bottom: 2rem;
border-top: 1px solid #eee;
}
.related-posts {
padding-left: 0;
list-style: none;
}
.related-posts h3 {
margin-top: 0;
}
.related-posts li small {
font-size: 75%;
color: #999;
}
.related-posts li a:hover {
color: #268bd2;
text-decoration: none;
}
.related-posts li a:hover small {
color: inherit;
}
/*
* Pagination
*
* Super lightweight (HTML-wise) blog pagination. `span`s are provide for when
* there are no more previous or next posts to show.
*/
.pagination {
overflow: hidden; /* clearfix */
margin-left: -1rem;
margin-right: -1rem;
font-family: "PT Sans", Helvetica, Arial, sans-serif;
color: #ccc;
text-align: center;
}
/* Pagination items can be `span`s or `a`s */
.pagination-item {
display: block;
padding: 1rem;
border: 1px solid #eee;
}
.pagination-item:first-child {
margin-bottom: -1px;
}
/* Only provide a hover state for linked pagination items */
a.pagination-item:hover {
background-color: #f5f5f5;
}
@media (min-width: 30em) {
.pagination {
margin: 3rem 0;
}
.pagination-item {
float: left;
width: 50%;
}
.pagination-item:first-child {
margin-bottom: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.pagination-item:last-child {
margin-left: -1px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
}

View File

@ -0,0 +1,65 @@
.highlight .hll { background-color: #ffc; }
.highlight .c { color: #999; } /* Comment */
.highlight .err { color: #a00; background-color: #faa } /* Error */
.highlight .k { color: #069; } /* Keyword */
.highlight .o { color: #555 } /* Operator */
.highlight .cm { color: #09f; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #099 } /* Comment.Preproc */
.highlight .c1 { color: #999; } /* Comment.Single */
.highlight .cs { color: #999; } /* Comment.Special */
.highlight .gd { background-color: #fcc; border: 1px solid #c00 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #f00 } /* Generic.Error */
.highlight .gh { color: #030; } /* Generic.Heading */
.highlight .gi { background-color: #cfc; border: 1px solid #0c0 } /* Generic.Inserted */
.highlight .go { color: #aaa } /* Generic.Output */
.highlight .gp { color: #009; } /* Generic.Prompt */
.highlight .gs { } /* Generic.Strong */
.highlight .gu { color: #030; } /* Generic.Subheading */
.highlight .gt { color: #9c6 } /* Generic.Traceback */
.highlight .kc { color: #069; } /* Keyword.Constant */
.highlight .kd { color: #069; } /* Keyword.Declaration */
.highlight .kn { color: #069; } /* Keyword.Namespace */
.highlight .kp { color: #069 } /* Keyword.Pseudo */
.highlight .kr { color: #069; } /* Keyword.Reserved */
.highlight .kt { color: #078; } /* Keyword.Type */
.highlight .m { color: #f60 } /* Literal.Number */
.highlight .s { color: #d44950 } /* Literal.String */
.highlight .na { color: #4f9fcf } /* Name.Attribute */
.highlight .nb { color: #366 } /* Name.Builtin */
.highlight .nc { color: #0a8; } /* Name.Class */
.highlight .no { color: #360 } /* Name.Constant */
.highlight .nd { color: #99f } /* Name.Decorator */
.highlight .ni { color: #999; } /* Name.Entity */
.highlight .ne { color: #c00; } /* Name.Exception */
.highlight .nf { color: #c0f } /* Name.Function */
.highlight .nl { color: #99f } /* Name.Label */
.highlight .nn { color: #0cf; } /* Name.Namespace */
.highlight .nt { color: #2f6f9f; } /* Name.Tag */
.highlight .nv { color: #033 } /* Name.Variable */
.highlight .ow { color: #000; } /* Operator.Word */
.highlight .w { color: #bbb } /* Text.Whitespace */
.highlight .mf { color: #f60 } /* Literal.Number.Float */
.highlight .mh { color: #f60 } /* Literal.Number.Hex */
.highlight .mi { color: #f60 } /* Literal.Number.Integer */
.highlight .mo { color: #f60 } /* Literal.Number.Oct */
.highlight .sb { color: #c30 } /* Literal.String.Backtick */
.highlight .sc { color: #c30 } /* Literal.String.Char */
.highlight .sd { color: #c30; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #c30 } /* Literal.String.Double */
.highlight .se { color: #c30; } /* Literal.String.Escape */
.highlight .sh { color: #c30 } /* Literal.String.Heredoc */
.highlight .si { color: #a00 } /* Literal.String.Interpol */
.highlight .sx { color: #c30 } /* Literal.String.Other */
.highlight .sr { color: #3aa } /* Literal.String.Regex */
.highlight .s1 { color: #c30 } /* Literal.String.Single */
.highlight .ss { color: #fc3 } /* Literal.String.Symbol */
.highlight .bp { color: #366 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #033 } /* Name.Variable.Class */
.highlight .vg { color: #033 } /* Name.Variable.Global */
.highlight .vi { color: #033 } /* Name.Variable.Instance */
.highlight .il { color: #f60 } /* Literal.Number.Integer.Long */
.css .o,
.css .o + .nt,
.css .nt + .nt { color: #999; }

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -0,0 +1,94 @@
// https://github.com/ghiculescu/jekyll-table-of-contents
(function($){
$.fn.toc = function(options) {
var defaults = {
noBackToTopLinks: false,
title: '<i>Jump to...</i>',
minimumHeaders: 3,
headers: 'h1, h2, h3, h4, h5, h6',
listType: 'ol', // values: [ol|ul]
showEffect: 'show', // values: [show|slideDown|fadeIn|none]
showSpeed: 'slow' // set to 0 to deactivate effect
},
settings = $.extend(defaults, options);
function fixedEncodeURIComponent (str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
var headers = $(settings.headers).filter(function() {
// get all headers with an ID
var previousSiblingName = $(this).prev().attr( "name" );
if (!this.id && previousSiblingName) {
this.id = $(this).attr( "id", previousSiblingName.replace(/\./g, "-") );
}
if (this.id == 'table-of-contents') {
$(this).hide();
$(this).next().hide();
return false;
}
return this.id;
}), output = $(this);
if (!headers.length || headers.length < settings.minimumHeaders || !output.length) {
$(this).hide();
return;
}
if (0 === settings.showSpeed) {
settings.showEffect = 'none';
}
var render = {
show: function() { output.hide().html(html).show(settings.showSpeed); },
slideDown: function() { output.hide().html(html).slideDown(settings.showSpeed); },
fadeIn: function() { output.hide().html(html).fadeIn(settings.showSpeed); },
none: function() { output.html(html); }
};
var get_level = function(ele) { return parseInt(ele.nodeName.replace("H", ""), 10); }
var highest_level = headers.map(function(_, ele) { return get_level(ele); }).get().sort()[0];
var return_to_top = '<i class="fa fa-chevron-up back-to-top"> </i>';
var level = get_level(headers[0]),
this_level,
html = settings.title + " <"+settings.listType+">";
headers.on('click', function() {
if (!settings.noBackToTopLinks) {
window.location.hash = this.id;
}
})
.addClass('clickable-header')
.each(function(_, header) {
this_level = get_level(header);
if (!settings.noBackToTopLinks && this_level === highest_level) {
$(header).addClass('top-level-header').after(return_to_top);
}
if (this_level === level) // same level as before; same indenting
html += "<li><a href='#" + fixedEncodeURIComponent(header.id) + "'>" + header.innerHTML + "</a>";
else if (this_level <= level){ // higher level than before; end parent ol
for(i = this_level; i < level; i++) {
html += "</li></"+settings.listType+">"
}
html += "<li><a href='#" + fixedEncodeURIComponent(header.id) + "'>" + header.innerHTML + "</a>";
}
else if (this_level > level) { // lower level than before; expand the previous to contain a ol
for(i = this_level; i > level; i--) {
html += "<"+settings.listType+"><li>"
}
html += "<a href='#" + fixedEncodeURIComponent(header.id) + "'>" + header.innerHTML + "</a>";
}
level = this_level; // update for the next one
});
html += "</"+settings.listType+">";
if (!settings.noBackToTopLinks) {
$(document).on('click', '.back-to-top', function() {
$(window).scrollTop(0);
window.location.hash = '';
});
}
render[settings.showEffect]();
};
})(jQuery);

View File