Milesight Node Red & Watteco decoder
Watteco's devices are compatible with the Milesight LoRaWAN gateways.
Present tutorial is a simple entry point to Watteco standard LoRaWAN codec usage inside the embeded NodeRed. Following exemple uses an UG56 gateway with NodeRed installed. Please follow the user guide and other milesight documentations to install the gateway and declare your devices on it. Once a device is correctly associated with the gateway, you can implement your decoding functions with the embeded NodeRed.
Javascript codec for Watteco sensors are available on our Github repository. Notice that the distribution of our javascript codecs is available through NPM packages and can be easily imported if the aimed device support NPM package management (ie: npm install <wattecoSensor codec>).
However, the current Milesight Gateway firmware does not support NPM import.
Milesigth support : "Milesight UG56 do not currently support updating Node-re versions via npm package. Since updating in this way will result in modifications to other configuration files of the gateway. But a release is expected in May 2024 to support Node-red 3.0. The version number is 56.0.0.4 and will support the latest version of node-red at that time."
Below is a quick and easy way to use our codec distribution when npm package management is not available, with a simple copy and paste of the required codec and a light source complement. Please follow the steps below.
- Under Node Red screen (Button <Launch> under APP/NodeRed menu of the Gateway administration screen), create your own sensor specific function node. And connect it to LoraInput Node as input and msg Node as output.
- Open the just created node (double click) and name it. Here it will be used to decode a Watteco Temperature humidity sensor dataflow. Hence choosen name is "TH_decodeUplink".
- Copy the full source code from our TH codec distribution. and copy it in the function TAB source code of the node.
- Go at the end of the big line "var driver ..." and remove the following words at the end: "exports.driver=driver"
- Jump to a final line and add the input object formating of the driver function decodeUplink.
Finaly, the source code should be :
var driver;var driver;(()=>{var t={580:e=>{let t=6,a=10,i=12,r={0:0,1:1,2:4,3:4,4:8,5:8};r[t]=16,r[7]=16,r[8]=24,r[9]=24,r[a]=32,r[11]=32,r[i]=32;let n=14,o=[[{sz:2,lbl:0},{sz:2,lbl:1},{sz:2,lbl:3},{sz:3,lbl:5},{sz:4,lbl:9},{sz:5,lbl:17},{sz:6,lbl:33},{sz:7,lbl:65},{sz:8,lbl:129},{sz:10,lbl:512},{sz:11,lbl:1026},{sz:11,lbl:1027},{sz:11,lbl:1028},{sz:11,lbl:1029},{sz:11,lbl:1030},{sz:11,lbl:1031}],[{sz:7,lbl:111},{sz:5,lbl:26},{sz:4,lbl:12},{sz:3,lbl:3},{sz:3,lbl:7},{sz:2,lbl:2},{sz:2,lbl:0},{sz:3,lbl:2},{sz:6,lbl:54},{sz:9,lbl:443},{sz:9,lbl:441},{sz:10,lbl:885},{sz:10,lbl:884},{sz:10,lbl:880},{sz:11,lbl:1763},{sz:11,lbl:1762}],[{sz:4,lbl:9},{sz:3,lbl:5},{sz:2,lbl:0},{sz:2,lbl:1},{sz:2,lbl:3},{sz:5,lbl:17},{sz:6,lbl:33},{sz:7,lbl:65},{sz:8,lbl:129},{sz:10,lbl:512},{sz:11,lbl:1026},{sz:11,lbl:1027},{sz:11,lbl:1028},{sz:11,lbl:1029},{sz:11,lbl:1030},{sz:11,lbl:1031}]];function d(e,t,a,i){return{uncompressSamples:[{data_relative_timestamp:i,data:{value:u(e,t),label:a}}],codingType:0,codingTable:0,resolution:null}}function l(e,t){for(let a=0;an?e.getNextSample(a):i>0?function(e,t,i){return e.getNextSample(a,i)+t+Math.pow(2,i)-1}(e,t,i):t}function u(e,t){let a=e.getNextSample(t);return t===i?function(e){let t=2147483648&e?-1:1,a=(e>>23&255)-127,i=8388607&e;if(128===a)return t*(i?Number.NaN:Number.POSITIVE_INFINITY);if(-127===a){if(0===i)return 0*t;a=-126,i/=1<<22}else i=(i|1<<23)/(1<<23);return t*i*Math.pow(2,a)}(a):a}function c(e,a,i,r,n){let o=e.getNextSample(t,n);return 0===i?function(e,t,a,i){return e>=Math.pow(2,i-1)?e*t+a:(e+1-Math.pow(2,i))*t+a}(o,r,a,n):1===i?(o+Math.pow(2,n)-1)*r+a:a-(o+(Math.pow(2,n)-1))*r}Math.trunc=Math.trunc||function(e){return isNaN(e)?NaN:e>0?Math.floor(e):Math.ceil(e)},e.exports={normalisation_batch:function(e){let t=e.date,u=function(e,t,u,p){let m=function(){let e=[],t=0;for(;t<16;)e.push({codingType:0,codingTable:0,resolution:null,uncompressSamples:[]}),t+=1;return{batch_counter:0,batch_relative_timestamp:0,series:e}}(),f=function(e){function t(e,t,a){let i=t,r=a-1;if(8*e.length0;)e[i>>3]&1<<(7&i)&&(o|=1<0&&(l=8);d>0;){let e=0;for(;l>0;){let t=n>>3;this.byteArray[t]&1<<(7&n)&&(o|=1<<8*(d-1)+e),l--,e++,n+=1}d--,l=8}if((3==e||5==e||7==e||9==e)&&o&1<=2;)t.push(parseInt(e.substring(0,2),16)),e=e.substring(2,e.length);return t}(u)),g=function(e){let t=e.toString(2);for(;t.length<8;)t="0"+t;return{isCommonTimestamp:parseInt(t[t.length-2],2),hasSample:!parseInt(t[t.length-3],2),batch_req:parseInt(t[t.length-4],2),nb_of_type_measure:parseInt(t.substring(0,4),2)}}(f.getNextSample(4));m.batch_counter=f.getNextSample(4,3),f.getNextSample(4,1);let E=function(e,t,a,i,r){let n=0,o=0;for(let _=0;_0){let e=o[s-1];o.push(t.getNextSample(a,i)+e+Math.pow(2,i)-1)}else o.push(precedingTimestamp);else o.push(t.getNextSample(a));d=o[s]}return{timestampCommon:o,lastTimestamp:d}}(e,t,s,i),p=u.timestampCommon,m=u.lastTimestamp;for(let a=0;a0)l.data.value=c(t,n,e.series[i].codingType,r[i].resol,d);else{if(a){a=0;continue}l.data.value=n}}else l.data.value=t.getNextSample(r[i].sampletype);l.data_relative_timestamp=p[o],e.series[i].uncompressSamples.push(l)}}return m}(e,t,i,r,d,s):function(e,t,a,i,r,o){let d={};for(let s=0;si&&(i=l.data_relative_timestamp),s=t.getNextBifromHi(e.series[r].codingTable),s<=n){let i=e.series[r].uncompressSamples[e.series[r].uncompressSamples.length-1].data.value;l.data.value=s>0?c(t,i,e.series[r].codingType,a[r].resol,s):i}else l.data.value=t.getNextSample(a[r].sampletype);e.series[r].uncompressSamples.push(l)}}}return i}(e,t,r,o,d,s)}(m,f,v,t,P,g,e)),m.batch_relative_timestamp=s(f,P),function(e,t,a){let i={batch_counter:e.batch_counter,batch_relative_timestamp:e.batch_relative_timestamp};return a&&(i.batch_absolute_timestamp=a),i.dataset=e.series.reduce((function(i,r,n){return i.concat(r.uncompressSamples.map((function(i){let r={data_relative_timestamp:i.data_relative_timestamp,data:{value:t[n].divide?i.data.value/t[n].divide:i.data.value,label:t[n].taglbl}};var o,d,l;return t[n].lblname&&(r.data.label_name=t[n].lblname),a&&(r.data_absolute_timestamp=(o=a,d=e.batch_relative_timestamp,l=i.data_relative_timestamp,new Date(new Date(o)-1e3*(d-l)).toISOString())),r})))}),[]),i}(m,t,p)}(e.batch1,e.batch2,e.payload,t),p=[];for(let e=0;e{const i=a(794),r=a(580);e.exports={watteco_decodeUplink:function(e,t,a){e.bytes,e.fPort;let n=e.recvTime;try{let o=i.normalisation_standard(e,a),d=o.payload;if("batch"!==o.type)return{data:o.data,warnings:o.warning};{let e={batch1:t[0],batch2:t[1],payload:d,date:n};try{return{data:r.normalisation_batch(e),warnings:[]}}catch(e){return{error:e.message,warnings:[]}}}}catch(e){return{error:e.message,warnings:[]}}}}},794:t=>{class a extends Error{constructor(e){super(e),this.name="ValidationError"}}let i={16:{name:"boolean",size:1},8:{name:"general8",size:1},9:{name:"general16",size:2},10:{name:"general24",size:3},11:{name:"general32",size:4},24:{name:"bitmap8",size:1},25:{name:"bitmap16",size:2},32:{name:"uint8",size:1},33:{name:"uint16",size:2},34:{name:"uint24",size:3},35:{name:"uint32",size:4},40:{name:"int8",size:1},41:{name:"int16",size:2},43:{name:"int32",size:4},48:{name:"enum8",size:1},66:{name:"char string",size:1},65:{name:"bytes string",size:1},67:{name:"long bytes string",size:2},76:{name:"structured ordered sequence",size:2},57:{name:"single",size:4}},r={32778:{0:{0:{divider:1,function_type:"int",name:"positive_active_energy",size:4},1:{divider:1,function_type:"int",name:"negative_active_energy",size:4},2:{divider:1,function_type:"int",name:"positive_reactive_energy",size:4},3:{divider:1,function_type:"int",name:"negative_reactive_energy",size:4},4:{divider:1,function_type:"int",name:"positive_active_power",size:4},5:{divider:1,function_type:"int",name:"negative_active_power",size:4},6:{divider:1,function_type:"int",name:"positive_reactive_power",size:4},7:{divider:1,function_type:"int",name:"negative_reactive_power",size:4}}},32784:{0:{0:{divider:1,function_type:"int",name:"active_energy_a",size:4},1:{divider:1,function_type:"int",name:"reactive_energy_a",size:4},2:{divider:1,function_type:"int",name:"active_energy_b",size:4},3:{divider:1,function_type:"int",name:"reactive_energy_b",size:4},4:{divider:1,function_type:"int",name:"active_energy_c",size:4},5:{divider:1,function_type:"int",name:"reactive_energy_c",size:4},6:{divider:1,function_type:"int",name:"active_energy_abc",size:4},7:{divider:1,function_type:"int",name:"reactive_energy_abc",size:4}},1:{0:{divider:1,function_type:"int",name:"active_power_a",size:4},1:{divider:1,function_type:"int",name:"reactive_power_a",size:4},2:{divider:1,function_type:"int",name:"active_power_b",size:4},3:{divider:1,function_type:"int",name:"reactive_power_b",size:4},4:{divider:1,function_type:"int",name:"active_power_c",size:4},5:{divider:1,function_type:"int",name:"reactive_power_c",size:4},6:{divider:1,function_type:"int",name:"active_power_abc",size:4},7:{divider:1,function_type:"int",name:"reactive_power_abc",size:4}}},32779:{0:{0:{divider:10,function_type:"int",name:"Vrms",size:2},1:{divider:10,function_type:"int",name:"Irms",size:2},2:{divider:1,function_type:"int",name:"angle",size:2}}},32781:{0:{0:{divider:10,function_type:"int",name:"Vrms_a",size:2},1:{divider:10,function_type:"int",name:"Irms_a",size:2},2:{divider:1,function_type:"int",name:"angle_a",size:2},3:{divider:10,function_type:"int",name:"Vrms_b",size:2},4:{divider:10,function_type:"int",name:"Irms_b",size:2},5:{divider:1,function_type:"int",name:"angle_b",size:2},6:{divider:10,function_type:"int",name:"Vrms_c",size:2},7:{divider:10,function_type:"int",name:"Irms_c",size:2},8:{divider:1,function_type:"int",name:"angle_c",size:2}}},32850:{0:{0:{divider:1e3,function_type:"int",name:"frequency",size:2},1:{divider:1e3,function_type:"int",name:"frequency_min",size:2},2:{divider:1e3,function_type:"int",name:"frequency_max",size:2},3:{divider:10,function_type:"int",name:"Vrms",size:2},4:{divider:10,function_type:"int",name:"Vrms_min",size:2},5:{divider:10,function_type:"int",name:"Vrms_max",size:2},6:{divider:10,function_type:"int",name:"Vpeak",size:2},7:{divider:10,function_type:"int",name:"Vpeak_min",size:2},8:{divider:10,function_type:"int",name:"Vpeak_max",size:2},9:{divider:1,function_type:"int",name:"over_voltage",size:2},10:{divider:1,function_type:"int",name:"sag_voltage",size:2}}},32773:{0:{0:{divider:1,function_type:"none",name:"pin_state_1",size:1},1:{divider:1,function_type:"none",name:"pin_state_2",size:1},2:{divider:1,function_type:"none",name:"pin_state_3",size:1},3:{divider:1,function_type:"none",name:"pin_state_4",size:1},4:{divider:1,function_type:"none",name:"pin_state_5",size:1},5:{divider:1,function_type:"none",name:"pin_state_6",size:1},6:{divider:1,function_type:"none",name:"pin_state_7",size:1},7:{divider:1,function_type:"none",name:"pin_state_8",size:1},8:{divider:1,function_type:"none",name:"pin_state_9",size:1},9:{divider:1,function_type:"none",name:"pin_state_10",size:1}}},80:{6:{0:{divider:1e3,function_type:"none",name:"power_modes",size:2},1:{divider:1e3,function_type:"none",name:"current_power_source",size:2},2:{divider:1e3,function_type:"none",name:"constant_power",size:2},3:{divider:1e3,function_type:"none",name:"rechargeable_battery",size:2},4:{divider:1e3,function_type:"none",name:"disposable_battery",size:2},5:{divider:1e3,function_type:"none",name:"solar_harvesting",size:2},6:{divider:1e3,function_type:"none",name:"TIC_harvesting",size:2}}}};function o(e,t){return 2===t&&(32768&e)>0&&(e-=65536),3===t&&(8388608&e)>0&&(e-=16777216),4===t&&(2147483648&e)>0&&(e-=4294967296),e}function l(e){let t=2147483648&e?-1:1,a=(e>>23&255)-127,i=8388607&e;if(128===a)return t*(i?Number.NaN:Number.POSITIVE_INFINITY);if(-127===a){if(0===i)return 0;a=-126,i/=1<<23}else i=(i|1<<23)/(1<<23);return t*i*Math.pow(2,a)}function _(e,t,a,i){void 0===i&&(i=!1);let r,n,o="U"!=a.substr(0,1),d=parseInt(a.substr(1,2),10)/8,l=d;for(i?(r=-1,n=t+d-1):r=1,n=t,tmpInt64=0,j=n;l>0;j+=r,l--)tmpInt64=(tmpInt64<<8)+e[j];return o&&d<8&&128&e[n]&&(tmpInt64-=1<<8*d),tmpInt64}function u(e,t){let a=e.toString(16).toUpperCase();for(t=null==t?t=2:t;a.length=128?(v=p(256*i[d+6+e*E+S]+i[d+7+e*E+S]),v=parseInt(v,2),h=p(256*i[d+8+e*E+S]+i[d+9+e*E+S]),h=parseInt(h,2),S+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+v+", occurences_down: "+h+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+P+"}";else{let t=i[d+e*E+1+S],_=r[m][g][t].name;"none"===u?(a=((256*i[d+2+e*E+S]+i[d+3+e*E+S])/s).toString(),c=((256*i[d+4+e*E+S]+i[d+5+e*E+S])/s).toString()):"int"===u?(a=o((256*i[d+2+e*E+S]+i[d+3+e*E+S])/s).toString(),c=o((256*i[d+4+e*E+S]+i[d+5+e*E+S])/s).toString()):"float"===u&&(a=l((256*i[d+2+e*E+S]+i[d+3+e*E+S])/s).toString(),c=l((256*i[d+4+e*E+S]+i[d+5+e*E+S])/s).toString()),P=p(i[d+6+e*E+S]),P=parseInt(P,2),P>=128?(v=p(256*i[d+7+e*E+S]+i[d+8+e*E+S]),v=parseInt(v,2),h=p(256*i[d+9+e*E+S]+i[d+10+e*E+S]),h=parseInt(h,2),S+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+v+", occurences_down: "+h+", field: "+_+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+P+", field: "+_+"}"}t.push(n)}if("0"===_[3]&&"1"===_[4]){e-=3;let a="",n="";if(0===b)"none"===u?a=((256*i[d+1+e*E+S]+i[d+2+e*E+S])/s).toString():"int"===u?a=o((256*i[d+1+e*E+S]+i[d+2+e*E+S])/s).toString():"float"===u&&(a=l((256*i[d+1+e*E+S]+i[d+2+e*E+S])/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+"}";else{let t=i[d+e*E+1+S],_=r[m][g][t].name;"none"===u?a=((256*i[d+2+e*E+S]+i[d+3+e*E+S])/s).toString():"int"===u?a=o((256*i[d+2+e*E+S]+i[d+3+e*E+S])/s).toString():"float"===u&&(a=l((256*i[d+2+e*E+S]+i[d+3+e*E+S])/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+", field: "+_+"}"}t.push(n)}if(E+=1,P=0,h=0,v=0,z=i[d+e*E+S],void 0===z){n.zclheader.alarmmsg=t,a=1;break}}}(a,n,d,s,_,u,m,b,v,h,e,t):4===S?function(e,t,a,i,n,d,s,_,u,c,m,g){let E=0,P=0,v=0,h=0,S=0,b=0;1===c&&(e+=1,b=1),void 0===u&&(u="single"===_?"float":"int8"===_||"int16"===_||"int32"===_?"int":"none");let z=i[d+e*E];for(void 0===z&&(n.zclheader.alarmmsg=t,a=1);0===a;){if(1===c){let t=i[d+e*E+1+P];s=r[m][g][t].divider,u=r[m][g][t].function_type}let _=p(z),A=4*f(_[5])+2*f(_[6])+f(_[7]),y=!0;if("0"===_[0]&&(y=!1),"1"===_[3]&&"0"===_[4]){let a="",n="",c="",f="";if(f="1"===_[1]?"exceed":"fall",0===b)"none"===u?(a=((256*i[d+1+e*E+P]*256*256+256*i[d+2+e*E+P]*256+256*i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString(),c=((256*i[d+5+e*E+P]*256*256+256*i[d+6+e*E+P]*256+256*i[d+7+e*E+P]+i[d+8+e*E+P])/s).toString()):"int"===u?(a=o((256*i[d+1+e*E+P]*256*256+256*i[d+2+e*E+P]*256+256*i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString(),c=o((256*i[d+5+e*E+P]*256*256+256*i[d+6+e*E+P]*256+256*i[d+7+e*E+P]+i[d+8+e*E+P])/s).toString()):"float"===u&&(a=l((256*i[d+1+e*E+P]*256*256+256*i[d+2+e*E+P]*256+256*i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString(),c=l((256*i[d+5+e*E+P]*256*256+256*i[d+6+e*E+P]*256+256*i[d+7+e*E+P]+i[d+8+e*E+P])/s).toString()),v=p(i[d+9+e*E+P]),v=parseInt(v,2),v>=128?(h=p(256*i[d+10+e*E+P]+i[d+11+e*E+P]),h=parseInt(h,2),S=p(256*i[d+12+e*E+P]+i[d+13+e*E+P]),S=parseInt(S,2),P+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+h+", occurences_down: "+S+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+v+"}";else{let t=i[d+e*E+1],_=r[m][g][t].name;"none"===u?(a=((256*i[d+2+e*E+P]*256*256+256*i[d+3+e*E+P]*256+256*i[d+4+e*E+P]+i[d+5+e*E+P])/s).toString(),c=((256*i[d+6+e*E+P]*256*256+256*i[d+7+e*E+P]*256+256*i[d+8+e*E+P]+i[d+9+e*E+P])/s).toString()):"int"===u?(a=o((256*i[d+2+e*E+P]*256*256+256*i[d+3+e*E+P]*256+256*i[d+4+e*E+P]+i[d+5+e*E+P])/s).toString(),c=o((256*i[d+6+e*E+P]*256*256+256*i[d+7+e*E+P]*256+256*i[d+8+e*E+P]+i[d+9+e*E+P])/s).toString()):"float"===u&&(a=l((256*i[d+2+e*E+P]*256*256+256*i[d+3+e*E+P]*256+256*i[d+4+e*E+P]+i[d+5+e*E+P])/s).toString(),c=l((256*i[d+6+e*E+P]*256*256+256*i[d+7+e*E+P]*256+256*i[d+8+e*E+P]+i[d+9+e*E+P])/s).toString()),v=p(i[d+10+e*E+P]),v=parseInt(v,2),v>=128?(h=p(256*i[d+11+e*E+P]+i[d+12+e*E+P]),h=parseInt(h,2),S=p(256*i[d+13+e*E+P]+i[d+14+e*E+P]),S=parseInt(S,2),P+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+h+", occurences_down: "+S+", field: "+_+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+v+", field: "+_+"}"}t.push(n)}if("0"===_[3]&&"1"===_[4]){e-=3;let a="",n="";if(0===b)"none"===u?a=((256*i[d+1+e*E+P]*256*256+256*i[d+2+e*E+P]*256+256*i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString():"int"===u?a=o((256*i[d+1+e*E+P]*256*256+256*i[d+2+e*E+P]*256+256*i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString():"float"===u&&(a=l((256*i[d+1+e*E+P]*256*256+256*i[d+2+e*E+P]*256+256*i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+"}";else{let t=i[d+e*E+1],_=r[m][g][t].name;"none"===u?a=((256*i[d+2+e*E+P]*256*256+256*i[d+3+e*E+P]*256+256*i[d+4+e*E+P]+i[d+5+e*E+P])/s).toString():"int"===u?a=o((256*i[d+2+e*E+P]*256*256+256*i[d+3+e*E+P]*256+256*i[d+4+e*E+P]+i[d+5+e*E+P])/s).toString():"float"===u&&(a=l((256*i[d+2+e*E+P]*256*256+256*i[d+3+e*E+P]*256+256*i[d+4+e*E+P]+i[d+5+e*E+P])/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+", field: "+_+"}"}t.push(n)}if(E+=1,v=0,S=0,h=0,z=i[d+e*E+P],void 0===z){n.zclheader.alarmmsg=t,a=1;break}}}(a,n,d,s,_,u,m,b,v,h,e,t):1===S?function(e,t,a,i,n,d,s,_,u,c,m,g){let E=0,P=0,v=0,h=0,S=0,b=0;1===c&&(e+=1,b=1),void 0===u&&(u="single"===_?"float":"int8"===_||"int16"===_||"int32"===_?"int":"none");let z=i[d+e*E];for(void 0===z&&(n.zclheader.alarmmsg=t,a=1);0===a;){if(1===c){let t=i[d+e*E+1+P];s=r[m][g][t].divider,u=r[m][g][t].function_type}let _=p(z),A=4*f(_[5])+2*f(_[6])+f(_[7]),y=!0;if("0"===_[0]&&(y=!1),"1"===_[3]&&"0"===_[4]){let a="",n="",c="",f="";if(f="1"===_[1]?"exceed":"fall",0===b)"none"===u?(a=(i[d+1+e*E+P]/s).toString(),c=(i[d+2+e*E+P]/s).toString()):"int"===u?(a=o(i[d+1+e*E+P]/s).toString(),c=o(i[d+2+e*E+P]/s).toString()):"float"===u&&(a=l(i[d+1+e*E+P]/s).toString(),c=l(i[d+2+e*E+P]/s).toString()),v=p(i[d+3+e*E+P]),v=parseInt(v,2),v>=128?(h=p(256*i[d+4+e*E+P]+i[d+5+e*E+P]),h=parseInt(h,2),S=p(256*i[d+6+e*E+P]+i[d+7+e*E+P]),S=parseInt(S,2),P+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+h+", occurences_down: "+S+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+v+"}";else{let t=i[d+e*E+1+P],_=r[m][g][t].name;"none"===u?(a=(i[d+2+e*E+P]/s).toString(),c=(i[d+3+e*E+P]/s).toString()):"int"===u?(a=o(i[d+2+e*E+P]/s).toString(),c=o(i[d+3+e*E+P]/s).toString()):"float"===u&&(a=l(i[d+2+e*E+P]/s).toString(),c=l(i[d+3+e*E+P]/s).toString()),v=p(i[d+4+e*E+P]),v=parseInt(v,2),v>=128?(h=p(256*i[d+5+e*E+P]+i[d+6+e*E+P]),h=parseInt(h,2),S=p(256*i[d+7+e*E+P]+i[d+8+e*E+P]),S=parseInt(S,2),P+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+h+", occurences_down: "+S+", field: "+_+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+v+", field: "+_+"}"}t.push(n)}if("0"===_[3]&&"1"===_[4]){e-=3;let a="",n="";if(0===b)"none"===u?a=(i[d+1+e*E+P]/s).toString():"int"===u?a=o(i[d+1+e*E+P]/s).toString():"float"===u&&(a=l(i[d+1+e*E+P]/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+"}";else{let t=i[d+e*E+1+P],_=r[m][g][t].name;"none"===u?a=(i[d+2+e*E+P]/s).toString():"int"===u?a=o(i[d+2+e*E+P]/s).toString():"float"===u&&(a=l(i[d+2+e*E+P]/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+", field: "+_+"}"}t.push(n)}if(E+=1,v=0,S=0,h=0,z=i[d+e*E+P],void 0===z){n.zclheader.alarmmsg=t,a=1;break}}}(a,n,d,s,_,u,m,b,v,h,e,t):3===S&&function(e,t,a,i,n,d,s,_,u,c,m,g){let E=0,P=0,v=0,h=0,S=0,b=0;1===c&&(e+=1,b=1),void 0===u&&(u="single"===_?"float":"int8"===_||"int16"===_||"int32"===_?"int":"none");let z=i[d+e*E];for(void 0===z&&(n.zclheader.alarmmsg=t,a=1);0===a;){if(1===c){let t=i[d+e*E+1+P];s=r[m][g][t].divider,u=r[m][g][t].function_type}let _=p(z),A=4*f(_[5])+2*f(_[6])+f(_[7]),y=!0;if("0"===_[0]&&(y=!1),"1"===_[3]&&"0"===_[4]){let a="",n="",c="",f="";if(f="1"===_[1]?"exceed":"fall",0===b)"none"===u?(a=((256*i[d+1+e*E+P]+i[d+2+e*E+P]+i[d+3+e*E+P])/s).toString(),c=((256*i[d+4+e*E+P]+i[d+5+e*E+P]+i[d+6+e*E+P])/s).toString()):"int"===u?(a=o((256*i[d+1+e*E+P]+i[d+2+e*E+P]+i[d+3+e*E+P])/s).toString(),c=o((256*i[d+4+e*E+P]+i[d+5+e*E+P]+i[d+6+e*E+P])/s).toString()):"float"===u&&(a=l((256*i[d+1+e*E+P]+i[d+2+e*E+P]+i[d+3+e*E+P])/s).toString(),c=l((256*i[d+4+e*E+P]+i[d+5+e*E+P]+i[d+6+e*E+P])/s).toString()),v=p(i[d+7+e*E+P]),v=parseInt(v,2),v>=128?(h=p(256*i[d+8+e*E+P]+i[d+9+e*E+P]),h=parseInt(h,2),S=p(256*i[d+10+e*E+P]+i[d+11+e*E+P]),S=parseInt(S,2),P+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+h+", occurences_down: "+S+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+v+"}";else{let t=i[d+e*E+1+P],_=r[m][g][t].name;"none"===u?(a=((256*i[d+2+e*E+P]+i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString(),c=((256*i[d+5+e*E+P]+i[d+6+e*E+P]+i[d+7+e*E+P])/s).toString()):"int"===u?(a=o((256*i[d+2+e*E+P]+i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString(),c=o((256*i[d+5+e*E+P]+i[d+6+e*E+P]+i[d+7+e*E+P])/s).toString()):"float"===u&&(a=l((256*i[d+2+e*E+P]+i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString(),c=l((256*i[d+5+e*E+P]+i[d+6+e*E+P]+i[d+7+e*E+P])/s).toString()),v=p(i[d+8+e*E+P]),v=parseInt(v,2),v>=128?(h=p(256*i[d+9+e*E+P]+i[d+10+e*E+P]),h=parseInt(h,2),S=p(256*i[d+11+e*E+P]+i[d+12+e*E+P]),S=parseInt(S,2),P+=4,n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences_up: "+h+", occurences_down: "+S+", field: "+_+"}"):n="cause:{alarm:"+y+", criterion_index: "+A+", mode: threshold, crossing: "+f+", value: "+a+", gap: "+c+", occurences: "+v+", field: "+_+"}"}t.push(n)}if("0"===_[3]&&"1"===_[4]){e-=3;let a="",n="";if(0===b)"none"===u?a=((256*i[d+1+e*E+P]*256+256*i[d+2+e*E+P]+i[d+3+e*E+P])/s).toString():"int"===u?a=o((256*i[d+1+e*E+P]+i[d+2+e*E+P]+i[d+3+e*E+P])/s).toString():"float"===u&&(a=l((256*i[d+1+e*E+P]+i[d+2+e*E+P]+i[d+3+e*E+P])/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+"}";else{let t=i[d+e*E+1],_=r[m][g][t].name;"none"===u?a=((256*i[d+2+e*E+P]+i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString():"int"===u?a=o((256*i[d+2+e*E+P]+i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString():"float"===u&&(a=l((256*i[d+2+e*E+P]+i[d+3+e*E+P]+i[d+4+e*E+P])/s).toString()),n="cause:{alarm:"+y+", criterion_index: "+A+", mode: delta, value: "+a+", field: "+_+"}"}t.push(n)}if(E+=1,v=0,S=0,h=0,z=i[d+e*E+P],void 0===z){n.zclheader.alarmmsg=t,a=1;break}}}(a,n,d,s,_,u,m,b,v,h,e,t)}function P(e){let t="";for(let a=0;a>5|(6&t[0])<<2,v=t[1],r.zclheader.cmdID=u(v,2),z=256*t[2]+t[3],r.zclheader.clustID=u(z,4),10===v|138===v|1===v){f=1,r.data={},i=256*t[4]+t[5],r.zclheader.attID=u(i,4);let A=t[4],H=0;if(10!==v&&138!==v||(H=7),138===v&&(r.zclheader.alarm=1),1===v&&(H=8,r.zclheader.status=t[6]),83!==z&&84!==z&&85!==z&&86!==z&&87!==z||(r.data=function(t,a,i){const r=["!?!","*",""," ACTIF","ACTIF","CONSO","CONTROLE","DEP","INACTIF","PROD","TEST","kVA","kW"],o=["!?!","*",""," ? ","000","HC","HCD","HCE","HCH","HH","HH ","HP","HP ","HPD","HPE","HPH","JA","JA ","P","P ","PM","PM ","XXX"],l=["!?!","*","","BT 4 SUP36","BT 5 SUP36","HTA 5 ","HTA 8 ","TJ EJP ","TJ EJP-HH ","TJ EJP-PM ","TJ EJP-SD ","TJ LU ","TJ LU-CH ","TJ LU-P ","TJ LU-PH ","TJ LU-SD ","TJ MU ","TV A5 BASE","TV A8 BASE","BASE","H PLEINE-CREUSE","HPHC","HC","HC et Week-End","EJP","PRODUCTEUR"],u=["!?!","*",""," ? ","000","HC","HCD","HCE","HCH","HH","HH ","HP","HP ","HPD","HPE","HPH","JA","JA ","P","P ","PM","PM ","XXX","INDEX NON CONSO","BASE","HEURE CREUSE","HEURE PLEINE","HEURE NORMALE","HEURE POINTE","HC BLEU","BUHC","HP BLEU","BUHP","HC BLANC","BCHC","HP BLANC","BCHP","HC ROUGE","RHC","HP ROUGE","RHP","HEURE WEEK-END"],p=["!?!","*","","BT 4 SUP36","BT 5 SUP36","HTA 5 ","HTA 8 ","TJ EJP ","TJ EJP-HH ","TJ EJP-PM ","TJ EJP-SD ","TJ LU ","TJ LU-CH ","TJ LU-P ","TJ LU-PH ","TJ LU-SD ","TJ MU ","TV A5 BASE","TV A8 BASE","BASE","H PLEINE-CREUSE","HPHC","HC","HC et Week-End","EJP","PRODUCTEUR"];function f(e,t,a){var i={};return 0==(128&e[t])?(iEnum=127&e[t],iEnum++,i=a[iEnum],t+=1):(sz=127&e[t],t+=1,sz>0?(i=String.fromCharCode.apply(null,e.slice(t,t+sz)),t+=sz):i=""),{x:i,i:t}}function g(e,t){return{x:ze=c(_(e,t,"U8"),2)+"/"+c(_(e,t+1,"U8"),2)+"/"+c(_(e,t+2,"U8"),2)+" "+c(_(e,t+3,"U8"),2)+":"+c(_(e,t+4,"U8"),2)+":"+c(_(e,t+5,"U8"),2),i:t+=6}}function E(e,t,a){ts=_(e,t,"U32",a),t+=4,ts+=new Date("2000/01/01 00:00:00").getTime()/1e3,ts+=3600;var i=new Date(1e3*ts);return{x:c(i.getDate(),2)+"/"+c(i.getMonth(),2)+"/"+i.getFullYear()+" "+c(i.getHours(),2)+":"+c(i.getMinutes(),2)+":"+c(i.getSeconds(),2),i:t}}function v(e,t,a){return{x:ze=String.fromCharCode.apply(null,e.slice(t,t+a)),i:t+=a}}function S(e,t){return{b:e,i:t}}function z(e,t){return function(e,t){return eos=e.slice(t).indexOf(0),ze=String.fromCharCode.apply(null,e.slice(t,t+eos)),t+=eos+1,{x:ze,i:t}}(e,t)}function A(e,t){return{x:ze=_(e,t,"U8"),i:t+=1}}function H(e,t){return{x:ze=_(e,t,"U16"),i:t+=2}}function C(e,t){return{x:ze=_(e,t,"I16"),i:t+=2}}function I(e,t){return{x:ze=_(e,t,"U24"),i:t+=3}}function T(e,t){var a={};for(t=1;t<=4;t++)a["Value_"+t]=_(e,t,"U24"),t+=3;return{x:a,i:t}}function N(e,t){return{x:ze=_(e,t,"U32"),i:t+=4}}function R(e,t){return{x:ze=BytesToFloat32(e,t),i:t+=4}}function U(e,t){return g(e,t)}function x(e,t){return E(e,t)}function w(e,t){return f(e,t,o)}function F(e,t){return{x:{},i:t=f(e,E(e,t).i,o).i}}function O(e,t){return D=c(_(e,t,"U8"),2),t++,M=c(_(e,t,"U8"),2),t++,h=c(_(e,t,"U8"),2),t++,{x:D+"/"+M+" "+h,i:t}}function J(e,t){var a={};return s=v(e,t,1),d=g(e,s.i),n=_(e,t,"U8"),t=d.i+1,a.S=s.x,a.Date=d.x,a.Value=n,{x:a,i:t}}function B(e,t){var a={};return s=v(e,t,1),d=g(e,s.i),n=_(e,t,"U16"),t=d.i+1,a.S=s.x,a.Date=d.x,a.Value=n,{x:a,i:t}}function V(e,t){var a={};return s=v(e,t,1),d=g(e,s.i),n=_(e,t,"U24"),t=d.i+1,a.S=s.x,a.Date=d.x,a.Value=n,{x:a,i:t}}function X(e,t){return f(e,t,r)}function G(t,a){var i={};return dd=_(t,a,"U24"),a+=3,i.Value=dd,e=f(t,a,r),i.Label=e.x,{x:i,i:a=e.i}}function q(e,t){return f(e,t,l)}function k(e,t){for(var a=[],i=0;i<11;i++)y={},h=c(_(e,t,"U8"),2),t++,255==h?y.Status="NONUTILE":(m=c(_(e,t,"U8"),2),t++,s=P(e.slice(t,2)),t++,y.Time=h+":"+m,y.Status=s,t+=e[t]+1),a.push(y);return{x:a,i:t}}function L(e){return e}function Y(e){return e}function W(e){return e}function j(e){return e}function Z(e){return e}function Q(e){return e}function K(e){return e}function $(e){return e}function ee(e){return e}function te(e){return e}function ae(e){return e}function ie(e){return e}function re(e){return e}function ne(e){return e}function oe(e){return e}function de(e){return e}function le(e){return e}function se(e){return e}function _e(e){return e}function ue(e){return e}function ce(e){return e}const pe=[["CONTRAT",z,0,Y],["DATECOUR",U,0,L],["DATE",U,0,L],["EA",I,0,function(e){return e}],["ERP",I,0,function(e){return e}],["PTCOUR",z,0,Y],["PREAVIS",z,0,Y],["MODE",S,0,Y],["DATEPA1",U,0,L],["PA1",H,0,ie],["DATEPA2",U,0,L],["PA2",H,0,ie],["DATEPA3",U,0,L],["PA3",H,0,ie],["DATEPA4",U,0,L],["PA4",H,0,ie],["DATEPA5",U,0,L],["PA5",H,0,ie],["DATEPA6",U,0,L],["PA6",H,0,ie],["*p*",I,0,K],["KDC",A,0,ae],["KDCD",A,0,ae],["TGPHI",R,0,ce],["PSP",H,0,ie],["PSPM",H,0,ie],["PSHPH",H,0,ie],["PSHPD",H,0,ie],["PSHCH",H,0,ie],["PSHCD",H,0,ie],["PSHPE",H,0,ie],["PSHCE",H,0,ie],["PSJA",H,0,ie],["PSHH",H,0,ie],["PSHD",H,0,ie],["PSHM",H,0,ie],["PSDSM",H,0,ie],["PSSCM",H,0,ie],["MODE",S,0,Y],["PA1MN",H,0,ie],["PA10MN",H,0,ie],["PREA1MN",C,0,re],["PREA10MN",C,0,re],["TGPHI",R,0,ce],["U10MN",H,0,function(e){return e}]],me=[["DEBUTp",U,0,L,0],["FINp",U,0,L,6],["CAFp",H,0,Q,12],["DATEEAp",U,0,L,14],["EApP",I,0,se,20],["EApPM",I,0,se,23],["EApHCE",I,0,se,26],["EApHCH",I,0,se,29],["EApHH",I,0,se,32],["EApHCD",I,0,se,35],["EApHD",I,0,se,38],["EApJA",I,0,se,41],["EApHPE",I,0,se,44],["EApHPH",I,0,se,47],["EApHPD",I,0,se,50],["EApSCM",I,0,se,53],["EApHM",I,0,se,56],["EApDSM",I,0,se,59],["DATEERPp",U,0,L,62],["ERPpP",I,0,ue,68],["ERPpPM",I,0,ue,71],["ERPpHCE",I,0,ue,74],["ERPpHCH",I,0,ue,77],["ERPpHH",I,0,ue,80],["ERPpHCD",I,0,ue,83],["ERPpHD",I,0,ue,86],["ERPpJA",I,0,ue,89],["ERPpHPE",I,0,ue,92],["ERPpHPH",I,0,ue,95],["ERPpHPD",I,0,ue,98],["ERPpSCM",I,0,ue,101],["ERPpHM",I,0,ue,104],["ERPpDSM",I,0,ue,107],["DATEERNp",U,0,L,110],["ERNpP",I,0,ue,116],["ERNpPM",I,0,ue,119],["ERNpHCE",I,0,ue,122],["ERNpHCH",I,0,ue,125],["ERNpHH",I,0,ue,128],["ERNpHCD",I,0,ue,131],["ERNpHD",I,0,ue,134],["ERNpJA",I,0,ue,137],["ERNpHPE",I,0,ue,140],["ERNpHPH",I,0,ue,143],["ERNpHPD",I,0,ue,146],["ERNpSCM",I,0,ue,149],["ERNpHM",I,0,ue,152],["ERNpDSM",I,0,ue,155]],fe=[["DEBUTp1",U,0,L,0],["FINp1",U,0,L,6],["CAFp1",H,0,Q,12],["DATEEAp1",U,0,L,14],["EAp1P",I,0,se,20],["EAp1PM",I,0,se,23],["EAp1HCE",I,0,se,26],["EAp1HCH",I,0,se,29],["EAp1HH",I,0,se,32],["EAp1HCD",I,0,se,35],["EAp1HD",I,0,se,38],["EAp1JA",I,0,se,41],["EAp1HPE",I,0,se,44],["EAp1HPH",I,0,se,47],["EAp1HPD",I,0,se,50],["EAp1SCM",I,0,se,53],["EAp1HM",I,0,se,56],["EAp1DSM",I,0,se,59],["DATEERPp1",U,0,L,62],["ERPp1P",I,0,ue,68],["ERPp1PM",I,0,ue,71],["ERPp1HCE",I,0,ue,74],["ERPp1HCH",I,0,ue,77],["ERPp1HH",I,0,ue,80],["ERPp1HCD",I,0,ue,83],["ERPp1HD",I,0,ue,86],["ERPp1JA",I,0,ue,89],["ERPp1HPE",I,0,ue,92],["ERPp1HPH",I,0,ue,95],["ERPp1HPD",I,0,ue,98],["ERPp1SCM",I,0,ue,101],["ERPp1HM",I,0,ue,104],["ERPp1DSM",I,0,ue,107],["DATEERNp1",U,0,L,110],["ERNp1P",I,0,ue,116],["ERNp1PM",I,0,ue,119],["ERNp1HCE",I,0,ue,122],["ERNp1HCH",I,0,ue,125],["ERNp1HH",I,0,ue,128],["ERNp1HCD",I,0,ue,131],["ERNp1HD",I,0,ue,134],["ERNp1JA",I,0,ue,137],["ERNp1HPE",I,0,ue,140],["ERNp1HPH",I,0,ue,143],["ERNp1HPD",I,0,ue,146],["ERNp1SCM",I,0,ue,149],["ERNp1HM",I,0,ue,152],["ERNp1DSM",I,0,ue,155]],ge=[["ADIR1",H,0,Z],["ADIR2",H,0,Z],["ADIR3",H,0,Z],["ADCO",z,0,Y],["OPTARIF",z,0,Y],["ISOUSC",A,0,j],["BASE",N,0,te],["HCHC",N,0,te],["HCHP",N,0,te],["EJPHN",N,0,te],["EJPHPM",N,0,te],["BBRHCJB",N,0,te],["BBRHPJB",N,0,te],["BBRHCJW",N,0,te],["BBRHPJW",N,0,te],["BBRHCJR",N,0,te],["BBRHPJR",N,0,te],["PEJP",A,0,j],["GAZ",N,0,ee],["AUTRE",N,0,ee],["PTEC",z,0,Y],["DEMAIN",z,0,Y],["IINST",H,0,Z],["IINST1",H,0,Z],["IINST2",H,0,Z],["IINST3",H,0,Z],["ADPS",H,0,Z],["IMAX",H,0,Z],["IMAX1",H,0,Z],["IMAX2",H,0,Z],["IMAX3",H,0,Z],["PMAX",N,0,K],["PAPP",N,0,K],["HHPHC",function(e,t){return{x:ze=String.fromCharCode.apply(null,e.slice(0,1)),i:t+=1}},0,function(e){return e}],["MOTDETAT",z,0,Y],["PPOT",A,0,function(e){return e}]],Ee=[["JAUNE",function(e,t){return h=c(_(e,t,"U8"),2),t++,m=c(_(e,t,"U8"),2),t++,D=c(_(e,t,"U8"),2),t++,M=c(_(e,t,"U8"),2),t++,{x:D+"/"+M+" "+h+":"+m,i:t}},0,L],["JAUNE",z,0,Y],["JAUNE",z,0,Y],["JAUNE",I,0,K],["JAUNE",A,0,j],["ENERG",function(e,t){var a={};for(t=1;t<=4;t++)a["Value_"+t]=_(e,t,"U24"),t+=3;return{x:a,i:t}},0,$],["ENERG",I,0,$],["ENERG",I,0,$],["ENERG",I,0,$],["ENERG",I,0,$],["ENERG",I,0,$],["PERCC",O,0,L],["PERCC",A,0,j],["PMAXC",T,0,K],["PMAXC",I,0,K],["PMAXC",I,0,K],["PMAXC",I,0,K],["TDEPA",T,0,K],["TDEPA",I,0,K],["TDEPA",I,0,K],["TDEPA",I,0,K],["PERCP",O,0,L],["PERCP",A,0,j],["PMAXP",T,0,K],["PMAXP",I,0,K],["PMAXP",I,0,K],["PMAXP",I,0,K],["PSOUSC",T,0,K],["PSOUSC",I,0,K],["PSOUSC",I,0,K],["PSOUSC",I,0,K],["PSOUSP",T,0,K],["PSOUSP",I,0,K],["PSOUSP",I,0,K],["PSOUSP",I,0,K],["FCOU",function(e,t){return h=c(_(e,t,"U8"),2),t++,m=c(_(e,t,"U8"),2),t++,{x:h+":"+m,i:t}},0,L],["FCOU",A,0,j]],Pe=[["ADSC",z,0,Y],["VTIC",A,0,j],["DATE",function(e,t){var a={};return s=v(e,t,1),d=g(e,s.i),a.S=s.x,a.Date=d.x,{x:a,i:t=d.i}},0,L],["NGTF",function(e,t){return f(e,t,p)},0,Y],["LTARF",function(e,t){return f(e,t,u)},0,Y],["EAST",N,0,te],["EASF01",N,0,te],["EASF02",N,0,te],["EASF03",N,0,te],["EASF04",N,0,te],["EASF05",N,0,te],["EASF06",N,0,te],["EASF07",N,0,te],["EASF08",N,0,te],["EASF09",N,0,te],["EASF10",N,0,te],["EASD01",N,0,te],["EASD02",N,0,te],["EASD03",N,0,te],["EASD04",N,0,te],["EAIT",N,0,te],["ERQ1",N,0,te],["ERQ2",N,0,te],["ERQ3",N,0,te],["ERQ4",N,0,te],["IRMS1",H,0,Z],["IRMS2",H,0,Z],["IRMS3",H,0,Z],["URMS1",H,0,Z],["URMS2",H,0,Z],["URMS3",H,0,Z],["PREF",A,0,j],["PCOUP",A,0,j],["SINSTS",I,0,K],["SINSTS1",I,0,K],["SINSTS2",I,0,K],["SINSTS3",I,0,K],["SMAXSN",V,0,K],["SMAXSN1",V,0,K],["SMAXSN2",V,0,K],["SMAXSN3",V,0,K],["SMAXSN?1",V,0,K],["SMAXSN1?1",V,0,K],["SMAXSN2?1",V,0,K],["SMAXSN3?1",V,0,K],["SINSTI",I,0,K],["SMAXIN",V,0,K],["SMAXIN-1",V,0,K],["CCASN",V,0,K],["CCASN?1",V,0,K],["CCAIN",V,0,K],["CCAIN?1",V,0,K],["UMOY1",B,0,Z],["UMOY2",B,0,Z],["UMOY3",B,0,Z],["STGE",function(e,t){var a=P(e.slice(t,2));return t+=4,{x:a,i:t+=4}},0,L],["DPM1",J,0,j],["FPM1",J,0,j],["DPM2",J,0,j],["FPM2",J,0,j],["DPM3",J,0,j],["FPM3",J,0,j],["MSG1",z,0,Y],["MSG2",z,0,Y],["PRM",z,0,Y],["RELAIS",function(e,t){return ze=_(e,t,"U8"),t++,{x:ze,i:t}},0,Z],["NTARF",A,0,j],["NJOURF",A,0,j],["NJOURF+1",A,0,j],["PJOURF+1",k,0,L],["PPOINTE",k,0,L]],ve=[["TRAME",X,0,Y],["ADS",function(e,t){var a=P(e.slice(t+1,t+1+e[t]));return t+=e[t]+1,d={x:a,i:t},{x:a,i:t}},0,L],["MESURES1",q,0,Y],["DATE",U,0,L],["EA_s",I,0,ne],["ER+_s",I,0,oe],["ER-_s",I,0,oe],["EAPP_s",I,0,de],["EA_i",I,0,ne],["ER+_i",I,0,oe],["ER-_i",I,0,oe],["EAPP_i",I,0,de],["PTCOUR1",w,0,Y],["TARIFDYN",X,0,Y],["ETATDYN1",w,0,Y],["PREAVIS1",w,0,W],["TDYN1CD",F,0,L],["TDYN1CF",F,0,L],["TDYN1FD",F,0,L],["TDYN1FF",F,0,L],["MODE",X,0,Y],["CONFIG",X,0,Y],["DATEPA1",U,0,L],["PA1_s",H,0,ie],["PA1_i",H,0,ie],["DATEPA2",x,0,L],["PA2_s",H,0,ie],["PA2_i",H,0,ie],["DATEPA3",x,0,L],["PA3_s",H,0,ie],["PA3_i",H,0,ie],["DATEPA4",x,0,L],["PA4_s",H,0,ie],["PA4_i",H,0,ie],["DATEPA5",x,0,L],["PA5_s",H,0,ie],["PA5_i",H,0,ie],["DATEPA6",x,0,L],["PA6_s",H,0,ie],["PA6_i",H,0,ie],["DebP",x,0,L],["EAP_s",I,0,le],["EAP_i",I,0,le],["ER+P_s",I,0,_e],["ER-P_s",I,0,_e],["ER+P_i",I,0,_e],["ER-P_i",I,0,_e],["DebP-1",x,0,L],["FinP-1",x,0,L],["EaP-1_s",I,0,le],["EaP-1_i",I,0,le],["ER+P-1_s",I,0,_e],["ER-P-1_s",I,0,_e],["ER+P-1_i",I,0,_e],["ER-P-1_i",I,0,_e],["PS",G,0,L],["PREAVIS",X,0,Y],["PA1MN",H,0,ie],["PMAX_s",G,0,L],["PMAX_i",G,0,L],["TGPHI_s",R,0,ce],["TGPHI_i",R,0,ce],["MESURES2",q,0,Y],["PTCOUR2",w,0,Y],["ETATDYN2",w,0,Y],["PREAVIS2",w,0,W],["TDYN2CD",F,0,L],["TDYN2CF",F,0,L],["TDYN2FD",F,0,L],["TDYN2FF",F,0,L],["DebP_2",x,0,L],["EaP_s2",I,0,le],["DebP-1_2",x,0,L],["FinP-1_2",x,0,L],["EaP-1_s2",I,0,le],["_DDMES1_",I,0,function(e){return e}]];if(data=[],83==t)if(!1&attributeID)profil=pe,data._TICFrameType="ICE Generale";else if(!1&attributeID)profil=me,data._TICFrameType="ICE Periode P";else{if(!(!1&attributeID))return data;profil=fe,data._TICFrameType="ICE Periode P moins 1"}else if(84==t)profil=ge,data._TICFrameType="CBE/Historique";else if(85==t)profil=Ee,data._TICFrameType="CJE";else if(86==t)profil=Pe,data._TICFrameType="Standard";else{if(87!=t)return data;profil=ve,data._TICFrameType="PMEPMI"}let{DescSize:he,Indexes:Se}=function(e){var t=[],a=e[0],i=31&a;if(0==i&&(i=8),IsVarIndexes=0!=(32&a),IsVarIndexes)for(r=1;r1;r--)for(b=0;b<8;b++)e[r-1]>>b&1&&t.push(iField),iField++}return{DescSize:i,Indexes:t}}(i);var be=i.slice(0,he),ze={};128==(128&be[0])&&(ze.Obsolete=!0),ze.Bytes=P(be),ze.Indexes=Se,data._Descriptor=ze;for(var Ae=he,ye=0;ye>5,r.data.modbus_last_frame_of_serie=(28&e)>>2,r.data.modbus_EP9=1==(1&e),r.data.modbus_EP8=2==(2&e),r.data.modbus_EP7=128==(128&a),r.data.modbus_EP6=64==(64&a),r.data.modbus_EP5=32==(32&a),r.data.modbus_EP4=16==(16&a),r.data.modbus_EP3=8==(8&a),r.data.modbus_EP2=4==(4&a),r.data.modbus_EP1=2==(2&a),r.data.modbus_EP0=1==(1&a);let i=H+4;if(without_header=0,!0===r.data.modbus_EP0){if(0===without_header&&(r.data.modbus_slaveID_EP0=t[i],r.data.modbus_fnctID_EP0=t[i+1],r.data.modbus_datasize_EP0=t[i+2],i+=3),r.data.modbus_payload_EP0="",void 0===t[i])return r;for(let e=0;e0;)r.zclheader.modepower=t[14+5*a],r.zclheader.powersource=t[15+5*a],r.zclheader.delta=256*t[16+5*a]+t[17+5*a],r.zclheader.changedpowersource=t[18+5*a],a++,e--}}if(0===f)throw new a("bad payload")}else r.batch={},r.batch.report="batch";return r}t.exports={normalisation_standard:function(e,t){let i=[],r=e.bytes,n=!0,o=0,d=v(r,e.fPort);if(void 0!==d.zclheader){if(void 0!==d.zclheader.alarmmsg&&(i=d.zclheader.alarmmsg),7===r[1])return{data:d.zclheader,warning:i};if(9===r[1])return{data:d.zclheader,warning:i};if(1===r[1]){if(void 0===d.zclheader.data){let t=[];for(;n;){let a=Object.keys(d.data)[o];if(void 0===a){n=!1;break}t.push({variable:a,value:d.data[a],date:e.recvTime}),o++}return{data:t,type:"standard",warning:i}}return{data:{variable:"read reporting configuration response status",value:d.zclheader.data,date:e.recvTime},warning:i}}}if(void 0!==d.zclheader){if(void 0!==t){let a=d.zclheader.endpoint,r=!0,n=0,o=[],l="";for(;r;){let i=Object.keys(d.data)[n];if(void 0===i){r=!1;break}void 0===t[i]?o.push({variable:i,value:d.data[i],date:e.recvTime}):(l=t[i][a],"NA"===l?o.push({variable:l,value:"NA",date:e.recvTime}):o.push({variable:l,value:d.data[i],date:e.recvTime})),n++}return{data:o,type:"standard",warning:i}}throw a("bad decoding")}return{type:d.batch.report,payload:d.lora.payload}}}}},a={};function i(e){var r=a[e];if(void 0!==r)return r.exports;var n=a[e]={exports:{}};return t[e](n,n.exports,i),n.exports}var r={};(()=>{var e=r;let t=i(13),a=[2,[{taglbl:0,resol:10,sampletype:7,lblname:"temperature",divide:100},{taglbl:1,resol:100,sampletype:6,lblname:"humidity",divide:100},{taglbl:2,resol:1,sampletype:6,lblname:"battery_voltage",divide:1e3},{taglbl:3,resol:1,sampletype:1,lblname:"violation_detection",divide:1}]],n={pin_state:["violation_detection"]};e.decodeUplink=function(e){return result=t.watteco_decodeUplink(e,a,n)}})(),driver=r})();
_input = {
"bytes": Buffer.from(msg.payload, 'base64'),
"fPort": msg.fport,
"recvTime": msg.time // The date in ISO 8601 format
}
return driver.decodeUplink(_input);
- Finally "deploy" your NodeRed flow and wait for next input frame from the sensor in the case below the received frame decoded and shown in the Output debugger of nodeRed is a standard Temperature measurement frame. HThis implementation should also work for any other standard frame comming from the TH sensor or, if configured, the default batch configuration.
Please refer to all existing codec distributions depending on the sensor you want to decode.