Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
products:camel:camelv1 [2023/01/13 09:49] – manu | products:camel:camelv1 [2023/01/13 18:21] (current) – manu | ||
---|---|---|---|
Line 33: | Line 33: | ||
===== - Manuel utilisateur ===== | ===== - Manuel utilisateur ===== | ||
{{ : | {{ : | ||
+ | |||
+ | ===== - Javascript Codec to decode LoRaWAN frames ===== | ||
+ | |||
+ | The function used to parse the bytes transmitted in LoRaWAN | ||
+ | |||
+ | <sxh javascript; first-line: 1;> | ||
+ | // Decode decodes an array of bytes into an object. | ||
+ | // - fPort contains the LoRaWAN fPort number | ||
+ | // - bytes is an array of bytes, e.g. [225, 230, 255, 0] | ||
+ | // The function must return an object, e.g. {" | ||
+ | var TEMP_BYTE_0_IDX = 0; | ||
+ | var TEMP_BYTE_1_IDX = 1; | ||
+ | var RH_BYTE_0_IDX = 2; | ||
+ | var RH_BYTE_1_IDX = 3; | ||
+ | var VOLT_BYTE_0_IDX = 4; | ||
+ | var LORA_MIN_BATT_VAL = 1; | ||
+ | var LORA_MAX_BATT_VAL = 254; | ||
+ | var LORA_BATT_RANGE = LORA_MAX_BATT_VAL - LORA_MIN_BATT_VAL; | ||
+ | var LORA_BATT_ERROR = 255; | ||
+ | var BATT_VOLTAGE_LOW = 3.0; | ||
+ | var BATT_VOLTAGE_HIGH = 4.2; | ||
+ | |||
+ | |||
+ | function Decode(fPort, | ||
+ | |||
+ | var temperature_code = 0; | ||
+ | var humidity_code = 0; | ||
+ | var temperature = 0.0; | ||
+ | var humidity = 0.0; | ||
+ | var voltage_code = 0; | ||
+ | var voltage = 0.0 | ||
+ | temperature_code = (bytes[TEMP_BYTE_0_IDX] << 8 ) + bytes[TEMP_BYTE_1_IDX]; | ||
+ | humidity_code = (bytes[RH_BYTE_0_IDX] << 8 ) + bytes[RH_BYTE_1_IDX]; | ||
+ | voltage_code = bytes[VOLT_BYTE_0_IDX]; | ||
+ | | ||
+ | temperature = ((175.72 * temperature_code) / 65536.0) - 46.85; | ||
+ | humidity = ((125.0 * humidity_code) / 65536.0) - 6.0; | ||
+ | var data = {}; | ||
+ | if (voltage_code != LORA_BATT_ERROR) { | ||
+ | voltage = (((voltage_code - LORA_MIN_BATT_VAL) * (BATT_VOLTAGE_HIGH - BATT_VOLTAGE_LOW))/ | ||
+ | data = | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }; | ||
+ | } | ||
+ | else { | ||
+ | data = | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | return data; | ||
+ | } | ||
+ | </ |