Skip to content

smart config support #124

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

Closed
seopyoon opened this issue Jan 12, 2017 · 4 comments
Closed

smart config support #124

seopyoon opened this issue Jan 12, 2017 · 4 comments

Comments

@seopyoon
Copy link
Contributor

So far, the arduino sdk is not supporting the SmartConfig function it seems.
When are you planning on adding WiFi.beginSmartConfig()?

Is there a way to use smart config functionality at the very moment?

@seopyoon
Copy link
Contributor Author

seopyoon commented Jan 13, 2017

I made modifications to WiFiSTA.cpp and .h to support ESP's smart config functionality. But it does not seem to work.

To WiFiSTA.cpp, I added:


bool WiFiSTAClass::_smartConfigStarted = false;
bool WiFiSTAClass::_smartConfigDone = false;


bool WiFiSTAClass::beginSmartConfig() {
    if (_smartConfigStarted) {
        return false;
    }

    if (!WiFi.enableSTA(true)) {
        return false;
    }


    esp_err_t err;
    err = esp_smartconfig_start(reinterpret_cast<sc_callback_t>(&WiFiSTAClass::_smartConfigCallback), 1);
    if (err == ESP_OK) {
        _smartConfigStarted = true;
        _smartConfigDone = false;
        return true;
    }
    return false;
}

bool WiFiSTAClass::stopSmartConfig() {
    if (!_smartConfigStarted) {
        return true;
    }

    if (esp_smartconfig_stop() == ESP_OK) {
        _smartConfigStarted = false;
        return true;
    }

    return false;
}

bool WiFiSTAClass::smartConfigDone() {
    if (!_smartConfigStarted) {
        return false;
    }

    return _smartConfigDone;
}

void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
    smartconfig_status_t status = (smartconfig_status_t) st;
    if (status == SC_STATUS_LINK) {
        wifi_sta_config_t *sta_conf = reinterpret_cast<wifi_sta_config_t *>(result);

        esp_wifi_set_config(WIFI_IF_AP, (wifi_config_t *)sta_conf);
        esp_wifi_disconnect();
        esp_wifi_connect();
    } else if (status == SC_STATUS_LINK_OVER) {
        WiFi.stopSmartConfig();
    }
}

and, to WiFiSta.h, I added:

public:
    bool beginSmartConfig();
    bool stopSmartConfig();
    bool smartConfigDone();

protected:
    static bool _smartConfigStarted;
    static bool _smartConfigDone;
    static void _smartConfigCallback(uint32_t status, void* result);

It does not crash or anything, but when trying to use ESP Smart Config using the app on PlayStore, it gives me Esptouch fail error, after several seconds of trying. I believe the modifications to the Arduino classes are done correctly, but somehow the functionality is not working well.

@seopyoon seopyoon reopened this Jan 13, 2017
@seopyoon
Copy link
Contributor Author

I accidentally closed the issue. So I reopened it.

@me-no-dev
Copy link
Member

Why not submit a PR? :) we can merge those things and have your name there

@seopyoon
Copy link
Contributor Author

@me-no-dev done!

brentru added a commit to adafruit/arduino-esp32 that referenced this issue Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants