From c1a4d2540cc75ada53074167d85e3ab0dc2f4943 Mon Sep 17 00:00:00 2001 From: Thiemann96 Date: Wed, 13 Sep 2023 10:05:55 +0200 Subject: [PATCH 1/2] added transformers for rg15 phenomena --- lib/decoding/sensebox_home.js | 143 ++++++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 41 deletions(-) diff --git a/lib/decoding/sensebox_home.js b/lib/decoding/sensebox_home.js index 6aaeb6d..62211c5 100644 --- a/lib/decoding/sensebox_home.js +++ b/lib/decoding/sensebox_home.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /** * This decoding profile decodes the measurements for the sensors of the @@ -8,136 +8,197 @@ * @license MIT */ -const { bytesToInt, findSensorIds } = require('./helpers'); +const { bytesToInt, findSensorIds } = require("./helpers"); // alternative titles recognized for the sensors const sensorMatchings = { temperature: { - title: ['temperatur', 'temperature'], + title: ["temperatur", "temperature"], }, humidity: { - title: ['rel. luftfeuchte', 'luftfeuchtigkeit', 'humidity'] + title: ["rel. luftfeuchte", "luftfeuchtigkeit", "humidity"], }, pressure: { - title: ['luftdruck', 'druck', 'pressure', 'air pressure'] + title: ["luftdruck", "druck", "pressure", "air pressure"], }, lightintensity: { - title: ['licht', 'helligkeit', 'beleuchtungsstärke', 'einstrahlung', 'light', 'light intensity'] + title: [ + "licht", + "helligkeit", + "beleuchtungsstärke", + "einstrahlung", + "light", + "light intensity", + ], }, uvlight: { - title: ['uv', 'uv-a', 'uv-intensität', 'uv-intensity'] + title: ["uv", "uv-a", "uv-intensität", "uv-intensity"], }, pm10: { - title: ['pm10', 'pm 10'] + title: ["pm10", "pm 10"], }, pm25: { - title: ['pm2.5', 'pm 2.5'] + title: ["pm2.5", "pm 2.5"], }, soiltemperature: { - title: ['soiltemperature', 'soil temperature', 'temperature soil', 'bodentemperatur', 'boden temperatur', 'temperatur boden'] + title: [ + "soiltemperature", + "soil temperature", + "temperature soil", + "bodentemperatur", + "boden temperatur", + "temperatur boden", + ], }, soilmoisture: { - title: ['soilmoisture', 'soil moisture', 'moisture soil', 'bodenfeuchte', 'boden feuchte', 'feuchte boden', 'bodenfeuchtigkeit', 'boden feuchtigkeit', 'feuchtigkeit boden'] + title: [ + "soilmoisture", + "soil moisture", + "moisture soil", + "bodenfeuchte", + "boden feuchte", + "feuchte boden", + "bodenfeuchtigkeit", + "boden feuchtigkeit", + "feuchtigkeit boden", + ], }, soundlevel: { - title: ['soundlevel', 'sound level', 'lautstärke', 'schallpegel', 'schall pegel'] + title: [ + "soundlevel", + "sound level", + "lautstärke", + "schallpegel", + "schall pegel", + ], }, bmetemperature: { - title: ['lufttemperatur'] + title: ["lufttemperatur"], }, bmehumidity: { - title: ['luftfeuchte'] + title: ["luftfeuchte"], }, bmepressure: { - title: ['atm. luftdruck'] + title: ["atm. luftdruck"], }, bmevoc: { - title: ['VOC'] + title: ["VOC"], }, windspeed: { - title: ['windgeschwindigkeit', 'wind weschwindigkeit', 'windspeed', 'wind speed'] + title: [ + "windgeschwindigkeit", + "wind weschwindigkeit", + "windspeed", + "wind speed", + ], }, co2: { - title: ['co2', 'CO₂', 'co 2'] - } + title: ["co2", "CO₂", "co 2"], + }, + rg15_total: { + title: ["Niederschlag (gesamt)"], + }, + rg15_event: { + title: ["Niederschlag (letztes Ereignis)"], + }, + rg15_intensity: { + title: ["Regenintensität"], + }, }; const transformers = { temperature: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 771 - 18).toFixed(1)) + transformer: (bytes) => + parseFloat((bytesToInt(bytes) / 771 - 18).toFixed(1)), }, humidity: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 1e2).toFixed(1)) + transformer: (bytes) => parseFloat((bytesToInt(bytes) / 1e2).toFixed(1)), }, pressure: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 81.9187 + 300).toFixed(1)) + transformer: (bytes) => + parseFloat((bytesToInt(bytes) / 81.9187 + 300).toFixed(1)), }, lightintensity: { bytes: 3, - transformer (bytes) { + transformer(bytes) { const [mod, ...times] = bytes; return bytesToInt(times) * 255 + bytesToInt([mod]); - } + }, }, uvlight: { bytes: 3, - transformer (bytes) { + transformer(bytes) { const [mod, ...times] = bytes; return bytesToInt(times) * 255 + bytesToInt([mod]); - } + }, }, pm10: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 10).toFixed(1)) + transformer: (bytes) => parseFloat((bytesToInt(bytes) / 10).toFixed(1)), }, pm25: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 10).toFixed(1)) + transformer: (bytes) => parseFloat((bytesToInt(bytes) / 10).toFixed(1)), }, soiltemperature: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 771 - 18).toFixed(1)) + transformer: (bytes) => + parseFloat((bytesToInt(bytes) / 771 - 18).toFixed(1)), }, soilmoisture: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 1e2).toFixed(1)) + transformer: (bytes) => parseFloat((bytesToInt(bytes) / 1e2).toFixed(1)), }, soundlevel: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 10).toFixed(1)) + transformer: (bytes) => parseFloat((bytesToInt(bytes) / 10).toFixed(1)), }, bmetemperature: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 771 - 18).toFixed(1)) + transformer: (bytes) => + parseFloat((bytesToInt(bytes) / 771 - 18).toFixed(1)), }, bmehumidity: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 1e2).toFixed(1)) + transformer: (bytes) => parseFloat((bytesToInt(bytes) / 1e2).toFixed(1)), }, bmepressure: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 81.9187 + 300).toFixed(1)) + transformer: (bytes) => + parseFloat((bytesToInt(bytes) / 81.9187 + 300).toFixed(1)), }, bmevoc: { bytes: 3, - transformer (bytes) { + transformer(bytes) { const [mod, ...times] = bytes; return bytesToInt(times) * 255 + bytesToInt([mod]); - } + }, }, windspeed: { bytes: 2, - transformer: bytes => parseFloat((bytesToInt(bytes) / 10).toFixed(1)) + transformer: (bytes) => parseFloat((bytesToInt(bytes) / 10).toFixed(1)), }, co2: { bytes: 2, - transformer: bytes => bytesToInt(bytes) + transformer: (bytes) => bytesToInt(bytes), + }, + rg15_total: { + bytes: 2, + transformer: (bytes) => bytesToInt(bytes) / 10, + }, + rg15_event: { + bytes: 2, + transformer: (bytes) => bytesToInt(bytes) / 10, + }, + rg15_intensity: { + bytes: 2, + transformer: (bytes) => bytesToInt(bytes) / 10, }, }; @@ -147,7 +208,7 @@ const transformers = { * @param {Box} box - The box to retrieve sensorIds from * @return {Array} A bufferTransformer for the box */ -const createBufferTransformer = function createBufferTransformer (box) { +const createBufferTransformer = function createBufferTransformer(box) { const sensorMap = findSensorIds(box.sensors, sensorMatchings); const transformer = []; @@ -157,7 +218,7 @@ const createBufferTransformer = function createBufferTransformer (box) { transformer.push({ sensorId: sensorMap[key], bytes: transformers[key].bytes, - transformer: transformers[key].transformer + transformer: transformers[key].transformer, }); } } @@ -166,5 +227,5 @@ const createBufferTransformer = function createBufferTransformer (box) { }; module.exports = { - createBufferTransformer + createBufferTransformer, }; From 420f88099becb6ac2e94d78fea7d223d5fece935 Mon Sep 17 00:00:00 2001 From: Thiemann96 Date: Wed, 13 Sep 2023 10:10:02 +0200 Subject: [PATCH 2/2] added parsefloat to transformer --- lib/decoding/sensebox_home.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/decoding/sensebox_home.js b/lib/decoding/sensebox_home.js index 62211c5..422099f 100644 --- a/lib/decoding/sensebox_home.js +++ b/lib/decoding/sensebox_home.js @@ -190,15 +190,15 @@ const transformers = { }, rg15_total: { bytes: 2, - transformer: (bytes) => bytesToInt(bytes) / 10, + transformer: (bytes) => parseFloat(bytesToInt(bytes) / 10).toFixed(1), }, rg15_event: { bytes: 2, - transformer: (bytes) => bytesToInt(bytes) / 10, + transformer: (bytes) => parseFloat(bytesToInt(bytes) / 10).toFixed(1), }, rg15_intensity: { bytes: 2, - transformer: (bytes) => bytesToInt(bytes) / 10, + transformer: (bytes) => parseFloat(bytesToInt(bytes) / 10).toFixed(1), }, };