48 lines
1.1 KiB
Markdown
48 lines
1.1 KiB
Markdown
# Network component for ESP-IDF
|
|
|
|
because copying it over and over was a pain
|
|
|
|
## TODO
|
|
- needs timezone var for sntp
|
|
- still doesnt work with hidden ssids, need2fix
|
|
|
|
### How use
|
|
|
|
quite simply
|
|
|
|
```c++
|
|
#include <network/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");
|
|
}
|
|
```
|
|
|
|
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.
|