You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to set the configuration URL on startup dynamically, however the only working code I've managed to get to compile results in a bytes object instead of a string, which breaks the HA integration.
Can someone add an example on how to achieve this?
// Setup vars
String localIP;
constchar* url;
...
// In Setup// Set device as a Wi-Fi Station
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to Wi-Fi..");
}
localIP = WiFi.localIP().toString();
Serial.print("Sensor IP Address: ");
Serial.println(localIP);
Serial.println();
url = String(String("http://") + localIP).c_str();
device.setConfigurationUrl(String(url).c_str());
This results in the following in the MQTT messages:
{"cu":"���?"}
Unfortunately I've not found a way to combine an IPAddress variable with a const like "http://" without all the String().c_str() conversions, and from the Serial.println I can verify the IP is properly set in the string...
The text was updated successfully, but these errors were encountered:
Please note that in your code char url[20] maybe short....
http:// = 7 chars
xxx.xxx.xxx.xxx = 15 chars
so the worst condition cu can be 22 chars + \0 so 23 chars
I've been trying to set the configuration URL on startup dynamically, however the only working code I've managed to get to compile results in a bytes object instead of a string, which breaks the HA integration.
Can someone add an example on how to achieve this?
This results in the following in the MQTT messages:
Unfortunately I've not found a way to combine an
IPAddress
variable with a const like"http://"
without all theString().c_str()
conversions, and from theSerial.println
I can verify the IP is properly set in the string...The text was updated successfully, but these errors were encountered: