Gateway TLG3901B/BLV2 Series User Manual
V2.0.4
40
December 2020
rfch:0,
powe:14,
modu:"LORA",
datr:"SF7BW125",
codr:"4/6",
ipol:false,
size:5,
data:""
};
var beacon_pkt;
function onInit() {
beacon_pkt = new Uint8Array(5);
beacon_pkt[0] = 0x5A; //magic
beacon_pkt[1] = 0x00; //sequence
beacon_pkt[2] = 0x00; //cmd
beacon_pkt[3] = 0x00; //node address
beacon_pkt[4] = 0x00; //data
dgram = require('dgram');
udp_sock = dgram.createSocket('udp4');
cmd_sock = dgram.createSocket('udp4');
cmd_sock.on('listening', function () {
var address = cmd_sock.address();
debug_print('UDP Server listening on ' + address.a ':' +
address.port);
});
cmd_sock.on('message', function (message, remote) {
debug_print(remote.a ':' + remote.port +' - ' + message);
cmd_node_address = message[0];
cmd_node_data = message[1];
update_cmd = true;
});
cmd_sock.bind(cmd_port);
setInterval(beacon, 10000); //broadcast beacon every 10 second
}
function onLoRaRx (data) {
var recv_pkt = JSON.parse(data);
var recv_data = new Buffer(recv_pkt.data, 'base64');
debug_print("Receive packet from freq:" + recv_pkt.freq +
", datarate:" + recv_pkt.datr + ", coderate:" + recv_pkt.codr);