Skip to content

esp32/modsmartconfig: Add smartconfig module. #13658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/library/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ The following libraries are specific to the ESP8266 and ESP32.

espnow.rst

.. toctree::
:maxdepth: 1

smartconfig.rst

Libraries specific to the RP2040
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
134 changes: 134 additions & 0 deletions docs/library/smartconfig.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
:mod:`smartconfig` --- support for the SmartConfig provisioning protocol
========================================================================

.. module:: smartconfig
:synopsis: SmartConfig provisioning protocol support

This module provides an interface to the SmartConfig provisioning protocol
provided by Espressif on ESP32 devices (`API docs <https://docs.espressif.com/
projects/esp-idf/en/latest/esp32/api-reference/network/esp_smartconfig.html>`_).

Introduction
------------

The SmartConfig\ :sup:`TM` is a provisioning technology developed by TI to
connect a new Wi-Fi device to a Wi-Fi network. It uses a mobile application to
broadcast the network credentials from a smartphone, or a tablet, to an
un-provisioned Wi-Fi device.

The advantage of this technology is that the device does not need to directly
know SSID or password of an Access Point (AP). This information is provided
using the smartphone. This is particularly important to headless device and
systems, due to their lack of a user interface.

A simple example would be::

import network, time
import smartconfig

# A WLAN interface must be instancing to start smartconfig progress
sta = network.WLAN(network.STA_IF)
sta.active(True)

smartconfig.type(smartconfig.TYPE_ESPTOUCH_AIRKISS)

smartconfig.start()

while not smartconfig.done():
time.sleep_ms(100)

print(smartconfig.info())
# (ssid, password, bssid, type[, v2_data])

smartconfig.stop()

Functions
---------

.. function:: version()

Get the version of SmartConfig.

.. function:: start()

Start the SmartConfig process.

After received the broadcast data, it will try to use the data to connect
to the AP, the ``smartconfig.done()`` function returns ``True`` regardless
of whether the connection is successful or not.

**Note:** This function automatically calls the ``smartconfig.stop()``
function first.

.. function:: stop()

Stop the SmartConfig process.

.. function:: done()

Returns ``True`` if the SmartConfig process completed, and ``False`` for
otherwise.

**Note:** If returns ``True``, it will automatically calls the
``smartconfig.stop()`` function.

.. function:: timeout([seconds])

Gets or sets the timeout seconds for the SmartConfig process.

Parameter *seconds* range: 15s ~ 255s.

.. function:: fast_mode([is_fast_mode])

Get or set the mode of SmartConfig. Default is normal mode.

.. function:: v2_key([key])

Get or set the crypt key string for EspTouch V2 protocol.

*key* length must be 16 characters.

Passing ``None`` or an empty string ``''`` to clear the key.

.. function:: info()

Returns a 4 or 5-tuple ``(ssid, password, bssid, type[, v2_data])``.

**Note:** ``v2_data`` is the custom data for EspTouch V2 protocol type.

.. function:: ssid()

Returns the received ``ssid`` as ``str``.

.. function:: password()

Returns the received ``password`` as ``str``.

.. function:: bssid()

Returns the received ``bssid`` as ``bytes``.

.. function:: type([type])

Get or set SmartConfig protocol *type*.

You must set a protocol *type* for receiving data that broadcast by your phone
over the same protocol, usually set to ``smartconfig.TYPE_ESPTOUCH_AIRKISS``,
which can cover mostly of the application scenarios.

When SmartConfig process done, you can get the protocol type used by the
phone.

.. function:: v2_data()

Returns the received ``v2_data`` as ``str``.

Constants
---------

.. data:: TYPE_ESPTOUCH
TYPE_AIRKISS
TYPE_ESPTOUCH_AIRKISS
TYPE_ESPTOUCH_V2

SmartConfig protocol types.
1 change: 1 addition & 0 deletions ports/esp32/esp32_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ list(APPEND MICROPY_SOURCE_PORT
machine_rtc.c
machine_sdcard.c
modespnow.c
modsmartconfig.c
)
list(TRANSFORM MICROPY_SOURCE_PORT PREPEND ${MICROPY_PORT_DIR}/)
list(APPEND MICROPY_SOURCE_PORT ${CMAKE_BINARY_DIR}/pins.c)
Expand Down
Loading
Loading