diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h
index 53b0dc1..d8f5cc1 100644
--- a/Arduino/CanGrow/include/CanGrow.h
+++ b/Arduino/CanGrow/include/CanGrow.h
@@ -228,6 +228,7 @@ struct Config_System_Sensor {
byte type[Max_Sensors];
char name[Max_Sensors][32];
+ char i2c_address[Max_Sensors][5];
byte gpio[Max_Sensors];
};
diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h
index 6e72f33..142c780 100644
--- a/Arduino/CanGrow/include/CanGrow_LittleFS.h
+++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h
@@ -234,6 +234,7 @@ bool LoadConfig() {
if(objSystemSensor["type"][i] > 0) {
config.system.sensor.type[i] = objSystemSensor["type"][i];
strlcpy(config.system.sensor.name[i], objSystemSensor["name"][i], sizeof(config.system.sensor.name[i]));
+ strlcpy(config.system.sensor.i2c_address[i], objSystemSensor["i2c_address"][i], sizeof(config.system.sensor.i2c_address[i]));
// gpio
config.system.sensor.gpio[i] = objSystemSensor["gpio"][i];
@@ -328,6 +329,7 @@ bool SaveConfig(bool writeToSerial = false) {
if(config.system.sensor.type[i] > 0) {
objSystemSensor["type"][i] = config.system.sensor.type[i];
objSystemSensor["name"][i] = config.system.sensor.name[i];
+ objSystemSensor["i2c_address"][i] = config.system.sensor.i2c_address[i];
objSystemSensor["gpio"][i] = config.system.sensor.gpio[i];
}
diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h
index a9de976..ea7ccd1 100644
--- a/Arduino/CanGrow/include/Webserver/Page_system.h
+++ b/Arduino/CanGrow/include/Webserver/Page_system.h
@@ -974,6 +974,13 @@ String Proc_WebPage_system_sensor_addEdit(const String& var) {
sensorName.replace("%", "%");
return sensorName;
+ } else if(var == "SENSOR_I2C_ADDRESS") {
+ // "escape" % character, because it would break the template processor.
+ // tasmote webcall for example has percentage char in its path
+ String sensorI2cAddress = config.system.sensor.i2c_address[tmpParam_editSensorId];
+ sensorI2cAddress.replace("%", "%");
+ return sensorI2cAddress;
+
} else if(var == "GPIO_INDEX") {
return Html_SelectOpt_GPIOindex(config.system.sensor.gpio[tmpParam_editSensorId]);
@@ -1028,6 +1035,12 @@ void WebPage_system_sensor_add(AsyncWebServerRequest *request) {
strlcpy(config.system.sensor.name[sensorId], p_name->value().c_str(), sizeof(config.system.sensor.name[sensorId]));
}
+ if(request->hasParam("i2c_address", true)) {
+ const AsyncWebParameter* p_i2c_address = request->getParam("i2c_address", true);
+ Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_i2c_address->name().c_str(), p_i2c_address->value().c_str());
+ strlcpy(config.system.sensor.i2c_address[sensorId], p_i2c_address->value().c_str(), sizeof(config.system.sensor.i2c_address[sensorId]));
+ }
+
if(request->hasParam("gpio", true)) {
const AsyncWebParameter* p_gpio = request->getParam("gpio", true);
Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio->name().c_str(), p_gpio->value().c_str());
diff --git a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h
index 25a6740..54a4f81 100644
--- a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h
+++ b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h
@@ -278,7 +278,11 @@ const char* Page_system_sensor_add_HTML PROGMEM = R"(%HEADER%
Name:
-
+
+
+I2C address:
+
leave empty for default
+