// Decode uplink function. // // Input is an object with the following fields: // - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0] // - fPort = Uplink fPort. // - variables = Object containing the configured device variables. // // Output must be an object with the following fields: // - data = Object representing the decoded payload. function decodeUplink(input) { return { data: Decoder(input.bytes, input.fPort) }; } function datalog(i,bytes){ var aa= parseFloat(((bytes[3+i]<<24>>16 | bytes[4+i])/10).toFixed(1)); var bb= parseFloat(((bytes[5+i]<<8 | bytes[6+i])/10).toFixed(1)); var cc= getMyDate((bytes[7+i]<<24 | bytes[8+i]<<16 | bytes[9+i]<<8 | bytes[10+i]).toString(10)); var string='['+aa+','+bb+','+cc+']'+','; return string; } function getzf(c_num){ if(parseInt(c_num) < 10) c_num = '0' + c_num; return c_num; } function getMyDate(str){ var c_Date; if(str > 9999999999) c_Date = new Date(parseInt(str)); else c_Date = new Date(parseInt(str) * 1000); var c_Year = c_Date.getFullYear(), c_Month = c_Date.getMonth()+1, c_Day = c_Date.getDate(), c_Hour = c_Date.getHours(), c_Min = c_Date.getMinutes(), c_Sen = c_Date.getSeconds(); var c_Time = c_Year +'-'+ getzf(c_Month) +'-'+ getzf(c_Day) +' '+ getzf(c_Hour) +':'+ getzf(c_Min) +':'+getzf(c_Sen); return c_Time; } function Decoder(bytes, port) { //LSN50_v2_S31_S31B Decode if(port==0x02) { var decode = {}; var mode=(bytes[6] & 0x7C)>>2; if(mode==0) { decode.BatV=(bytes[0]<<8 | bytes[1])/1000; decode.EXTI_Trigger=(bytes[6] & 0x01)? "TRUE":"FALSE"; // decode.Door_status=(bytes[6] & 0x80)? "CLOSE":"OPEN"; decode.TempC_SHT31= parseFloat(((bytes[7]<<24>>16 | bytes[8])/10).toFixed(1)); decode.Hum_SHT31=parseFloat(((bytes[9]<<8 | bytes[10])/10).toFixed(1)); // decode.Data_time= getMyDate((bytes[2]<<24 | bytes[3]<<16 | bytes[4]<<8 | bytes[5]).toString(10)); } else if(mode==31) { decode.SHTEMP_MIN= bytes[7]<<24>>24; decode.SHTEMP_MAX= bytes[8]<<24>>24; decode.SHHUM_MIN= bytes[9]; decode.SHHUM_MAX= bytes[10]; } if(bytes.length==11) return decode; } else if(port==3) { for(var i=0;i>4&0x0f)+'.'+(bytes[3]&0x0f); var tdc_time= bytes[4]<<16 | bytes[5]<<8 | bytes[6]; return { FIRMWARE_VERSION:firm_ver, FREQUENCY_BAND:freq_band, SUB_BAND:sub_band, TDC_sec:tdc_time, } } } // Encode downlink function. // // Input is an object with the following fields: // - data = Object representing the payload that must be encoded. // - variables = Object containing the configured device variables. // // Output must be an object with the following fields: // - bytes = Byte array containing the downlink payload. function encodeDownlink(input) { return { bytes: [225, 230, 255, 0] }; }