// Décodeur LoRaWAN officiel : TC01-LB (Dragino) // Source : https://github.com/TheThingsNetwork/lorawan-devices/blob/master/vendor/dragino/tc01-lb.js // The Things Network Device Repository, fichier publié par le constructeur, distribué sans modification. // Format : decodeUplink(input) (TTN v3 / ChirpStack v4). Hébergé par smartbuildings.fr. function decodeUplink(input) {\n return { \n data: Decode(input.fPort, input.bytes, input.variables)\n }; \n}\nfunction datalog(i,bytes){\n var aa= bytes[3+i];\n var bb= parseFloat(((bytes[4+i]<<24>>16 | bytes[5+i])/10).toFixed(2));\n var cc= (bytes[6+i]&0x02) ? \"High\":\"Low\";\n var dd= (bytes[6+i]&0x01) ? \"True\":\"False\";\n var ee= getMyDate((bytes[7+i]<<24 | bytes[8+i]<<16 | bytes[9+i]<<8 | bytes[10+i]).toString(10));\n var string='['+aa+','+bb+','+cc+','+dd+','+ee+']'+','; \n \n return string;\n}\n\nfunction getzf(c_num){ \n if(parseInt(c_num) < 10)\n c_num = '0' + c_num; \n\n return c_num; \n}\n\nfunction getMyDate(str){ \n var c_Date;\n if(str > 9999999999)\n c_Date = new Date(parseInt(str));\n else \n c_Date = new Date(parseInt(str) * 1000);\n \n var c_Year = c_Date.getFullYear(), \n c_Month = c_Date.getMonth()+1, \n c_Day = c_Date.getDate(),\n c_Hour = c_Date.getHours(), \n c_Min = c_Date.getMinutes(), \n c_Sen = c_Date.getSeconds();\n var c_Time = c_Year +'-'+ getzf(c_Month) +'-'+ getzf(c_Day) +' '+ getzf(c_Hour) +':'+ getzf(c_Min) +':'+getzf(c_Sen); \n \n return c_Time;\n}\n\nfunction Decode(fPort, bytes, variables) {\n //TC01-LB Decode \n if(fPort==0x02)\n {\n var decode = {};\n decode.battery=(bytes[0]<<8 | bytes[1])/1000;\n decode.type= bytes[2];\n decode.temperature= parseFloat(((bytes[3]<<24>>16 | bytes[4])/10).toFixed(2));\n decode.interrupt_flag=(bytes[5] & 0x01)? \"TRUE\":\"FALSE\";\n decode.interrupt_level=(bytes[5] & 0x02)? \"HIGH\":\"LOW\"; \n decode.temph_flag= (bytes[5] &0x04)? \"True\":\"False\";\n decode.templ_flag= (bytes[5] &0x08)? \"True\":\"False\";\n decode.data_time= getMyDate((bytes[6]<<24 | bytes[7]<<16 | bytes[8]<<8 | bytes[9]).toString(10)); \n \n if(bytes.length==10)\n return decode;\n }\n else if(fPort==3) \n {\n var pnack= ((bytes[6]>>7)&0x01) ? \"True\":\"False\";\n for(var i=0;i>4&0x0f)+'.'+(bytes[2]&0x0f);\n \n if(bytes[3]==0x01)\n freq_band=\"EU868\";\n else if(bytes[3]==0x02)\n freq_band=\"US915\";\n else if(bytes[3]==0x03)\n freq_band=\"IN865\";\n else if(bytes[3]==0x04)\n freq_band=\"AU915\";\n else if(bytes[3]==0x05)\n freq_band=\"KZ865\";\n else if(bytes[3]==0x06)\n freq_band=\"RU864\";\n else if(bytes[3]==0x07)\n freq_band=\"AS923\";\n else if(bytes[3]==0x08)\n freq_band=\"AS923_1\";\n else if(bytes[3]==0x09)\n freq_band=\"AS923_2\";\n else if(bytes[3]==0x0A)\n freq_band=\"AS923_3\";\n else if(bytes[3]==0x0F)\n freq_band=\"AS923_4\";\n else if(bytes[3]==0x0B)\n freq_band=\"CN470\";\n else if(bytes[3]==0x0C)\n freq_band=\"EU433\";\n else if(bytes[3]==0x0D)\n freq_band=\"KR920\";\n else if(bytes[3]==0x0E)\n freq_band=\"MA869\";\n \n if(bytes[4]==0xff)\n sub_band=\"NULL\";\n else\n sub_band=bytes[4];\n\n var bat= (bytes[5]<<8 | bytes[6])/1000;\n \n return {\n SENSOR_MODEL:sensor,\n FIRMWARE_VERSION:firm_ver,\n FREQUENCY_BAND:freq_band,\n SUB_BAND:sub_band,\n battery:bat,\n }\n }\n}\n