Last active
May 2, 2019 00:50
-
-
Save shimarin/9fc3b51edddadcb607ee587c2cd40e28 to your computer and use it in GitHub Desktop.
wifi eth bridge idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <esp_private/wifi.h> | |
#include <netif/wlanif.h> | |
static esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void *eb) | |
{ | |
if (destination_mac_address_belongs_to_eth) { | |
esp_eth_tx(buffer, len); | |
esp_wifi_internal_free_rx_buffer(eb); | |
return ESP_OK; | |
} | |
// else | |
if (is_broadcast) { | |
esp_eth_tx(buffer, len); | |
} | |
wlanif_input(esp_netif[TCPIP_ADAPTER_IF_STA], buffer, len, eb); | |
return ESP_OK; | |
} | |
static esp_err_t event_handler(void *ctx, system_event_t *event) | |
{ | |
switch(event->event_id) { | |
case SYSTEM_EVENT_STA_START: | |
esp_wifi_connect(); | |
break; | |
case SYSTEM_EVENT_STA_CONNECTED: | |
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, (wifi_rxcb_t)tcpip_adapter_sta_input); | |
break; | |
case SYSTEM_EVENT_STA_DISCONNECTED: | |
attempt_to_reconnect(); | |
break; | |
default: | |
break; | |
} | |
return ESP_OK; | |
} | |
void app_main() | |
{ | |
tcpip_adapter_init(); | |
esp_event_loop_init(event_handler, NULL); | |
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); | |
esp_wifi_init(&cfg); | |
wifi_config_t wifi_config = { | |
.sta = { | |
.ssid = "MY_SSID", | |
.password = "MY_PASSWORD" | |
}, | |
}; | |
esp_wifi_set_mode(WIFI_MODE_STA); | |
esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config); | |
esp_wifi_start(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment