I'm trying to readout a heat meter. The data of the meter is send via M-Bus to a Teltonika TRB 143 router and then send over MQTT to my NodeRed. On the router i can choose between the data format XML and HEX.
if i use XML i get the following data:
<?xml version="1.0" encoding="ISO-8859-1"?> <MBusData> <SlaveInformation> <Id>66180143</Id> <Manufacturer>DME</Manufacturer> <Version>160</Version> <ProductName></ProductName>
<Medium>Heat: Outlet</Medium> <AccessNumber>0</AccessNumber> <Status>00</Status> <Signature>0000</Signature> </SlaveInformation>
<DataRecord id="0"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Energy (10 kWh)</Unit> <Value>70880</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="1"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Tariff>1</Tariff> <Device>0</Device> <Unit>Energy (10 kWh)</Unit> <Value>0</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="2"><Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Tariff>2</Tariff> <Device>0</Device> <Unit>Volume (1e-2 m^3)</Unit> <Value>31850</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="3"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Volume (1e-2 m^3)</Unit> <Value>3297988</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="4"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Power (W)</Unit> <Value>0</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="5"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Volume flow (m m^3/h)</Unit> <Value>0</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="6"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Flow temperature (1e-1 deg C)</Unit> <Value>752</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="7"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Return temperature (1e-1 deg C)</Unit> <Value>715</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="8"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Temperature Difference (1e-1 deg C)</Unit> <Value>37</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="9"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Operating time (hours)</Unit> <Value>30728</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="10"> <Function>Instantaneous value</Function> <StorageNumber>0</StorageNumber> <Unit>Time Point (time & date)</Unit> <Value>2023-07-25T16:23:00</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="11"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Unit>Energy (10 kWh)</Unit> <Value>70579</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="12"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Unit>Volume (1e-2 m^3)</Unit> <Value>3280495</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="13"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Tariff>1</Tariff> <Device>0</Device> <Unit>Energy (10 kWh)</Unit> <Value>0</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="14"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Tariff>2</Tariff> <Device>0</Device> <Unit>Volume (1e-2 m^3)</Unit> <Value>31846</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp>
</DataRecord> <DataRecord id="15"> <Function>Instantaneous value</Function> <StorageNumber>1</StorageNumber> <Unit>Time Point (date)</Unit> <Value>2023-06-30</Value> <Timestamp>2023-07-25T13:54:03Z</Timestamp> </DataRecord> </MBusData> `
With the MQTT Node i only get a string as an output and cannot use the data, i want a JavaScript Object. When i choose the option: "output: parsed J-SON object", i just get "failed to parse json string".
How can i convert my string to a JS object?