Commit 9f210cc7 authored by Micha Mueller's avatar Micha Mueller
Browse files

Minor improvement to MQTT topic check

parent 6f4c2e4f
......@@ -104,7 +104,7 @@ bool Configuration::read() {
try {
boost::property_tree::read_info(globalConfig, cfg);
} catch (boost::property_tree::info_parser_error& e) {
LOG(fatal) << "global.conf not found! Please make sure the ocnfig-path is correct.";
LOG(fatal) << "global.conf not found! Please make sure the config-path is correct.";
return false;
}
......@@ -182,7 +182,7 @@ bool Configuration::read() {
if(checkMqtt(s->getMqtt())) {
_sensors.push_back(s);
} else {
LOG(error) << "MQTT-Suffix used twice! Aborting";
LOG(error) << "Problematic MQTT-Topics! Please check your config files";
return false;
}
}
......@@ -198,32 +198,21 @@ bool Configuration::read() {
}
return true;
}
/*
bool Configuration::readSensorVals(Sensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
sensor.setInterval(stoull(val.second.data()));
} else if (boost::iequals(val.first, "minValues")) {
sensor.setMinValues(stoull(val.second.data()));
} else {
//
}
}
LOG(debug) << " Interval : " << sensor.getInterval();
LOG(debug) << " minValues: " << sensor.getMinValues();
return true;
}*/
bool Configuration::checkMqtt(const std::string& mqtt) {
//MQTT topic must have at least 128 bit = 16 bytes = 32 hex chars
//but can have more (with some extra '/')
if (mqtt.length() < 32) {
LOG(error) << "MQTT-Topic \"" << mqtt << "\" not long enough!";
//MQTT topic must have 128 bit = 16 bytes = 32 hex chars
//but can have more with some extra '/', therefore remove all '/'
std::string str(mqtt);
str.erase(std::remove(str.begin(), str.end(), '/'), str.end());
if (str.length() != 32) {
LOG(error) << "MQTT-Topic \"" << mqtt << "\" does not consist of 32 hex chars!";
return false;
}
auto returnIt = _mqttSuffixes.insert(mqtt);
auto returnIt = _mqttTopics.insert(mqtt);
if (!returnIt.second) {
LOG(error) << "MQTT-Topic \"" << mqtt << "\" used twice!";
return false;
}
return true;
......
......@@ -84,7 +84,7 @@ private:
std::string _cfgFilePath;
global_t _global;
sensorVector_t _sensors;
mqttSet_t _mqttSuffixes;
mqttSet_t _mqttTopics;
//vector which holds data of the opened plugins
std::vector<dl_t> _plugins;
......
......@@ -50,7 +50,7 @@ sensorVector_t sensors;
void sigintHandler(int sig) {
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
LOG(info) << "Received SIGINT";
LOG(fatal) << "Received SIGINT";
//Stop all sensors
LOG(info) << "Stopping sensors...";
for(auto s : sensors) {
......
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