Decode function for rak 612

Hi,

I’m looking for an exemple of decode function specific to RAK612.
I was not able to find one on this forum or Rakwireless web sites.

Thanks in advance

Patrice

Please refer to:https://github.com/RAKWireless/RUI_LoRa_node_payload_decoder

Nothing for rak612 I’m afraid. On for RAK5205/RAK7205, RAK7204, and RAK7200.

The 612 sends plain ASCII as a hex string as “Key x” where x is the button number, although you can change that if you want to via AT commands.

So, for TTN, you need a JavaScript function that will turn the ASCII hex back to a string:

function Decoder(bytes, port) {

	var str = '';
	
	for (var n = 0; n < bytes.length; n += 2) {
		str += String.fromCharCode(parseInt(bytes.substr(n, 2), 16));
	}
	
	return str;
}

Thanks but I got an error
‘Substr is not a function’

OK, didn’t actually test this on TTN as the setup would have taken longer than preparing the code, I’ve swapped the substr for substring, so try this:

function Decoder(bytes, port) {

	var str = '';
	
	for (var n = 0; n < bytes.length; n += 2) {
		str += String.fromCharCode(parseInt(bytes.substring(n, n + 2), 16));
	}
	
	return str;
}

Same: substring is not a function.

Both of these functions work in the browser so I’ll have to figure out how to test this - there must be something going on with the JavaScript processing server side that I’m not aware of.

However, as there is no actual moving numbers, the replies will be consistent depending on which key is pressed, so you could just take the raw data and compare with that.