Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed handling of empty list of IDs / 0x00000000 in Preferences #180

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/BresserWeatherSensorMQTTCustom/src/WeatherSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down
43 changes: 24 additions & 19 deletions examples/BresserWeatherSensorMQTTCustom/src/WeatherSensorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -55,6 +56,7 @@ void WeatherSensor::initList(std::vector<uint32_t> &list, const std::vector<uint
list.clear();
cfgPrefs.begin("BWS-CFG", false);
log_d("Key %s in preferences? %d", key, cfgPrefs.isKey(key));

if (cfgPrefs.isKey(key))
{
size_t size = cfgPrefs.getBytesLength(key);
Expand All @@ -64,27 +66,26 @@ void WeatherSensor::initList(std::vector<uint32_t> &list, const std::vector<uint
if ((buf[0] | buf[1] | buf[2] | buf[3]) == 0)
{
size = 0;
log_d("Empty list");
}
for (size_t i = 0; i < size; i += 4)
{
list.push_back(
(buf[i] << 24) |
(buf[i + 1] << 16) |
(buf[i + 2] << 8) |
buf[i + 3]);
buf[i + 3]
);
}
}
else

if (list.size() == 0)
{
log_d("Using sensor_ids_%s list from WeatherSensorCfg.h", key);
list = list_def;
}
cfgPrefs.end();

if (list.size() == 0)
{
log_d("(empty)");
}
for (size_t i = 0; i < list.size(); i++)
{
log_d("%08X", list[i]);
Expand Down Expand Up @@ -117,13 +118,15 @@ void WeatherSensor::setSensorsInc(uint8_t *buf, uint8_t size)
// Get sensors include list from Preferences
uint8_t WeatherSensor::getSensorsInc(uint8_t *payload)
{
cfgPrefs.begin("BWS-CFG", false);
uint8_t size = cfgPrefs.getBytesLength("inc");
cfgPrefs.getBytes("inc", payload, size);
cfgPrefs.end();
log_d("size: %d", size);
for (const uint32_t &id : sensor_ids_inc)
{
for (int i = 3; i >= 0; i--)
{
*payload++ = (id >> (i * 8)) & 0xFF;
}
}

return size;
return sensor_ids_inc.size() * 4;
}

// Set sensors exclude list in Preferences
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=BresserWeatherSensorReceiver
version=0.28.7
version=0.28.8
author=Matthias Prinke <matthias-bs@web.de>
maintainer=Matthias Prinke <matthias-bs@web.de>
sentence=Bresser 5-in-1/6-in-1/7-in-1 868 MHz Weather Sensor Radio Receiver for Arduino based on CC1101, SX1276/RFM95W or SX1262.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BresserWeatherSensorReceiver",
"version": "0.28.7",
"version": "0.28.8",
"description": "Bresser 5-in-1/6-in-1/7-in-1 868 MHz Weather Sensor Radio Receiver for Arduino based on CC1101, SX1276/RFM95W or SX1262",
"main": "WeatherSensor.cpp",
"frameworks": "arduino",
Expand Down
4 changes: 2 additions & 2 deletions src/WeatherSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down
43 changes: 24 additions & 19 deletions src/WeatherSensorConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -55,6 +56,7 @@ void WeatherSensor::initList(std::vector<uint32_t> &list, const std::vector<uint
list.clear();
cfgPrefs.begin("BWS-CFG", false);
log_d("Key %s in preferences? %d", key, cfgPrefs.isKey(key));

if (cfgPrefs.isKey(key))
{
size_t size = cfgPrefs.getBytesLength(key);
Expand All @@ -64,27 +66,26 @@ void WeatherSensor::initList(std::vector<uint32_t> &list, const std::vector<uint
if ((buf[0] | buf[1] | buf[2] | buf[3]) == 0)
{
size = 0;
log_d("Empty list");
}
for (size_t i = 0; i < size; i += 4)
{
list.push_back(
(buf[i] << 24) |
(buf[i + 1] << 16) |
(buf[i + 2] << 8) |
buf[i + 3]);
buf[i + 3]
);
}
}
else

if (list.size() == 0)
{
log_d("Using sensor_ids_%s list from WeatherSensorCfg.h", key);
list = list_def;
}
cfgPrefs.end();

if (list.size() == 0)
{
log_d("(empty)");
}
for (size_t i = 0; i < list.size(); i++)
{
log_d("%08X", list[i]);
Expand Down Expand Up @@ -117,13 +118,15 @@ void WeatherSensor::setSensorsInc(uint8_t *buf, uint8_t size)
// Get sensors include list from Preferences
uint8_t WeatherSensor::getSensorsInc(uint8_t *payload)
{
cfgPrefs.begin("BWS-CFG", false);
uint8_t size = cfgPrefs.getBytesLength("inc");
cfgPrefs.getBytes("inc", payload, size);
cfgPrefs.end();
log_d("size: %d", size);
for (const uint32_t &id : sensor_ids_inc)
{
for (int i = 3; i >= 0; i--)
{
*payload++ = (id >> (i * 8)) & 0xFF;
}
}

return size;
return sensor_ids_inc.size() * 4;
}

// Set sensors exclude list in Preferences
Expand All @@ -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
Expand Down
Loading