show binary file, generated by server
All checks were successful
Build and Push Multi-Arch Docker Image / build-and-push (push) Successful in 15m48s
All checks were successful
Build and Push Multi-Arch Docker Image / build-and-push (push) Successful in 15m48s
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "WPS_EXAMPLE";
|
||||
|
||||
// Funktion, um WPS zu starten (z.B. durch Button-Interrupt aufgerufen)
|
||||
// Function to start WPS (e.g., called by button interrupt)
|
||||
void start_wps_process()
|
||||
{
|
||||
ESP_LOGI(TAG, "Starting WPS...");
|
||||
@@ -14,8 +14,7 @@ void start_wps_process()
|
||||
// ESP_ERROR_CHECK(esp_wifi_wps_start(0)); // Start WPS indefinitely (handle timeout via event)
|
||||
}
|
||||
|
||||
static void wifi_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT)
|
||||
{
|
||||
@@ -23,51 +22,51 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base,
|
||||
{
|
||||
case WIFI_EVENT_STA_START:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_START: Wi-Fi station started.");
|
||||
// Option 1: Start WPS direkt hier
|
||||
// Option 1: Start WPS directly here
|
||||
// start_wps_process();
|
||||
// Option 2: Warten auf externen Trigger (z.B. Button), siehe start_wps_process()
|
||||
// Optional: Versuchen, sich normal zu verbinden, falls Zugangsdaten gespeichert sind
|
||||
// Option 2: Wait for external trigger (e.g., button), see start_wps_process()
|
||||
// Optional: Try to connect normally if credentials are stored
|
||||
// esp_wifi_connect();
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_CONNECTED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_CONNECTED");
|
||||
// Falls verbunden (z.B. aus Flash), WPS deaktivieren, falls es noch lief
|
||||
// If connected (e.g., from flash), disable WPS if it was still running
|
||||
// esp_wifi_wps_disable();
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
|
||||
// Eventuell normalen Verbindungsversuch starten oder auf WPS-Trigger warten
|
||||
// esp_wifi_connect(); // Oder: Warte auf Button für WPS
|
||||
// Possibly start normal connection attempt or wait for WPS trigger
|
||||
// esp_wifi_connect(); // Or: Wait for button for WPS
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_SUCCESS");
|
||||
// WPS erfolgreich, Zugangsdaten wurden empfangen.
|
||||
// Der Wi-Fi Stack versucht nun automatisch, sich zu verbinden.
|
||||
// WPS deaktivieren.
|
||||
// WPS successful, credentials were received.
|
||||
// The Wi-Fi stack now automatically tries to connect.
|
||||
// Disable WPS.
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
// Optional: Zugangsdaten auslesen und speichern, falls nötig (normalerweise nicht erforderlich, da der Stack sie intern nutzt)
|
||||
// Optional: Read and save credentials if needed (usually not required as the stack uses them internally)
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_FAILED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_FAILED");
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
// Hier Fehlerbehandlung: Info an User, evtl. erneuten Start ermöglichen
|
||||
// Here error handling: Info to user, possibly allow restart
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_TIMEOUT");
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
// Hier Fehlerbehandlung: Info an User, evtl. erneuten Start ermöglichen
|
||||
// Here error handling: Info to user, possibly allow restart
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_PIN:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_PIN");
|
||||
// Relevant für PIN-Modus
|
||||
// Relevant for PIN mode
|
||||
// wifi_event_sta_wps_er_pin_t* event = (wifi_event_sta_wps_er_pin_t*) event_data;
|
||||
// ESP_LOGI(TAG, "WPS PIN: %.*s", event->pin_code_len, event->pin_code); // Beispiel: ESP32 generiert PIN
|
||||
// ESP_LOGI(TAG, "WPS PIN: %.*s", event->pin_code_len, event->pin_code); // Example: ESP32 generates PIN
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -78,13 +77,13 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base,
|
||||
{
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
|
||||
ESP_LOGI(TAG, "Got IP address: " IPSTR, IP2STR(&event->ip_info.ip));
|
||||
// Verbindung erfolgreich hergestellt
|
||||
// Connection successfully established
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_sta_wps(void)
|
||||
{
|
||||
// 1. NVS initialisieren
|
||||
// 1. Initialize NVS
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
||||
{
|
||||
@@ -93,29 +92,29 @@ void wifi_init_sta_wps(void)
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
// 2. TCP/IP Stack initialisieren
|
||||
// 2. Initialize TCP/IP stack
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
// 3. Event Loop erstellen
|
||||
// 3. Create event loop
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
// 4. Default Wi-Fi Station Netif erstellen
|
||||
// 4. Create default Wi-Fi Station Netif
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
// 5. Wi-Fi Treiber initialisieren
|
||||
// 5. Initialize Wi-Fi driver
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
// 6. Event Handler registrieren
|
||||
// 6. Register event handler
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &wifi_event_handler, NULL));
|
||||
|
||||
// 7. Wi-Fi Modus auf Station setzen
|
||||
// 7. Set Wi-Fi mode to station
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
|
||||
// 8. Wi-Fi starten (löst WIFI_EVENT_STA_START aus)
|
||||
// 8. Start Wi-Fi (triggers WIFI_EVENT_STA_START)
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "Wi-Fi Initialisierung abgeschlossen.");
|
||||
ESP_LOGI(TAG, "Bereit für WPS Trigger (z.B. Button-Druck oder automatischen Start in STA_START).");
|
||||
ESP_LOGI(TAG, "Wi-Fi initialization completed.");
|
||||
ESP_LOGI(TAG, "Ready for WPS trigger (e.g., button press or automatic start in STA_START).");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user