uno r4 wifi: can't change wifi hostname, stays at esp32s3-…
Did you see this page?
https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples/
Edit:
char hostname[] = "my-uno-r4-wifi";
void setup() {
Serial.begin(9600);
// ...
WiFi.hostName(hostname);
// ...
}
Yes I did. It does not work.
Did you try this?
WiFi.setHostname(“myhost”);
Yes, it still shows up as: “esp32s3-3FE178”
Can you post your code?
You are calling the setHostname function before the wifi init function, correct?
For whatever reason, WiFi.setHostname on R4 returns void (on ESP32 it returns bool)
Looking at the other functions, modem.write returns bool. It's pretty easy to call this directly
#include <WiFi.h>
#include "arduino_secrets.h"
extern ModemClass modem;
bool didItWork;
void mySetHostname(const char *name) {
std::string res = "";
didItWork = modem.write(std::string(_HOSTNAME), res, "%s%s\r\n" , CMD_WRITE(_HOSTNAME), name);
}
void setup() {
Serial.begin(115200);
mySetHostname("tryInSetup");
WiFi.begin(SECRET_SSID, SECRET_PASS); // blocking until connection on R4
Serial.println(didItWork ? "ok" : "it didn't work");
}
void loop() {}
Looking further at that library code, a lot of the other functions have something that is missing from setHostname. So try adding it
Serial.begin(115200);
modem.begin(); // <-- this
mySetHostname("tryInSetup");
WiFi.begin(SECRET_SSID, SECRET_PASS);
If that works like it did for me, you can revert to WiFi.setHostname
So from what I see, the setHostname() function is calling modem.write() before a modem.begin() function call. Seems to me the modem.begin() call should be the first line in the setHostname() function in the library.
Just a thought…
Right. Until it is fixed in the library, you can call it manually in your sketch. Also no problem if it is called more than once.
I have tried it everywhere and there doesn’t appear to be an init function.
Prove it.
modem.begin() compiles ok here on on IDE v2.3.6. When you say “it doesn’t work”, how? Doesn’t compile? Doesn’t run? Doesn’t change the hostname?
kenb4 showed you the code a couple posts above until the library code is modified.
Trying those solutions now.
The host name reported on the modem is still esp32s3-3FE178
How are you showing the current hostname? I was testing with my Xfinity app, and it took a little while for it to "forget" the old config by itself. Forcing it forget might help.
Please provide a detailed answer as to how you know the hostname is not changing.
Provide sufficient detail so that someone else could replicate your test and verify your results.
I power off and on the modem/router between attempts
I have tried setting the Hostname many places as follows:
<CODE/>
std::string res = "";
modem.begin();
modem.write(std::string(_HOSTNAME), res, "%s%s\r\n" , CMD_WRITE(_HOSTNAME), DeviceName);
WiFi.setHostname(DeviceName);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed!");
// don't continue WIFI
}
else
{
//WiFi.disconnect();
modem.begin();
modem.write(std::string(_HOSTNAME), res, "%s%s\r\n" , CMD_WRITE(_HOSTNAME), DeviceName);
WIFI_Used = 1;
WiFi.setHostname(DeviceName);
String fv = WiFi.firmwareVersion();
Serial.println("Firmware "+fv);
if (fv < WIFI_FIRMWARE_LATEST_VERSION)
{
Serial.println("Please upgrade the firmware "+fv+ " to "+WIFI_FIRMWARE_LATEST_VERSION);
}
/*
To set a hostname, use WiFi.setHostname("my-arduino");
before connecting to the network, and then access it
via the network's DNS (like my-arduino.local)
*/
// attempt to connect to WiFi network:
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.setHostname(DeviceName);
// WiFi.mode(WIFI_STA);
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
WiFi.setHostname(DeviceName);
}
server.begin();
<CODE/>
The significance of that is not clear to me. What has that got to do with your problem?
Show the process you go through to arrive at the conclusion that the hostname is not changing in sufficient detail that someone else could do the same thing and observe the result.
Please do not assume that everyone knows what your setup is. We don't, unless you tell us and so far you have not.
The modem/router is where it shows the host name after it connects
it appears that you really do not want help. Did you not read the second paragraph?
Since it has not been possible to get you to provide complete and detailed information, I'll just leave this on my way out. It's a tried and tested method of setting the mDNS hostname (as alluded to in one of your "here's some code" replies - which as far as I can tell, you never actually do, but nevermind) on the Uno R4 WiFi with the ArduinoMDNS library.
Good-bye and good luck.
Sketch:
#include <WiFi.h>
#include <MDNS.h>
// Replace with your network credentials
#include <Arduino_Secrets.h>
// Change the hostname
const char* hostname = "r4wifi";
WiFiUDP udp;
MDNS mdns(udp);
void initWiFi() {
WiFi.begin(SECRET_SSID, SECRET_PASS);
Serial.print("Connecting to WiFi...");
while( WiFi.status() != WL_CONNECTED ) {
Serial.print('.');
delay(1000);
}
mdns.begin(WiFi.localIP(), hostname);
Serial.print("\nIP Address: ");
Serial.println(WiFi.localIP());
Serial.print("RRSI: ");
Serial.println(WiFi.RSSI());
}
void setup() {
Serial.begin(115200);
initWiFi();
}
void loop() {
mdns.run();
}
Ping results of mDNS name set in sketch showing that the mDNS hostname has been set:
me@alinuxbox:~ $ ping r4wifi.local
PING r4wifi.local (192.168.1.58) 56(84) bytes of data.
64 bytes from unor4fifi.my.network (192.168.1.58): icmp_seq=1 ttl=255 time=8.54 ms
64 bytes from unor4fifi.my.network (192.168.1.58): icmp_seq=2 ttl=255 time=80.6 ms
64 bytes from unor4fifi.my.network (192.168.1.58): icmp_seq=3 ttl=255 time=98.7 ms
^C
--- r4wifi.local ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 8.543/62.629/98.739/38.954 ms
MDNS.h not available