Juerd / ESP-WiFiSettings

WiFi Manager for the ESP32 Arduino environment
Other
168 stars 35 forks source link

Fix hostname generation + integer comparison compiler warning #4

Closed Pwuts closed 4 years ago

Pwuts commented 4 years ago

ESP32 hostname generation

~~Problem: currently, the hostname (if not set in the main sketch) is generated for the ESP32 from ESP.getEfuseMac() >> 24, which removes the last 24 bits of the MAC address, leaving the first 24 bits: the OUI (Organizationally Unique Identifier). This is the same for devices from the same manufacturer. The unique part of the MAC address is the 24 bits that are currently discarded.~~

Solution: ESP.getEfuseMac() & 0xFFFFFF gives the last 24 bits. Edit: this problem is not the problem I thought it was: ESP.getEfuseMac() returns the MAC address, but in reverse byte order. ESP.getEfuseMac() >> 24 does return the device-related part of the MAC address, but in reverse byte order.

ESP8266 hostname generation

Problem: the hostname for the ESP8266 is generated using ESP.getChipId() >> 8, but since the chip ID of the ESP8266 is the last 24 bits of its MAC address, this only leaves 16 bits (AKA the first two symbols of the ID part of the hostname is aways 00).

Solution: remove >> 8 truncation.

compiler warning

Problem: the compiler warned about a signed vs unsigned integer comparison. In the for-loop on line 50 of WiFiSettings.cpp, int i is used as an iterator but the limiter is raw.length() which has type size_t.

Solution: for (size_t i = 0; i < raw.length(); i++)

version

I think fixing these bugs justifies a v3.1.0 release, so I updated the version in the library manifests.

Juerd commented 4 years ago

I don't know about the 8266, but at least the ESP32 does seem to be correct: it uses the unique part of the MAC, not the vendor part. It does, as documented, have the bytes in reversed order:

By default, this is set to "esp32-123456" or "esp8266-123456" where 123456 is the hexadecimal representation of the device interface specific part of the ESP's MAC address, in reverse byte order.

For example, the full MAC for the device used for the screenshots at https://github.com/Juerd/ESP-WiFiSettings/tree/master/screenshots with the hostname esp32-202f58 is D8:A0:1D:58:2F:20, where D8:A0:1D is the vendor part and thus discarded.