// Décodeur LoRaWAN officiel : TS01-LB (Dragino) // Source : https://github.com/TheThingsNetwork/lorawan-devices/blob/master/vendor/dragino/ts01-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 var port = input.fPort;\n var bytes = input.bytes;\n var mode=(bytes[6] & 0x7C)>>2;\n var data = {};\n function datalog(i,bytes){\n var aa=(bytes[0+i]<<8 | bytes[1+i]).toString(10)/10;\n var bb=((bytes[2+i]<<8 | bytes[3+i]).toString(10)/32768.0*180).toFixed(2);\n var cc=((bytes[4+i]<<8 | bytes[5+i]).toString(10)/32768.0*180).toFixed(2);\n var dd=(bytes[6+i]&0x01)?\"OPEN\":\"CLOSE\"; \n var ee=(bytes[6+i]&0x01)?\"TRUE\":\"FLASE\"; \n var ff= 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+','+ff+']'+','; \n \n return string;\n}\n\n function getzf(c_num){ \n if(parseInt(c_num) < 10)\n c_num = '0' + c_num; \n\n return c_num; \n }\n\n function 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 switch (input.fPort) {\n case 2:\n\n \n data.batV=((bytes[0]<<8 | bytes[1]) & 0x3FFF)/1000;\n \n \n data.i_flag =(bytes[2])&0x80; \n data.a_flag =(bytes[2])&0x01;\n \n value=bytes[3]<<8 | bytes[4];\n if(bytes[3] & 0x80)\n {value |= 0xFFFF0000;}\n data.temp_DS18B20=(value/10).toFixed(2);//DS18B20,temperature \n \n value=bytes[5]<<8 | bytes[6];\n if(bytes[5] & 0x80)\n {value |= 0xFFFF0000;} \n data.Roll=(value/32768.0*180).toFixed(2);\n\n value=bytes[7]<<8 | bytes[8];\n if(bytes[7] & 0x80)\n {value |= 0xFFFF0000;} \n data.Pitch=(value/32768.0*180).toFixed(2);\n \n if(bytes[9]==0)\n {\n var in_flag = \"Level\"; \n }\n else\n {\n in_flag = \"Vertical\"; \n }\n data.in_flag=in_flag;\n\n if(bytes.length==11)\n return {\n data: data,\n }\n break;\ncase 3:\n var pnack= ((bytes[6]>>7)&0x01) ? \"True\":\"False\";\n for(var i=0;i>4&0x0f)+'.'+(bytes[2]&0x0f);\n data.BAT= (bytes[5]<<8 | bytes[6])/1000;\n }\n return {\n data: data,\n }\n break;\n \n default:\n return {\n errors: [\"unknown FPort\"]\n }\n}\n}