Skip to content

Commit

Permalink
Add WiFi mode documentation (nodemcu#2191)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstoer authored and Christian Krämer committed Jan 11, 2018
1 parent 5c587b1 commit 810aae4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion docs/en/modules/wifi.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,44 @@
!!! important
The WiFi subsystem is maintained by background tasks that must run periodically. Any function or task that takes longer than 15ms (milliseconds) may cause the WiFi subsystem to crash. To avoid these potential crashes, it is advised that the WiFi subsystem be suspended with [wifi.suspend()](#wifisuspend) prior to the execution of any tasks or functions that exceed this 15ms guideline.

### WiFi modes
Courtesy: content for this chapter is borrowed/inspired by the [Arduino ESP8266 WiFi documentation](https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html).

Devices that connect to WiFi network are called stations (STA). Connection to Wi-Fi is provided by an access point (AP), that acts as a hub for one or more stations. The access point on the other end is connected to a wired network. An access point is usually integrated with a router to provide access from Wi-Fi network to the internet. Each access point is recognized by a SSID (**S**ervice **S**et **ID**entifier), that essentially is the name of network you select when connecting a device (station) to the WiFi.

Each ESP8266 module can operate as a station, so we can connect it to the WiFi network. It can also operate as a soft access point (soft-AP), to establish its own WiFi network. Therefore, we can connect other stations to such modules. Third, ESP8266 is also able to operate both in station and soft access point mode *at the same time*. This offers the possibility of building e.g. [mesh networks](https://en.wikipedia.org/wiki/Mesh_networking).

#### Station
Station (STA) mode is used to get the ESP8266 connected to a WiFi network established by an access point.

![ESP8266 operating in station mode](../../img/WiFi-station-mode.png)

#### Soft Access Point
An access point (AP) is a device that provides access to Wi-Fi network to other devices (stations) and connects them further to a wired network. ESP8266 can provide similar functionality except it does not have interface to a wired network. Such mode of operation is called soft access point (soft-AP). The maximum number of stations connected to the soft-AP is five.

![ESP8266 operating in Soft Access Point mode](../../img/WiFi-softap-mode.png)

The soft-AP mode is often used and an intermediate step before connecting ESP to a WiFi in a station mode. This is when SSID and password to such network is not known upfront. The module first boots in soft-AP mode, so we can connect to it using a laptop or a mobile phone. Then we are able to provide credentials to the target network. Once done ESP is switched to the station mode and can connect to the target WiFi.

Such functionality is provided by the [NodeMCU enduser setup module](../modules/enduser-setup.md).

#### Station + Soft Access Point
Another handy application of soft-AP mode is to set up [mesh networks](https://en.wikipedia.org/wiki/Mesh_networking). ESP can operate in both soft-AP and Station mode so it can act as a node of a mesh network.

![ESP8266 operating in station AP mode](../../img/WiFi-stationap-mode.png)


### Function reference

The NodeMCU WiFi control is spread across several tables:

- `wifi` for overall WiFi configuration
- [`wifi`](#wifigetchannel) for overall WiFi configuration
- [`wifi.sta`](#wifista-module) for station mode functions
- [`wifi.ap`](#wifiap-module) for wireless access point (WAP or simply AP) functions
- [`wifi.ap.dhcp`](#wifiapdhcp-module) for DHCP server control
- [`wifi.eventmon`](#wifieventmon-module) for wifi event monitor


## wifi.getchannel()

Gets the current WiFi channel.
Expand Down
Binary file added docs/img/WiFi-softap-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/WiFi-station-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/WiFi-stationap-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 810aae4

Please sign in to comment.