How to set WiFi DHCP hostname on ESP32/ESP8266 (different from “espressif”)

Use

WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname("My-ESP32-Test");

to set a custom hostname for the ESP32. TheĀ Wifi.config(...) line is required as a workaround for this bug on Github.