Skip to content

Commit

Permalink
Fix static ethernet config
Browse files Browse the repository at this point in the history
With static ethernet config, `status` stayed `0` which let the function return
without setting `ethEvent`. Therefore, `reconnectETH` was never called and network services were never started.

Also, the RAK4631 uses little endian, which is why the IP addresses need to be
converted before setting them.

Fixes meshtastic#2543
  • Loading branch information
micheljung committed Jun 6, 2023
1 parent 5edc872 commit bf5d6de
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/mesh/eth/ethClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ static int32_t reconnectETH()
return 5000; // every 5 seconds
}

static uint32_t bigToLittleEndian(uint32_t value) {
return ((value >> 24) & 0xFF)
| ((value >> 8) & 0xFF00)
| ((value << 8) & 0xFF0000)
| ((value << 24) & 0xFF000000);
}

// Startup Ethernet
bool initEthernet()
{
Expand Down Expand Up @@ -126,7 +133,15 @@ bool initEthernet()
status = Ethernet.begin(mac);
} else if (config.network.address_mode == meshtastic_Config_NetworkConfig_AddressMode_STATIC) {
LOG_INFO("starting Ethernet Static\n");
Ethernet.begin(mac, config.network.ipv4_config.ip, config.network.ipv4_config.dns, config.network.ipv4_config.subnet);

IPAddress ip = IPAddress(bigToLittleEndian(config.network.ipv4_config.ip));
IPAddress dns = IPAddress(bigToLittleEndian(config.network.ipv4_config.dns));
IPAddress gateway = IPAddress(bigToLittleEndian(config.network.ipv4_config.gateway));
IPAddress subnet = IPAddress(bigToLittleEndian(config.network.ipv4_config.subnet));

Ethernet.begin(mac, ip, dns, gateway, subnet);

status = 1;
} else {
LOG_INFO("Ethernet Disabled\n");
return false;
Expand Down

0 comments on commit bf5d6de

Please sign in to comment.