-->
Page 1 of 1

Change device's ip or hostname from http request or API

PostPosted: Sun Jan 29, 2023 7:50 pm
by rimula-x
I want to write a program to change hostname or IP address by getting value from http request or API
For example, http://<ip>/?hostname=abc123
Then device will change its hostname to abc123 and display abc123 in serial.
My problem is I code like this ....
---------------
if( server.hasArg("hostname") ){
String newHostname = server.arg("hostname").c_str();
WiFi.hostname(newHostname.c_str());
server.send(200, "text/plain", "Hostname changed to: " + String(WiFi.hostname()));
---------------
The result is .... the new hostname value can show on web page, but the real hostname still not changed.
( I can't ping it.)

I have no idea what going on or How to fix it.
BTW, I can create web server and receive fixed values such as on/off.