Creating a mesh network without a router connected

Carboxyl
Posts: 1
Joined: Mon Jan 29, 2024 6:11 am

Creating a mesh network without a router connected

Postby Carboxyl » Mon Jan 29, 2024 6:18 am

Hey!

I'm new to IDF and am transitioning over from the Arduino IDE. This is my first larger project here.


I'm trying to create a routerless mesh network where every sensor on the network will dump all messages published on the network to serial, where a python program will pick them up and parse them. Right now, I'm getting a few problems with this snipping in just initializing the mesh configuration.

Code: Select all

void initialize_mesh_network(){
    // Initialize ESP-IDF components
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    Serial.println("Event loop started");
    
    // Wi-Fi configuration
    wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&wifi_cfg));
    ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
    ESP_ERROR_CHECK(esp_wifi_start());
    Serial.println("WiFi initialized");
    
    // Mesh network configuration
    mesh_cfg_t mesh_cfg = MESH_INIT_CONFIG_DEFAULT();
    mesh_cfg.channel = 1;
    memcpy((uint8_t *)&mesh_cfg.mesh_id, "BungleNet", strlen("BungleNet"));
    mesh_cfg.mesh_ap.max_connection = 8;  // Example max connections
    memcpy((uint8_t *)&mesh_cfg.mesh_ap.password, "bungus", strlen("bungus"));  

    // // Explicitly indicate no router connection for a routerless setup
    // mesh_cfg.router.ssid_len = 0;
    // memset(mesh_cfg.router.ssid, 0, sizeof(mesh_cfg.router.ssid));
    // memset(mesh_cfg.router.bssid, 0, sizeof(mesh_cfg.router.bssid));

    ESP_ERROR_CHECK(esp_mesh_init());

    ESP_ERROR_CHECK(esp_mesh_set_config(&mesh_cfg));

    Serial.println("Mesh network configured");
    ESP_ERROR_CHECK(esp_mesh_set_max_layer(25));
    
    ESP_ERROR_CHECK(esp_mesh_start());
}

from this, I get problems actually initializing the network, or if I swap the lines

Code: Select all


    ESP_ERROR_CHECK(esp_mesh_init());

    ESP_ERROR_CHECK(esp_mesh_set_config(&mesh_cfg));
I then get that the router configuration was not set correctly. Should I be using esp_mesh_set_self_organized? I was looking at this post

https://esp32.com/viewtopic.php?t=15022

And not getting very far. I'd genuinely appreciate a lecture or two on how this is done :)


Thanks!

rsimpsonbusa
Posts: 131
Joined: Tue May 17, 2016 8:12 pm

Re: Creating a mesh network without a router connected

Postby rsimpsonbusa » Mon Jan 29, 2024 6:45 pm

I presume you do not want or have a WiFi available but still need a mesh. I had a similar requirement, for example if you are going to use LORA instead of WiFi, or just collect data an store it. Anyways, what I ended up doing is using another ESP32 in STA mode so that it will provide the REQUIRED WiFi access for the Mesh. You can not have a Mesh without WiFi, its been extensively documented.

Use this ESP32 “wifi” node to be your logger, network access for LORA or whatever. They are cheap and in the future, if you finally get access to “real” wifi just connect to this network. It would be a good idea to name the ESP32 STA ssid to something that in the future will be a real SSDI WiFi.

A point to consider is that with the virtual WiFi you cannot have access to MQTT, HTTP etc, just internal messages.

Hope it helps.

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 241 guests