Commit bef55e84 authored by Alessio Netti's avatar Alessio Netti
Browse files

Updated subsampling function

- If a subSampling value of 0 or lower is chosen for a sensor, it will
never be pushed out over MQTT/Cassandra and only kept in memory
parent 34427d8b
......@@ -476,7 +476,7 @@ protected:
} else if (boost::iequals(val.first, "delta")) {
sBase.setDelta(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "subSampling")) {
sBase.setSubsampling(std::stoul(val.second.data()));
sBase.setSubsampling(std::stoi(val.second.data()));
}
}
sensorBase(sBase, config);
......
......@@ -118,7 +118,7 @@ public:
const std::string& getMqtt() const { return _mqtt; }
bool getSkipConstVal() const { return _skipConstVal; }
unsigned getCacheInterval() const { return _cacheInterval; }
unsigned getSubsampling() const { return _subsamplingFactor; }
int getSubsampling() const { return _subsamplingFactor; }
const CacheEntry* const getCache() const { return _cache.get(); }
const reading_t& getLatestValue() const { return _latestValue; }
const bool isInit() const { return _cache && _readingQueue; }
......@@ -131,7 +131,7 @@ public:
void setName(const std::string& name) { _name = name; }
void setMqtt(const std::string& mqtt) { _mqtt = mqtt; }
void setCacheInterval(unsigned cacheInterval) { _cacheInterval = cacheInterval; }
void setSubsampling(unsigned factor) { _subsamplingFactor = factor; }
void setSubsampling(int factor) { _subsamplingFactor = factor; }
void setLastRaw(int64_t raw) { _lastRawValue.value = raw; }
void setLastURaw(uint64_t raw) { _lastRawUValue.value = raw; }
......@@ -253,7 +253,7 @@ public:
else
_accumulator.value = reading.value;
if (_subsamplingIndex++ % _subsamplingFactor == 0) {
if (_subsamplingFactor>0 && _subsamplingIndex++%_subsamplingFactor==0) {
_accumulator.timestamp = reading.timestamp;
//TODO: if sensor starts with values of 0, these won't be pushed. This should be fixed
if( !(_skipConstVal && (_accumulator.value == _lastSentValue.value)) ) {
......@@ -280,7 +280,7 @@ protected:
std::string _mqtt;
bool _skipConstVal;
unsigned int _cacheInterval;
unsigned int _subsamplingFactor;
int _subsamplingFactor;
unsigned int _subsamplingIndex;
std::unique_ptr<CacheEntry> _cache;
bool _delta;
......
......@@ -302,7 +302,7 @@ All the different plugins share some same general principles in common regarding
3. Sensors hold only those attributes which are necessary to uniquely identify the target sensor. Common base attributes:
* __mqttsuffix__ (to make its [mqtt-topic](#mqttTopic) unique)
* __delta__ (identifies a monotonic sensor. If set to "on", differences between successive readings are collected)
* __subSampling__ (subsampling factor S. If > 1, only one reading every S is sent over MQTT, and the others are kept locally)
* __subSampling__ (subsampling factor S. If S>=1, only one reading every S is sent over MQTT, and the others are kept locally. If S<1, readings are never sent out and only kept locally)
5. Be aware that naming of sensor/group/entity is not fixed. A plugin developer can name them as he likes, e.g. counter/multicounter/host.
6. It is possible to define template groups or entities in the config file, but not template sensors (as a sensor should only consists of attributs which make him unique this would not be too useful). To specify a template group/entity simply prefix its definition with `template_` (see the example below). You can reference them later by using the `default` attribute. A template entity can consist of groups and these in turn can consist of sensors. When using a template, all of its attribute values are copied to the actual sensor. Copied attributes can be overwritten in the actual entity/sensor (some of them even should be overwritten, e.g. the mqttPart). However, groups/sensors associated with a template are copied to the actual entity/group and can NOT be overwritten. One can specify further groups/sensors which are then added to those copied from the template. Template entitys/groups itself or sensors within them are never used in live operation of the plugin. They are purely cosmetic for convenient configuration.
......
......@@ -382,7 +382,7 @@ protected:
} else if (boost::iequals(val.first, "delta")) {
sBase.setDelta(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "subSampling")) {
sBase.setSubsampling(std::stoul(val.second.data()));
sBase.setSubsampling(std::stoi(val.second.data()));
}
}
sensorBase(sBase, config);
......@@ -955,7 +955,7 @@ protected:
} else if (boost::iequals(val.first, "delta")) {
sBase.setDelta(to_bool(val.second.data()));
} else if (boost::iequals(val.first, "subSampling")) {
sBase.setSubsampling(std::stoul(val.second.data()));
sBase.setSubsampling(std::stoi(val.second.data()));
}
}
sensorBase(sBase, config);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment