Files
esp-network/README.md
2026-06-19 00:44:14 +02:00

1.3 KiB

Network component for ESP-IDF

Generic network component for esp-idf v6.0, because copying it over and over was a pain

How use

quite simply add it to ur idf-component.yml

  esp-network:
    git: git@git.drath.cc:drath/esp-network.git

and then in C

#include <network.h>
#include <esp_event.h>

static const wifi_networks_t known_networks = {
    .nets = {
        {"DAA+", "password", true},
        {"DAA", "password", false},
    },
    .num_nets = 2
};

void app_main(void) {
    esp_event_loop_create_default();
    init_wifi(&known_networks, "piec_monitor");
    // or
    init_ethernet("pmbus_monitor");
    // NEVER BOTH
} 

V important to call esp_event_loop_create_default();, then you can just use callbacks from related modules when IP get, ie.

void on_get_ip(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
    const ip_event_got_ip_t* event = (ip_event_got_ip_t*)event_data;
    ESP_LOGI(TAG, "ip getto: " IPSTR, IP2STR(&event->ip_info.ip));
    /* do further shit */
}

just register the callback before with

esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &on_get_ip, nullptr);

Event loop is global so as long as you include <esp_event.h> you can write and register a callback to anything you need to. You might also need <esp_netif.h>