Skip to content

Instantly share code, notes, and snippets.

@shimarin
Last active May 2, 2019 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shimarin/9fc3b51edddadcb607ee587c2cd40e28 to your computer and use it in GitHub Desktop.
Save shimarin/9fc3b51edddadcb607ee587c2cd40e28 to your computer and use it in GitHub Desktop.
wifi eth bridge idea
#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