57 lines
1.4 KiB
Markdown
57 lines
1.4 KiB
Markdown
# Network component for ESP-IDF
|
|
|
|
Generic network component for esp-idf v6.0, because copying it over and over was a pain
|
|
|
|
## TODO
|
|
- still doesnt work with hidden ssids, need2fix
|
|
|
|
### How use
|
|
|
|
quite simply add it to ur `idf-component.yml`
|
|
|
|
```yaml
|
|
esp-network:
|
|
git: git@git.drath.cc:drath/esp-network.git
|
|
```
|
|
|
|
and then in C
|
|
|
|
|
|
```c++
|
|
#include <network.h>
|
|
#include <esp_event.h>
|
|
|
|
static const wifi_networks_t known_networks = {
|
|
.nets = {
|
|
{"DAA+", "password"},
|
|
{"DAA", "password"},
|
|
},
|
|
.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.
|
|
|
|
```c++
|
|
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
|
|
```c++
|
|
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>`
|