diff --git a/vendor/dragino/lht65.js b/vendor/dragino/lht65.js index 76cad8a068..f1c5a5221f 100644 --- a/vendor/dragino/lht65.js +++ b/vendor/dragino/lht65.js @@ -102,22 +102,30 @@ default: } function normalizeUplink(input) { - return { - data: [ - { - air: { - location: "indoor", - temperature: input.data.TempC_SHT, - relativeHumidity: input.data.Hum_SHT, - } - }, - { - air: { - location: "outdoor", - temperature: input.data.TempC_DS, - }, - battery: input.data.BatV + var data = []; + + if (input.data.TempC_SHT) { + data.push({ + air: { + location: "indoor", + temperature: input.data.TempC_SHT, + relativeHumidity: input.data.Hum_SHT, } - ] - }; + }); + } + + if (input.data.TempC_DS) { + var val = { + air: { + location: "outdoor", + temperature: input.data.TempC_DS + } + } + if (input.data.BatV) { + val.battery = input.data.BatV + } + data.push(val); + } + + return { data: data }; } diff --git a/vendor/dragino/lse01.js b/vendor/dragino/lse01.js index bc906fb882..dfae74a447 100644 --- a/vendor/dragino/lse01.js +++ b/vendor/dragino/lse01.js @@ -35,17 +35,37 @@ switch (input.fPort) { } function normalizeUplink(input) { - return { - data: { - air: { - temperature: Number(input.data.TempC_DS18B20), - }, - soil: { - temperature: Number(input.data.temp_SOIL), - moisture: Number(input.data.water_SOIL), - ec: input.data.conduct_SOIL / 1000, - }, - battery: input.data.Bat, - } - }; + var data = {}; + var air = {}; + var soil = {}; + + if (input.data.TempC_DS18B20) { + air.temperature = Number(input.data.TempC_DS18B20); + } + + if (input.data.temp_SOIL) { + soil.temperature = Number(input.data.temp_SOIL); + } + + if (input.data.water_SOIL) { + soil.moisture = Number(input.data.water_SOIL); + } + + if (input.data.conduct_SOIL) { + soil.ec = input.data.conduct_SOIL / 1000; + } + + if (Object.keys(air).length > 0) { + data.air = air; + } + + if (Object.keys(soil).length > 0) { + data.soil = soil; + } + + if (input.data.Bat) { + data.battery = input.data.Bat; + } + + return { data: data }; } diff --git a/vendor/dragino/lsn50-v2.js b/vendor/dragino/lsn50-v2.js index 61fe744775..243b8b5ef3 100644 --- a/vendor/dragino/lsn50-v2.js +++ b/vendor/dragino/lsn50-v2.js @@ -199,16 +199,33 @@ default: } function normalizeUplink(input) { - return { - data: { - air: { - temperature: input.data.TempC_SHT, - relativeHumidity: input.data.Hum_SHT, - }, - action: { - contactState: input.data.Door_status === "CLOSE" ? "closed" : input.data.Door_status === "OPEN" ? "open" : undefined - }, - battery: input.data.BatV, - } - }; + var data = {}; + var air = {}; + var action = {}; + + if (input.data.TempC_SHT) { + air.temperature = input.data.TempC_SHT; + } + + if (input.data.Hum_SHT) { + air.relativeHumidity = input.data.Hum_SHT; + } + + if (input.data.Door_status === "CLOSE" || input.data.Door_status === "OPEN") { + action.contactState = input.data.Door_status === "CLOSE" ? "closed" : "open"; + } + + if (Object.keys(air).length > 0) { + data.air = air; + } + + if (Object.keys(action).length > 0) { + data.action = action; + } + + if (input.data.BatV) { + data.battery = input.data.BatV; + } + + return { data: data }; } diff --git a/vendor/dragino/lsn50v2-s31.js b/vendor/dragino/lsn50v2-s31.js index dea7d1c7f5..88ba741875 100644 --- a/vendor/dragino/lsn50v2-s31.js +++ b/vendor/dragino/lsn50v2-s31.js @@ -100,16 +100,33 @@ default: } function normalizeUplink(input) { - return { - data: { - air: { - temperature: input.data.TempC_SHT, - relativeHumidity: input.data.Hum_SHT - }, - action: { - contactState: input.data.Door_status === "CLOSE" ? "closed" : input.data.Door_status === "OPEN" ? "open" : undefined - }, - battery: input.data.BatV, - } - }; + var data = {}; + var air = {}; + var action = {}; + + if (input.data.TempC_SHT) { + air.temperature = input.data.TempC_SHT; + } + + if (input.data.Hum_SHT) { + air.relativeHumidity = input.data.Hum_SHT; + } + + if (input.data.Door_status === "CLOSE" || input.data.Door_status === "OPEN") { + action.contactState = input.data.Door_status === "CLOSE" ? "closed" : "open"; + } + + if (Object.keys(air).length > 0) { + data.air = air; + } + + if (Object.keys(action).length > 0) { + data.action = action; + } + + if (input.data.BatV) { + data.battery = input.data.BatV; + } + + return { data: data }; } diff --git a/vendor/milesight-iot/em300-th.js b/vendor/milesight-iot/em300-th.js index f0f9d7748d..f82bc10373 100644 --- a/vendor/milesight-iot/em300-th.js +++ b/vendor/milesight-iot/em300-th.js @@ -58,17 +58,27 @@ function Decoder(bytes, port) { } function normalizeUplink(input) { - return { - data: { - air: { - temperature: input.data.temperature, - relativeHumidity: input.data.humidity - }, - battery: input.data.battery, + var data = {}; + var air = {}; + + if (input.data.temperature) { + air.temperature = input.data.temperature; } - }; -} + if (input.data.humidity) { + air.relativeHumidity = input.data.humidity; + } + + if (Object.keys(air).length > 0) { + data.air = air; + } + + if (input.data.battery) { + data.battery = input.data.battery; + } + + return { data: data }; +} /* ****************************************** * bytes to number diff --git a/vendor/milesight-iot/ws301.js b/vendor/milesight-iot/ws301.js index aafd67643a..d1fdceb5b9 100644 --- a/vendor/milesight-iot/ws301.js +++ b/vendor/milesight-iot/ws301.js @@ -46,12 +46,17 @@ function Decoder(bytes, port) { function normalizeUplink(input) { - return { - data: { - action: { - contactState: input.data.door === "close" ? "closed" : input.data.door === "open" ? "open" : undefined - }, - battery: input.data.battery, - } - }; + var data = {}; + + if (input.data.door && (input.data.door === "close" || input.data.door === "open")) { + data.action = { + contactState: input.data.door === "close" ? "closed" : "open" + }; + } + + if (input.data.battery) { + data.battery = input.data.battery; + } + + return { data: data }; } diff --git a/vendor/sensative/strips.js b/vendor/sensative/strips.js index 5fe6191729..2392254932 100644 --- a/vendor/sensative/strips.js +++ b/vendor/sensative/strips.js @@ -192,12 +192,15 @@ function decodeUplink(input) { } function normalizeUplink(input) { - return { - data: { - air: { - temperature: input.data.temperature.value, - }, - battery: input.data.battery - } - }; - } + var data = {}; + + if (input.data && input.data.temperature && input.data.temperature.value) { + data.air = { temperature: input.data.temperature.value }; + } + + if (input.data && input.data.battery) { + data.battery = input.data.battery; + } + + return { data: data }; +}