I'm trying to get the [ESP-WIFI-MESH](https://www.espressif.com/en/products/s ... h/overview) working. I'm using the guide on espressif.
The werid thing is my code compiles and works fine on other ESP32's like a TTGO-display board for instance.
On this M5 it compiles fine but when I set the mesh config, it give an argument error implying the struct is invalid
Code: Select all
#include <Arduino.h>
#include <esp_wifi.h>
#include <esp_mac.h>
#include <esp_event.h>
#include <esp_log.h>
#include <esp_mesh.h>
#include <esp_mesh_internal.h>
#include <nvs_flash.h>
#include <ArduinoJson.h>
#include <FastLED.h>
/*******************************************************
* Macros
*******************************************************/
/*******************************************************
* Constants
*******************************************************/
#define RX_SIZE (1500)
#define TX_SIZE (1460)
#define IS_ROOT false
#define MESH_ID {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC}
#define MESH_CHANNEL 2
#define MESH_MAX_LAYER 6
#define SENDLOOP_INTERVAL 1000
#define LED_PIN 27
#define NUM_LEDS 1
CRGB led[NUM_LEDS];
/*******************************************************
* Variable Definitions
*******************************************************/
static const char *TAG = "mesh_test";
static esp_netif_t *netif_sta = NULL;
bool is_mesh_connected = false;
mesh_addr_t mesh_parent_addr;
int mesh_layer = -1;
/*******************************************************
* Function Declarations
*******************************************************/
/*******************************************************
* Function Definitions
*******************************************************/
void setup_led()
{
FastLED.addLeds<NEOPIXEL, LED_PIN>(led, NUM_LEDS);
led[0] = CRGB::Black;
FastLED.show();
}
void blink_led(uint8_t r, uint8_t g, uint8_t b, int delay_ms = 200)
{
led[0] = CRGB(r, g, b);
FastLED.show();
delay(delay_ms);
led[0] = CRGB::Black;
FastLED.show();
delay(delay_ms);
}
void flash_led(uint8_t r, uint8_t g, uint8_t b,int delay_ms = 100)
{
int i = 0;
while (i < 3)
{
led[0] = CRGB(r, g, b);
FastLED.show();
delay(delay_ms);
led[0] = CRGB::Black;
FastLED.show();
delay(delay_ms);
i++;
}
}
void ip_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
ESP_LOGI(MESH_TAG, "<IP_EVENT_STA_GOT_IP>IP:" IPSTR, IP2STR(&event->ip_info.ip));
}
void mesh_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
switch (event_id)
{
case MESH_EVENT_STARTED:
{
ESP_LOGI(MESH_TAG, "<MESH_EVENT_MESH_STARTED>ID:" MACSTR "", MAC2STR(id.addr));
mesh_layer = esp_mesh_get_layer();
Serial.printf("Event: MESH_EVENT_STARTED, Layer %d\n", mesh_layer);
}
case MESH_EVENT_PARENT_CONNECTED:
ESP_LOGI(TAG, "MESH_EVENT_PARENT_CONNECTED");
mesh_layer = esp_mesh_get_layer();
esp_mesh_get_parent_bssid(&mesh_parent_addr);
ESP_LOGI(TAG, "Layer %d, Parent %02x:%02x:%02x:%02x:%02x:%02x",
mesh_layer,
mesh_parent_addr.addr[0], mesh_parent_addr.addr[1], mesh_parent_addr.addr[2],
mesh_parent_addr.addr[3], mesh_parent_addr.addr[4], mesh_parent_addr.addr[5]);
Serial.println("Parent connected");
Serial.printf("Layer %d, Parent %02x:%02x:%02x:%02x:%02x:%02x\n",
mesh_layer,
mesh_parent_addr.addr[0], mesh_parent_addr.addr[1], mesh_parent_addr.addr[2],
mesh_parent_addr.addr[3], mesh_parent_addr.addr[4], mesh_parent_addr.addr[5]);
break;
case MESH_EVENT_PARENT_DISCONNECTED:
ESP_LOGI(TAG, "MESH_EVENT_PARENT_DISCONNECTED");
mesh_layer = esp_mesh_get_layer();
Serial.printf("Layer %d, Parent disconnected\n", mesh_layer);
break;
case MESH_EVENT_CHILD_CONNECTED:
{
mesh_event_child_connected_t *child_connected = (mesh_event_child_connected_t *)event_data;
ESP_LOGI(TAG, "<MESH_EVENT_CHILD_CONNECTED>aid:%d, " MACSTR "",
child_connected->aid,
MAC2STR(child_connected->mac));
Serial.println("Child connected");
break;
}
default:
ESP_LOGI(TAG, "Unhandled event ID: %d", event_id);
Serial.println("Unhandled event ID");
Serial.println(event_id);
break;
}
}
void setup_mesh()
{
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
Serial.println("NVS flash erased and re-initialized.");
}
ESP_ERROR_CHECK(ret);
//ESP_ERROR_CHECK(nvs_flash_init());
/* tcpip initialization */
ESP_ERROR_CHECK(esp_netif_init());
/* event initialization */
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* create network interfaces for mesh (only station instance saved for further manipulation, soft AP instance ignored */
ESP_ERROR_CHECK(esp_netif_create_default_wifi_mesh_netifs(&netif_sta, NULL));
/* wifi initialization */
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
esp_err_t wifi_start_err = esp_wifi_start();
if (wifi_start_err == ESP_OK)
{
Serial.println("WiFi started successfully.");
}
else
{
Serial.printf("Failed to start WiFi: %s\n", esp_err_to_name(wifi_start_err));
}
/* mesh initialization */
Serial.println("Init mesh");
esp_err_t mesh_init_err = esp_mesh_init();
if (mesh_init_err == ESP_OK)
{
Serial.println("Mesh initialized successfully.");
}
else
{
Serial.printf("Failed to initialize mesh: %s\n", esp_err_to_name(mesh_init_err));
}
ESP_ERROR_CHECK(esp_event_handler_register(MESH_EVENT, ESP_EVENT_ANY_ID, &mesh_event_handler, NULL));
mesh_cfg_t mesh_config = MESH_INIT_CONFIG_DEFAULT();
uint8_t mesh_id[] = MESH_ID;
memcpy(&mesh_config.mesh_id, mesh_id, 6);
mesh_config.channel = MESH_CHANNEL;
mesh_config.router.ssid_len = 0; // No router connection
//mesh_config.mesh_ap.max_connection = 2;
if (IS_ROOT)
{
ESP_ERROR_CHECK(esp_mesh_set_self_organized(true, true));
ESP_ERROR_CHECK(esp_mesh_set_type(MESH_ROOT));
ESP_LOGI(TAG, "Node set as root.");
Serial.println("Node set as root.");
}
else {
ESP_ERROR_CHECK(esp_mesh_set_self_organized(true, true));
ESP_ERROR_CHECK(esp_mesh_set_type(MESH_IDLE));
Serial.println("Node set as leaf.");
}
esp_err_t set_config_err = esp_mesh_set_config(&mesh_config);
if (set_config_err == ESP_OK)
{
Serial.println("Mesh configuration set successfully.");
}
else
{
Serial.printf("Failed to set mesh configuration: %s\n", esp_err_to_name(set_config_err));
}
esp_err_t err = esp_mesh_start();
if (err == ESP_OK)
{
ESP_LOGI(TAG, "Mesh started successfully.");
Serial.println("Mesh started successfully.");
is_mesh_connected = true;
flash_led(0,0,255,100);
}
else
{
ESP_LOGE(TAG, "Failed to start mesh: %s", esp_err_to_name(err));
Serial.println("Failed to start mesh.");
is_mesh_connected = false;
flash_led(255,0,0,100);
}
}
It failes here:
Code: Select all
esp_err_t set_config_err = esp_mesh_set_config(&mesh_config);
Again, this just works on other ESP32s.
In essense the config struct contains only the mesh ID and the channel.
Any reason this fails on this architecture and not on others?