diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h index bf59785..7bb0610 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h @@ -412,7 +412,7 @@ class WeatherSensor { void setSensorsCfg(uint8_t max_sensors, uint8_t rx_flags, uint8_t en_decoders = 0xFF); /*! - * Get sensors include list from Preferences + * Get sensors include list (Preferences/defaults) * * \param payload buffer for storing sensor IDs * @@ -421,7 +421,7 @@ class WeatherSensor { uint8_t getSensorsInc(uint8_t *payload); /*! - * Get sensors exclude list from Preferences + * Get sensors exclude list (Preferences/defaults) * * \param payload buffer for storing sensor IDs * diff --git a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp index 0a546be..b5551d1 100644 --- a/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp +++ b/examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp @@ -39,6 +39,7 @@ // 20240513 Created from WeatherSensor.cpp // 20240608 Modified implementation of maximum number of sensors // 20240609 Fixed implementation of maximum number of sensors +// 20240702 Fixed handling of empty list of IDs / 0x00000000 in Preferences // // // ToDo: @@ -55,6 +56,7 @@ void WeatherSensor::initList(std::vector &list, const std::vector &list, const std::vector &list, const std::vector= 0; i--) + { + *payload++ = (id >> (i * 8)) & 0xFF; + } + } - return size; + return sensor_ids_inc.size() * 4; } // Set sensors exclude list in Preferences @@ -149,16 +152,18 @@ void WeatherSensor::setSensorsExc(uint8_t *buf, uint8_t size) } } -// Get sensors exclude list from Preferences +// Get sensors exclude list uint8_t WeatherSensor::getSensorsExc(uint8_t *payload) { - cfgPrefs.begin("BWS-CFG", false); - uint8_t size = cfgPrefs.getBytesLength("exc"); - cfgPrefs.getBytes("exc", payload, size); - cfgPrefs.end(); - log_d("size: %d", size); + for (const uint32_t &id : sensor_ids_exc) + { + for (int i = 3; i >= 0; i--) + { + *payload++ = (id >> (i * 8)) & 0xFF; + } + } - return size; + return sensor_ids_exc.size() * 4; } // Set sensor configuration and store in in Preferences