Without this fix, this was causing the web interface to not take updates — by the time the HeatPump library tried to read the various argument strings they were reset.
Fix
I'm not sure that this is a good fix, but it does work: keeping the returned String in scope until after the setSettings call ensures that the underlying char * buffers aren't cleared.
Maybe a better fix would be to update the settings interface to support a String optionally somehow?
Problem
the
String
returned by theserver::arg
methods (likeserver::arg("POWER")
) drops out of scope right after itsc_str()
method is called.I'm using a ESP32. That implementation (https://github.com/espressif/arduino-esp32/blob/2.0.14/libraries/WebServer/src/WebServer.cpp#L549) returns a
String
by value, so once theString
returned byarg()
is out of scope, the underlyingc_str()
pointer becomes invalid.Without this fix, this was causing the web interface to not take updates — by the time the HeatPump library tried to read the various argument strings they were reset.
Fix
I'm not sure that this is a good fix, but it does work: keeping the returned
String
in scope until after thesetSettings
call ensures that the underlyingchar *
buffers aren't cleared.Maybe a better fix would be to update the settings interface to support a String optionally somehow?