forked from Brunas/esp32_p1meter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readout.ino
32 lines (28 loc) · 1.01 KB
/
readout.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
setupDataReadout()
This method reads JSON string specified in DsmrMap variable in dsmr_map.h file
and converts to telegramDecodedObjects MQTT vector.
*/
void setupDataReadout() {
JsonDocument _dsmrMapDocument;
DeserializationError _error = deserializeJson(_dsmrMapDocument, DSMR_MAP);
if (_error) {
debug("deserializeJson() failed: ");
debug(_error.c_str());
return;
}
// Create TelegramObject vector which will be used to send MQTT messages
const uint _count = _dsmrMapDocument.as<JsonArray>().size();
for (int i = 0; i < _count; i++) {
TelegramDecodedObject _tdo;
strcpy(_tdo.code, _dsmrMapDocument.as<JsonArray>()[i]["OBIS"]);
_tdo.name = _dsmrMapDocument.as<JsonArray>()[i]["Name"].as<String>();
telegramObjects.push_back(_tdo);
}
#ifdef DEBUG
debug("MQTT Topics initialized (" + String(_count) + "):");
for (int i = 0; i < _count; i++) {
debug(String(MQTT_ROOT_TOPIC) + "/" + telegramObjects[i].name + ". OBIS: " + String(telegramObjects[i].code));
}
#endif
}