Esptouch V2 implementation

Hello,

I would like to use esptouch v2 protocol on esp8266 but i couldnt find any documents or examples about it. I have found one example for esp32 but could you tell me how can i convert this code so it will work on esp8266.

#include "WiFi.h"

void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
{
    Serial.printf("[WiFi-event] event: %d\n", event);

    switch (event) {

        case ARDUINO_EVENT_SC_SCAN_DONE:
        {
            Serial.println("Scan done");
        }
        break;

        case ARDUINO_EVENT_SC_FOUND_CHANNEL:
        {
            Serial.println("Found channel");

        }
        break;

        case ARDUINO_EVENT_SC_GOT_SSID_PSWD:
        {
            Serial.println("Got SSID and password");

            uint8_t ssid[33] = { 0 };
            uint8_t password[65] = { 0 };

            uint8_t rvd_data[33] = { 0 };

            memcpy(ssid, info.sc_got_ssid_pswd.ssid, sizeof(info.sc_got_ssid_pswd.ssid));
            memcpy(password, info.sc_got_ssid_pswd.password, sizeof(info.sc_got_ssid_pswd.password));

            Serial.printf("SSID:%s\n", ssid);
            Serial.printf("PASSWORD:%s\n", password);

            if (info.sc_got_ssid_pswd.type == SC_TYPE_ESPTOUCH_V2) {
                ESP_ERROR_CHECK( esp_smartconfig_get_rvd_data(rvd_data, sizeof(rvd_data)) );

                Serial.println("RVD_DATA");
                Serial.write(rvd_data, 33);
                Serial.printf("\n");

                for (int i = 0; i < 33; i++) {
                    Serial.printf("%02x ", rvd_data[i]);
                }
                Serial.printf("\n");
            }
        }
        break;

        case ARDUINO_EVENT_SC_SEND_ACK_DONE:
        {
            Serial.println("SC_EVENT_SEND_ACK_DONE");
        }
        break;

        default:
        {
            Serial.printf("no case event: %d\n", event);
        }
        break;
    }
}

void setup() {
    Serial.begin(115200);

    Serial.println("ESP32 START");

    WiFi.mode(WIFI_AP_STA);
    WiFi.onEvent(WiFiEvent);
    WiFi.beginSmartConfig(SC_TYPE_ESPTOUCH_V2, "1234567890123456");

    Serial.println("SmartConfig...");

}

void loop() {
    // put your main code here, to run repeatedly:

}
2 Likes

Working on testing this myself, but the first thing I can offer is to import #include <ESP8266WiFi.h> instead of #include "WiFi.h".

More soon - but ultimately what I am learning today, it seems, is that the ESP8266WiFi doesn't implement v2 of ESPTouch protocol, and if we want this to work in this way we will need to tweak the library ourselves.

Specifically what in the ESP32 code is:

WiFi.beginSmartConfig( SC_TYPE_ESPTOUCH_V2, "1234567890123456" );

doesn't take parameters in the ESP8266 library, exposing that it has no ability to understand and encrypt/decrypt the pre-shared key. You/we would need to add the parameters and more importantly the encryption/decryption methods.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.