added handling of bad cases for INT and FLOAT
@@ -368,15 +368,19 @@ JSONReading::JSONReading(const Value& json)
// The reading should be an object at this stage, it is and invalid one if not
// the asset name ASSET_NAME_INVALID_READING will be created in the PI-Server containing the
// invalid asset_name/values.
+ if (json["reading"].IsString())
+ {
string tmp_reading1 = json["reading"].GetString();
// Escape specific character for to be properly manage as JSON
- for(const string &item : JSON_characters_to_be_escaped) {
+ for (const string &item : JSON_characters_to_be_escaped)
+ {
escapeCharacter(tmp_reading1, item);
}
- Logger::getLogger()->error("Invalid reading: Asset name |%s| reading value |%s| converted value |%s|",
+ Logger::getLogger()->error(
+ "Invalid reading: Asset name |%s| reading value |%s| converted value |%s|",
m_asset.c_str(),
json["reading"].GetString(),
tmp_reading1.c_str());
@@ -384,6 +388,29 @@ JSONReading::JSONReading(const Value& json)
DatapointValue value(tmp_reading1);
this->addDatapoint(new Datapoint(m_asset, value));
+ } else if (json["reading"].IsInt() ||
+ json["reading"].IsUint() ||
+ json["reading"].IsInt64() ||
+ json["reading"].IsUint64()) {
+
+ DatapointValue *value;
+
+ if (json["reading"].IsInt() ||
+ json["reading"].IsUint()) {
+ value = new DatapointValue((long) json["reading"].GetInt());
+ } else {
+ value = new DatapointValue((long) json["reading"].GetInt64());
+ }
+ this->addDatapoint(new Datapoint(m_asset, *value));
+ delete value;
+
+ } else if (json["reading"].IsDouble())
+ {
+ DatapointValue value(json["reading"].GetDouble());
+ this->addDatapoint(new Datapoint(m_asset, value));
+
+ }
+
m_asset = string(ASSET_NAME_INVALID_READING) + string("_") + m_asset.c_str();
}
}
