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

Conversation

Walkline80
Copy link

@Walkline80 Walkline80 commented Feb 13, 2024

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.

@Walkline80
Copy link
Author

You can go with MicroMsg or EspTouch App for smartconfig tests.

@Walkline80
Copy link
Author

In the present, because of 2.4G-5G mixed WiFi and WiFi6 routers, AirKiss protocol is no longer easy to use, even unusable, and using EspTouch and EspTouch V2 protocol requires additional installation of app, I'm afraid that many people don't like to use smartconfig now, but I think there should still be such a function, and it only takes up about 40K of firmware space :)

@Walkline80 Walkline80 force-pushed the smartconfig branch 2 times, most recently from 817af5c to 47fd1a1 Compare February 13, 2024 17:10
@Walkline80 Walkline80 changed the title Add smartconfig module to esp32 port esp32/modsmartconfig: Add smartconfig module. Feb 14, 2024
@Walkline80 Walkline80 force-pushed the smartconfig branch 3 times, most recently from a698696 to de7eb99 Compare February 16, 2024 14:36
@Walkline80
Copy link
Author

Rebase all commits to single one, and append document for smartconfig.

@Walkline80
Copy link
Author

Hi @projectgus, I didn't keep working on #4404 , because the ESP32 port requires ESP-IDF v5, which is a lot different than before, so I chose to start over.

@Walkline80
Copy link
Author

According to PR #13763 removed all STATIC macro in source files.

@mattytrentini
Copy link
Contributor

mattytrentini commented Jul 22, 2024

It looks like a nice feature, though I hadn't come across it before. I presume you've tested it? :)

I would guess that the maintainers would prefer this to be an optional component (even if it default to on by default).

To save folks from looking at the docs you've created (which are good, nice job!), they can read about this feature by looking at the Espressif SmartConfig documentation.

@Walkline80
Copy link
Author

@mattytrentini thanks for your review.

I would guess that the maintainers would prefer this to be an optional component (even if it default to on by default).

About the optional component, here is my thoughts:

  1. Keep the modification of ports/esp32/esp32_common.cmake

  2. Add a macro definition to (every) ports/esp32/boards/XXX/mpconfigboard.h, looks like:

    #define MICROPY_ENABLE_SMARTCONFIG (1)
  3. Finally, surround a preprocessor command to the whole modsmartconfig.c file, looks like:

    #if MICROPY_ENABLE_SMARTCONFIG
    ...
    ...
    #endif // MICROPY_ENABLE_SMARTCONFIG

I have tried these steps, #define MICROPY_ENABLE_SMARTCONFIG (1) and #define MICROPY_ENABLE_SMARTCONFIG (0) can make this component optionally appear or disappear. Please let me know if I'm correct, thanks~

they can read about this feature by looking at the Espressif SmartConfig documentation.

I see what you mean, aligning the function names in the component to the function names in the idf documentation.

But I can't fully agree with you, even if you do align the function names, there're still some differences between them, for example, the IDF API doesn't directly return the information, such as ssid and password, as well as the status of the smartconfig process, so you still have to refer to the component's documentation.

@beyonlo
Copy link

beyonlo commented Jul 26, 2024

This is a amazing PR, thank you guys!

@Walkline80
Copy link
Author

The following changes were made in this update:

  • Added version(), timeout(), fast_mode() and v2_key() functions.
  • Renamed function rvd_data() to v2_data().
  • Change the return value type of v2_data() to str.
  • Make module optional (already selected by default)

@PIBSAS
Copy link

PIBSAS commented Sep 17, 2024

Hope this will add to normal Micropython too!

@Walkline80
Copy link
Author

@PIBSAS thanks for your reply.

@Walkline80 Walkline80 force-pushed the smartconfig branch 2 times, most recently from 19ac0f6 to e835926 Compare September 23, 2024 12:15
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (e5eeaa7) to head (06a72b3).
Report is 12 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13658   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21336    21336           
=======================================
  Hits        21031    21031           
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Walkline80
Copy link
Author

I have no idea why there are 4 more files in the file changed list and the number of checks has increased to 67 and one of them fails....

Signed-off-by: Walkline Wang <walkline@gmail.com>
Signed-off-by: Walkine Wang <walkline@gmail.com>
* Added version(), timeout(), fast_mode() and v2_key() functions.

* Renamed function rvd_data() to v2_data().

* Change the return value type of v2_data() to str.

Signed-off-by: Walkine Wang <walkline@gmail.com>
Change data length from 32 to 64, to fit the maximum length specified
by the EspTouch app.

Signed-off-by: Walkline80 <walkline@gmail.com>
Signed-off-by: Walkline Wang <walkline@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants