aZholtikov / zh_network

ESP32 ESP-IDF and ESP8266 RTOS SDK component (arduino library for ESP32 family) for ESP-NOW based mesh network.
Apache License 2.0
44 stars 6 forks source link

how to get routing table ? #1

Closed sloev closed 9 months ago

sloev commented 9 months ago

hi, i am trying to create a tool to survey the changing routing tables to have an overview over time of the routing tables seen from each nodes perspective.

is it possible to get the routing table from the example in esp32?

really nice library!!! gonna use it here: https://github.com/ingenrod/mesh

aZholtikov commented 9 months ago

Hi!

In only the branch "esp32" added experimental function zh_network_get_route(). Not fully tested. I would appreciate for the test and feedback.

In your program add task (for example):

void zh_network_get_routing(void *pvParameter)
{
    typedef struct zh_network_routing_table_t
    {
        uint8_t original_target_mac[6];
        uint8_t intermediate_target_mac[6];
    } __attribute__((packed)) zh_network_routing_table_t;
    zh_vector_t *route_vector = zh_network_get_route();
    vTaskDelay(60000 / portTICK_PERIOD_MS); // Just wait a little while for the routing table to fill up.
    for (uint16_t i = 0; i < zh_vector_get_size(route_vector); ++i)
    {
        zh_network_routing_table_t *routing_table = zh_vector_get_item(route_vector, i);
        printf("Target MAC %02X:%02X:%02X:%02X:%02X:%02X route MAC %02X:%02X:%02X:%02X:%02X:%02X.\n", MAC2STR(routing_table->original_target_mac), MAC2STR(routing_table->intermediate_target_mac));
    }
    vTaskDelete(NULL);
}

And start it:

xTaskCreatePinnedToCore(&zh_network_get_routing, "zh_network_get_routing", 2048, NULL, 3, NULL, tskNO_AFFINITY);
aZholtikov commented 9 months ago

The function has been fully tested. It will be added to other branches soon. And will not be added to the example because its incorrect use may cause errors. Who needs it - will find it himself.