Commit 5f76ba03 authored by Micha Mueller's avatar Micha Mueller
Browse files

Add config parameter minValues

Available values in queue are only published if their number is >= minValues
parent 021cd550
......@@ -62,7 +62,7 @@ void MQTTPusher::push() {
while (keepRunning || totalCount) {
totalCount = 0;
BOOST_FOREACH(SYSFSSensor& sensor, _cfg._sensors) {
if (sensor.getSizeOfReadingQueue()) {
if (sensor.getSizeOfReadingQueue() >= sensor.getMinValues()) {
if (!_connected) {
if (mosquitto_reconnect(_mosq) != MOSQ_ERR_SUCCESS) {
std::cout << "mosquitto: could not reconnect to MQTT broker " << _cfg._global.brokerHost << ":" << _cfg._global.brokerPort << std::endl;
......@@ -84,7 +84,7 @@ void MQTTPusher::push() {
if (mosquitto_publish(_mosq, NULL, (_cfg._global.mqttPrefix+sensor.getMqtt()).c_str(), sizeof(reading_t)*count, reads, 0, false) != MOSQ_ERR_SUCCESS) {
std::cerr << "mosquitto: could not send message! Trying again later" << std::endl;
mosquitto_disconnect(_mosq);
_connected = 0;
_connected = false;
sensor.pushReadingQueue(reads, count);
sleep(5);
break;
......
......@@ -97,6 +97,8 @@ void SYSFSConfiguration::readSensor(SYSFSSensor& sensor, boost::property_tree::i
sensor.setInterval(stoi(s.second.data()));
} else if (boost::iequals(s.first, "mqttsuffix")) {
sensor.setMqtt(s.second.data());
} else if (boost::iequals(s.first, "minValues")) {
sensor.setMinValues(stoull(s.second.data()));
} else if (boost::iequals(s.first, "minI")) {
sensor.setConvert(true);
sensor.setMinI(stoull(s.second.data()));
......@@ -151,6 +153,7 @@ void SYSFSConfiguration::readSensor(SYSFSSensor& sensor, boost::property_tree::i
cout << " Path : " << sensor.getPath() << endl;
cout << " MQTT : " << sensor.getMqtt() << endl;
cout << " Interval: " << sensor.getInterval() << endl;
cout << " minValues:" << sensor.getMinValues() << endl;
if (sensor.doConvert()) {
cout << " minI : " << sensor.getMinI() << endl;
cout << " maxI : " << sensor.getMaxI() << endl;
......
......@@ -17,6 +17,7 @@ SYSFSSensor::SYSFSSensor(const std::string& name) {
_name = name;
_path = "";
_mqtt = "";
_minValues = 1;
_interval = 1000;
_convert = false;
_minI = 0;
......
......@@ -50,6 +50,14 @@ public:
_mqtt = mqtt;
}
uint64_t getMinValues() const {
return _minValues;
}
void setMinValues(uint64_t minValues) {
_minValues = minValues;
}
FILE* getFile() const {
return _file;
}
......@@ -144,6 +152,7 @@ private:
std::string _name;
std::string _path;
std::string _mqtt;
uint64_t _minValues;
bool _convert;
int64_t _minI;
int64_t _maxI;
......
......@@ -10,6 +10,7 @@ SensorTemplate {
interval 1000
mqttsuffix 0000
filter "s/Temperature ([[:digit:]]+)\\.([[:digit:]]+)°C/\\1\\200/"
minValues 3
}
sensor def2 {
......@@ -32,6 +33,7 @@ sensors {
path /home/micha/LRZ/dcdbOwnFork/sysfspusher/freq
interval 1000
mqttsuffix 0010
minValues 10
filter s/Frequency=([[:digit:]]+)/\\1/
}
......
Supports Markdown
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