// 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] // - variables contains the device variables e.g. {"calibration": "3.5"} (both the key / value are of type string) // The function must return an object, e.g. {"temperature": 22.5} function Decode(fPort, bytes, variables) { var mode=(bytes[2] & 0x7C)>>2; var data = {}; data.Bat_V=(bytes[0]<<8 | bytes[1])/1000 + 0.267; if(mode==1) { data.Work_mode="CO2"; data.Alarm_status=(bytes[2] & 0x01)? "TRUE":"FALSE"; data.TVOC_ppb= bytes[3]<<8 | bytes[4]; data.CO2_ppm= bytes[5]<<8 | bytes[6]; data.TempC_SHT=parseFloat(((bytes[7]<<24>>16 | bytes[8])/10).toFixed(2)); data.Hum_SHT=parseFloat(((bytes[9]<<8 | bytes[10])/10).toFixed(1)); } else if(mode==31) { data.Work_mode="ALARM"; data.SHTEMPMIN= bytes[3]<<24>>24; data.SHTEMPMAX= bytes[4]<<24>>24; data.SHTHUMMIN= bytes[5]; data.SHTHUMMAX= bytes[6]; data.CO2MIN= bytes[7]<<8 | bytes[8]; data.CO2MAX= bytes[9]<<8 | bytes[10]; } if(bytes.length==11) { return data; } }