I’m really enjoying chirpstack v4. Great improvement over the older version in terms of installation. The simplification has helped a lot!
Of course, i’m fairly new to this, so i’ll probably have made a simple mistake.
My current codec looks like this:
function decodeUplink(bytes, fport, variables) {
var device = bytes[0];
var msgNr = bytes[1];
var batteryVoltage = (bytes[2]<<8 | bytes[3]);
var distance = 0;
var msgCount = (bytes[4]<<8 | bytes[5]);
var gpsTime = (bytes[6]<<8 | bytes[7]);
var gpsSats = bytes[8];
var gpsFixType = bytes[9];
var gpsLat = (bytes[10] << 24 | bytes[11] << 16 | bytes[12]<<8 | bytes[13]);
var gpsLong = (bytes[14] << 24 | bytes[15] << 16 | bytes[16]<<8 | bytes[17]);
var gpsAltMSL = (bytes[18] << 8 | bytes[19])
return {
data: {
DeviceByte: device,
MsgNr: msgNr,
Voltage: batteryVoltage,
Distance: distance,
MessageCount: msgCount,
GPSTime: gpsTime,
GPSSats: gpsSats,
GPSFixType: gpsFixType,
GPSLat: gpsLat,
GPSLong: gpsLong,
GPSAltitude: gpsAltMSL
}
}
}
The output however is nothing. Of course even DeviceByte should have a value, but it’s null.
I’ve checked the logfiles of chirpstack, but there’s no error there.
the “debugging” in this topic attracted me to find some clues how to make the codecs in more professional way than waiting for a frame and looking into the logs where the error is.
So I will extend the question:
is it possible inside codec function to write some log file (console.log is not possible)?
is it possible to connect to sqlite3 or other (redis?) database?
is it possible to send message via socket or similar IP-based communication?
any other possibilities to throw out data out of codec function code?
Unfortunatelly for someone who is not proficient in JavaScript (like me) it’s not easy to write more elaborated codec, because JavaScript engine version is very old. E.g. Map() is not available (along with plenty of other JavaScript language features). So if I look into JS manuals, I fall down because of not implemented language features.
Although i agree that the codec stuff is not for a rule engine, the current implementation doesn’t really help in debugging the coded javascript itself.
I made a small mistake in the javascript (forgot a ;). Where do errors about that end up? How do i debug that?