For this (and any IoT action) I would use node red doing something as simple as that
Check this link
Decode function should be something like that
var devID;
var dat;
devID = msg.dev_id;
// Decode data received my nodes are loranode01 or loranode02, ..
if ( devID.match(/loranode\d{2}/) ) {
console.log("Valid devID=%s", devID);
dat = decode_loranode(msg.payload_raw);
console.log("bat=%d temp=%d hum=%d", dat.battery, dat.temperature, dat.humidity);
strSQL = "INSERT INTO weather (NODE, TEMPERATURE, HUMIDITY, BATT, FRAMECOUNT) "
strSQL += "VALUES ( ";
strSQL += dat.devID + ", ";
strSQL += dat.temperature + ", ";
strSQL += dat.humidity + ", ";
strSQL += dat.battery + ", ";
strSQL += dat.fc + ", ";
strSQL += ") ";
console.log("MySQL=%s", strSQL);
msg.payload = strSQL;
return msg
} else {
console.log("Invalid devID=%s", devID);
}
function decode_loranode(data) {
var bytes = new Buffer(data, 'base64');
var battery = (bytes[2] << 8) | bytes[3] ;
var fc = (bytes[6] << 8) | bytes[7] ;
var temperature = ((bytes[10] << 8) | bytes[11]) / 10;
var humidity = bytes[14] / 2;
console.log("batt=%d fc=%d temp=%d hum=%d", battery, fc, temperature, humidity);
return {
battery: battery,
framecount: fc,
humidity: humidity,
temperature: temperature};
}