3

I'm building a mesh with ESP32 dev kits (ESP32-DevKitC V4) using the ESP-IDF VS Code extension and the ip_internal_network example project. The code for the example, common project components, and the API is linked. When the mesh nodes power on and build the network, they use the 10.0.0.0 network. How do I change the internal mesh network?

My operating assumptions:

  • The root node receives an external IP address from an external DHCP server.
  • The root node acts as an internal DHCP server to the mesh nodes.
  • The root node performs network address translation.
  • Its DHCPv4 server runs on the lwIP TCP/IP stack.
  • Internal IP addresses are leased from a pool governed by the root node (but it's possible that nodes request a particular address from this network and the server provides the next available; I'm unsure).
  • The network address is 10.0.0.0/8 (I inferred the subnet mask; it could be anything).

Obviously, the first thing I tried was searching for this network address in files. There was nothing in the project workspace and too many hits in the repo to be useful. I tried decimal and hex with no luck.

I also tried tracing the function that prints the IP address to the serial terminal to find the IP var, and working backwards to locate the statement that initializes this variable. I'm still reading event handler API documentation so I haven't made quick progress here either.

The programming interface is split among ESP-IDF component header files, build systems (CMake and Ninja?), KConfig options and host tools (idf.py?). C, FreeRTOS and build systems are all new to me so I would appreciate if someone with more experience could weigh in. Thank you.

0

1 Answer 1

2

I figured it out; it's in mesh_netif.c:43. I'm not sure why I passed over this file initially but it caused a lot of unnecessary headache. The relevant struct is this:

const esp_netif_ip_info_t g_mesh_netif_subnet_ip = {
    .ip = { .addr = ESP_IP4TOADDR( 192, 168, 0, 1) },
    .gw = { .addr = ESP_IP4TOADDR( 192, 168, 0, 1) },
    .netmask = { .addr = ESP_IP4TOADDR( 255, 255, 255, 0) },
};

I changed the 10.0.0.0/16 network to 192.168.0.0/24. The root node assumes the address in .ip. I assume child nodes check the ARP table and increment until an address is available, then send the DHCPREQUEST for that address to root. I say "assume" because although root runs lwIP, I am not sure child nodes run lwIP (they may just communicate in layer 2 ESP-WIFI-MESH frames).

Make sure your DHCP server publishes an IPv4 DNS address or ESP_ERROR_CHECK(esp_netif_set_dns_info(netif, ESP_NETIF_DNS_MAIN, &dns)) (mesh_netif.c:70) will fail and cause the board to power cycle. A way around this is to enable Use global DNS IP in menuconfig. The global DNS field is in hex format, so 10.32.64.128 is written 0x0A204080.

Mesh-internal IP messages are published with MQTT so the name/address .broker.address.uri in mqtt_app.c:74 must be accessible from the router.

Not the answer you're looking for? Browse other questions tagged or ask your own question.