Gateway TLG3901B/BLV2 Series User Manual
V2.0.4
30
December 2020
The LoRaScript sample code for converting base64 from rxpk to ASCII string is shown in List
4-3, and for sending txpk packet with base64 encoding is provided in List 4-4.
List 4-3 rxpk Data from Base64 to ASCII in LoRaScript
function onLoRaRx(data) {
//convert base64 to ascii encoding
var asciiStr = new Buffer(data, 'base64').toString('ascii');
debug_print("receive " + asciiStr);
}
List 4-4 Construct and Send a txpk Pakcet in LoRaScript
function onInit() {
setInterval(period_send, 1000); // send a txpk in every 1 second
}
function period_send () {
var msg = 'Hello World';
var msg_size = Buffer.byteLength(msg, 'asci');
var base64str = new Buffer(msg).toString('base64');
var json_obj = {
imme:true,
freq:915.5,
rfch:0,
powe:14,
modu:"LORA",
datr:"SF7BW125",
codr:"4/6",
ipol:false,
size:msg_size,
data:base64str
};
send_pkt(JSON.stringify(json_obj));
}
var lora_packet = require('lora-packet');
function onInit() {
debug_print("on init");
}
function onLoRaRx (data) {
debug_print("on Recv data");
var raw = JSON.parse(data);
var lorawan_packet = new Buffer(raw.data, 'base64');
if(lorawan_packet.length>12){