meterbus
This commit is contained in:
12
src/main.ts
12
src/main.ts
@ -10,9 +10,19 @@ const VERBOSE : boolean = true
|
|||||||
|
|
||||||
|
|
||||||
const TOPIC_PARSERS : { [key : string] : (msg: string) => string } = {
|
const TOPIC_PARSERS : { [key : string] : (msg: string) => string } = {
|
||||||
'IoT/espThermometer2/measurement': (msg : string) => {
|
'IoT/espThermometer2/measurement': (msg) => {
|
||||||
let jsonData = JSON.parse(msg)
|
let jsonData = JSON.parse(msg)
|
||||||
return `temperature,location=${jsonData.location} value=${jsonData.temperature}\nbattery,location=${jsonData.location},device=thermometer value=${jsonData.battery}`
|
return `temperature,location=${jsonData.location} value=${jsonData.temperature}\nbattery,location=${jsonData.location},device=thermometer value=${jsonData.battery}`
|
||||||
|
},
|
||||||
|
'IoT/ParsedData/MeterbusHub': (msg) => {
|
||||||
|
let jsonData = JSON.parse(msg)
|
||||||
|
if ('power' in jsonData.values) {
|
||||||
|
return `power,category=${jsonData.name} value=${jsonData.values.power}`
|
||||||
|
} else if ('temperature' in jsonData.values) {
|
||||||
|
return `temperature,location=${jsonData.name} value=${jsonData.values.temperature}`
|
||||||
|
} else {
|
||||||
|
throw new Error('no category found for meterbus value')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user