← index #3427PR #13658
Likely Duplicate · medium · value 4.975
QUERY · ISSUE

SmartConfig ESP8266 and ESP32

openby zaforicopened 2017-11-08updated 2024-10-31
enhancementport-esp8266port-esp32

Add smartconfig capability to micropython for esp8266 and esp32

Add the following to modesp.c
{ MP_ROM_QSTR(MP_QSTR_smartconfig), MP_ROM_PTR(&mp_module_esp_smartconfig) },

Create smartconfig python wrapper. An old example is at https://github.com/mianos/micropython/blob/master/esp8266/mod_esp_smartconfig.c

CANDIDATE · PULL REQUEST

esp32/modsmartconfig: Add smartconfig module.

openby walklinewangopened 2024-02-13updated 2025-06-19
port-esp32

Here is the test code which shown all methods and constants belong to smartconfig module, I was compiled firmware with micropython master (synced yesterday) and esp-idf v5.0.4, separately tested on esp32 and esp32c3 develop board.

import network
import time
import smartconfig

import esp
esp.osdebug(0)


TYPES = {
    smartconfig.TYPE_ESPTOUCH: 'ESPTOUCH',
    smartconfig.TYPE_AIRKISS: 'AIRKISS',
    smartconfig.TYPE_ESPTOUCH_AIRKISS: 'ESPTOUCH_AIRKISS',
    smartconfig.TYPE_ESPTOUCH_V2: 'ESPTOUCH_V2'
}

TIMEOUT = 120_000 # ms
TESTING_ESPTOUCH_V2 = False

def run_test():
    sta = network.WLAN(network.STA_IF)
    _ = sta.active(True)

    print('smartconfig')
    print(f'  - version: {smartconfig.version()}')

    if TESTING_ESPTOUCH_V2:
        smartconfig.v2_key('1234567890123456')
        print(f'  - v2 key: {smartconfig.v2_key()}')

        smartconfig.type(smartconfig.TYPE_ESPTOUCH_V2)
    else:
        smartconfig.type(smartconfig.TYPE_ESPTOUCH_AIRKISS)
    print(f'  - type: {TYPES[smartconfig.type()]}')

    smartconfig.fast_mode(True)
    print(f'  - fast mode: {smartconfig.fast_mode()}')

    smartconfig.timeout(15)
    print(f'  - timeout: {smartconfig.timeout()}')

    smartconfig.start()

    start_ms = time.ticks_ms()

    while not smartconfig.done():
        if time.ticks_ms() - start_ms > TIMEOUT:
            print('smartconfig timeout')
            smartconfig.stop()
            return

        time.sleep_ms(100)

    print('smartconfig done, ', end='')

    if sta.status() == network.STAT_GOT_IP:
        print('and connected to ap')
        print(f'smartconfig info: {smartconfig.info()}')
        print(f'  - ssid: "{smartconfig.ssid()}"')
        print(f'  - password: "{smartconfig.password()}"')
        print(f'  - bssid: {smartconfig.bssid()}')
        print(f'  - type: {smartconfig.type()} ({TYPES[smartconfig.type()]})')

        if smartconfig.v2_data():
            print(f'  - v2_data: "{smartconfig.v2_data()}"') # EspTouch V2 custom data
    else:
        # maybe wrong password or other situations
        print('but failed connect to ap')

    smartconfig.stop()


if __name__ == '__main__':
    run_test()

Update: Tested v5.1.2 and v5.2.2 in addition to esp-idf v5.0.4, compiled the firmware using the latest MicroPython code.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied