CubeCell AB02S chirpstack decoder

Hi, I have a CubeCell AB02S working OK using the LoRaWan_OnBoardGPS_Air530Z.ino sketch you have on GitHub and it is successfully uploading the data payload to Chirpstack but I cant get the codec working correctly. The unit is working well in other respects and I like it for our purpose.
I tried the TTN decoder you have in the same repo this decoder wont work on Chirpstack V3x
I have been trying to figure out the payload format but no success so far and I was hoping you can provide either a Chripstack compatible decoder Javascript or at least the order of the bytes in the payload from this sketch.
I am not the best at Javascript and Arduino (usually use micropython) so struggling to decipher the payload for a JavaScript decoder for Chripstack.
Regards
Andrew

That’s just an example, specifically, write it according to your own code.

Hi, Did you get this working in CS?

Many thanks

Hi
This JS codec script works OK for me

// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
//function decodeUplink(input) {
// return {
// data: {
// temp: 22.5
// }
// };
//}
function bytesToFloat(by) {
var bits = by[3]<<24 | by[2]<<16 | by[1]<<8 | by[0];
var sign = (bits>>>31 === 0) ? 1.0 : -1.0;
var e = bits>>>23 & 0xff;
var m = (e === 0) ? (bits & 0x7fffff)<<1 : (bits & 0x7fffff) | 0x800000;
var f = sign * m * Math.pow(2, e - 150);
return f;
}

function decodeUplink(input) {
var bytes = input.bytes;
return {
data: {
lat: bytesToFloat(bytes.slice(0,4)),
lon: bytesToFloat(bytes.slice(4,9))
}
}
}

Hi
Sorry, I just realised you were not asking about the codec. The other thing I had to modify for this crd to talk to Chirpstack was the part in the example sketch about the channel mask as below (first value changed to 0xFF00) This may be different depending on the area you are using it and I am in Australia.

/LoraWan channelsmask, default channels 0-7/
uint16_t userChannelsMask[6]={ 0xFF00,0x0000,0x0000,0x0000,0x0000,0x0000 };

Regards
Andrew

Hi,

Thanks for getting back to me. I got it working with this codec and everything seems ok. This is a little trick I learned for CS 3 when using TTN codecs… :slight_smile:

function Decode(fPort, bytes, variables) {
    return Generic_Decoder(bytes, fPort);
}

function bytesToInt(by) {
    f = by[0] | by[1]<<8 | by[2]<<16 | by[3]<<24;
    return f;
} 
  
function bytesToFloat(by) {
    var bits = by[3]<<24 | by[2]<<16 | by[1]<<8 | by[0];
    var sign = (bits>>>31 === 0) ? 1.0 : -1.0;
    var e = bits>>>23 & 0xff;
    var m = (e === 0) ? (bits & 0x7fffff)<<1 : (bits & 0x7fffff) | 0x800000;
    var f = sign * m * Math.pow(2, e - 150);
    return f;
} 
  
function Generic_Decoder(bytes, port) {
  
    var decoded = {};
    i = 0;
  
    decoded.latitude = bytesToFloat(bytes.slice(i,i+=4));
    decoded.longitude = bytesToFloat(bytes.slice(i,i+=4));
    decoded.altitude = bytesToFloat(bytes.slice(i,i+=4));
    decoded.course = bytesToFloat(bytes.slice(i,i+=4));
    decoded.speed = bytesToFloat(bytes.slice(i,i+=4));
    decoded.hdop = bytesToFloat(bytes.slice(i,i+=4));
  
    decoded.battery = ((bytes[i++] << 8) | bytes[i++]);

    return decoded;
}

Only thing is I set duty cycle to 30 seconds but on battery it does not seem to want to wake up and send only when powered. Do you know where I change this, as I am sure that it is down to a setting in the Sketch…

Anyway, thanks for getting back to me from all the way in Auz!