// Décodeur LoRaWAN officiel : AQS01-L (Dragino) // Source : https://github.com/TheThingsNetwork/lorawan-devices/blob/master/vendor/dragino/aqs01-l.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= parseFloat(((bytes[4+i]<<24>>16 | bytes[5+i])/10).toFixed(1));\n var bb= parseFloat(((bytes[2+i]<<8 | bytes[3+i])/10).toFixed(1));\n var cc= parseFloat(bytes[0+i]<<8 | bytes[1+i]);\n var dd= 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+']'+','; \n \n return string;\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])/1000;\n data.temperature= parseFloat(((bytes[2]<<24>>16 | bytes[3])/10).toFixed(1));\n data.humidity= parseFloat(((bytes[4]<<8 | bytes[5])/10).toFixed(1));\n data.air_pressure= parseFloat(((bytes[6]<<8 | bytes[7])/10).toFixed(1));\n data.co2= bytes[8]<<8 | bytes[9];\n data.TEMPL_flag= (bytes[10] &0x08)? \"True\":\"False\";\n data.TEMPH_flag= (bytes[10] &0x04)? \"True\":\"False\";\n data.CO2L_flag= (bytes[10] &0x02)? \"True\":\"False\";\n data.CO2H_flag= (bytes[10] &0x01)? \"True\":\"False\"; \n\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}