envy / esp-knx-ip

A KNX/IP library for the ESP8266 with Arduino
MIT License
136 stars 49 forks source link

Update a config_string .. #6

Closed mrWheel closed 6 years ago

mrWheel commented 6 years ago

Hi Nico,

Is there a way to update a registered config_string?

I have added a wifiManager to my sketch so I can configure a WiFi AP if the device cannot connect to the last known AP. So I have registered a SSID and Password string. During startup I read the values after knx.load():

  _SIDID_id = knx.register_config_string("sSID_ID", 50, WiFi.SSID());
  _SIDPW_id = knx.register_config_string("sSID_PW", 50, WiFi.psk());
  param_id = knx.register_config_int("My Parameter", default_val);

  Serial.print("_SIDID_id ["); Serial.print(_SIDID_id); Serial.println("]");
  Serial.print("_SIDPW_id ["); Serial.print(_SIDPW_id); Serial.println("]");

  knx.load(); // Try to load a config from EEPROM

  sSID_ID = knx.get_config_string(_SIDID_id);
  sSID_PW = knx.get_config_string(_SIDPW_id);

  Serial.print("Connect to AP ["); Serial.print(sSID_ID); Serial.println("]");
  ....

If the sSID_ID and sSID_PW does not make a WiFi connection I start the wifiManager to select the right AP. Then I want to save the new WiFi.SSID() and WiFi.pks() to te already registered positions ...

I tried:

_SIDID_id = knx.__config_set_string(_SIDID_id, WiFi.SSID());

but "__config_set_string()" is not public...

So, I created a public function:

void ESPKNXIP::update_config_string(config_id_t id, String val)
{
  memcpy(&custom_config_data[custom_configs[id].offset], val.c_str(), val.length()+1);
}

... that does the trick! Any change you can put this patch in the master?

Same goes with update_config_int() i suppose ..

Regards