// Décodeur LoRaWAN officiel : WL03A-LB (Dragino) // Source : https://github.com/TheThingsNetwork/lorawan-devices/blob/master/vendor/dragino/wl03a-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[0+i]&0x08)?\"PART\":\"SUM\";\n var bb=(bytes[0+i]&0x04)?\"YES\":\"NO\"; \n var cc=(bytes[0+i]&0x02)?\"TRUE\":\"FALSE\"; \n var dd=(bytes[0+i]&0x01)?\"LEAK\":\"NO LEAK\"; \n var ee=(bytes[1+i]<<16 | bytes[2+i]<<8 | bytes[3+i]).toString(10);\n var ff=(bytes[4+i]<<16 | bytes[5+i]<<8 | bytes[6+i]).toString(10);\n var gg= 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+','+gg+']'+','; \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 if(fPort==0x03)\n {\n var pnack= ((bytes[0]>>7)&0x01) ? \"True\":\"False\";\n for(var i=0;i>4&0x0f)+'.'+(bytes[2]&0x0f);\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 else\n { \n var count_mod=(bytes[0]&0x08)?\"PART\":\"SUM\"; \n var tdc_interval=(bytes[0]&0x04)?\"YES\":\"NO\"; \n var alarm=(bytes[0]&0x02)?\"TRUE\":\"FALSE\"; \n var leak_status=(bytes[0]&0x01)?\"LEAK\":\"NO LEAK\"; \n var leak_times=bytes[1]<<16 | bytes[2]<<8 | bytes[3];\n var leak_duration=bytes[4]<<16 | bytes[5]<<8 | bytes[6];\n var data_time= getMyDate((bytes[7]<<24 | bytes[8]<<16 | bytes[9]<<8 | bytes[10]).toString(10));\n \n if(bytes.length==11)\n {\n return {\n count_mod:count_mod, \n tdc:tdc_interval,\n alarm:alarm,\n water_leak_status:leak_status,\n water_leak_times:leak_times,\n lsat_water_leak_duration:leak_duration,\n time:data_time\n };\n }\n }\n}