Commit 40f82fd2 authored by Michael Ott's avatar Michael Ott
Browse files

Fix dcdbcsvimport to work in the new MQTT-Topic regime

parent b98bdff6
......@@ -90,21 +90,8 @@ sensor_t* createSensor(DCDB::SensorConfig& sensorConfig, const std::string& name
sensor->topic = psensor.pattern;
sensor->publicName = psensor.name;
} else {
int prefixLen = prefix.size() - std::count(prefix.begin(), prefix.end(), '/');
int suffixLen = 28-prefixLen;
do {
std::stringstream ss;
ss << std::setfill ('0') << std::setw(suffixLen) << std::hex << suffix;
std::string suffixStr = ss.str();
if ((size_t)suffixLen < suffixStr.size()) {
std::cerr << "The specified MQTT prefix (" << prefixLen << ") length is too long, it should not exceed " << 28 - suffixStr.size() << " hex characters" << std::endl;
exit(EXIT_FAILURE);
}
sensor->topic = prefix + suffixStr;
suffix++;
} while (sensorConfig.getPublicSensorByPattern(psensor, sensor->topic.c_str()) != DCDB::SC_UNKNOWNSENSOR);
sensor->topic = prefix + "/" + name;
sensor->publicName = name;
std::replace(sensor->publicName.begin(), sensor->publicName.end(), ' ', '_');
......@@ -179,11 +166,7 @@ int main(int argc, char** argv)
std::string csvFilename = argv[optind];
std::string prefix = argv[optind+1];
int prefixLen = prefix.size()-std::count(prefix.begin(), prefix.end(), '/');
if (prefixLen > 27) {
std::cerr << "The specified MQTT prefix is too long (" << prefixLen << "), it must not exceed 27 hex characters." << std::endl;
}
columns.erase(tsColumn);
if (sensorNameColumn > -1) {
columns.erase(sensorNameColumn);
......@@ -329,6 +312,8 @@ int main(int argc, char** argv)
}
}
std::cout << "Inserted " << total << " readings" << std::endl;
fs.close();
/* Create public sensor names */
......
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