I’ve managed to crack this.
First - word of warning - what I’m doing here is not suitable for TTN directly because my test SDM230-LoRaWAN is being very verbose but I’m using a private loRaWAN network server so it doesn’t matter quite so much.
Anyway:
I’ve got the SDM230 sending messages automatically and my network server is forwarding them as json over MQTT like this:
{
"adr": true,
"applicationID": "2",
"applicationName": "appTest2",
"data": "01569A8A060C000000003F820C4A3F820C4A585B",
"data_encode": "hexstring",
"devEUI": "8680000122450000",
"deviceName": "meter1",
"fCnt": 10,
"fPort": 1,
"rxInfo": [
{
"gatewayID": "ac1f09fffe080000",
"location": {
"altitude": 0,
"latitude": 0.0,
"longitude": 0.0
},
"loRaSNR": 14.8,
"rssi": -25
}
],
"timestamp": 1681156445,
"txInfo": {
"dr": 6,
"frequency": 868300000
}
}
I’m receiving this in node-red and processing the data elements thus:
// hex int to decimal int
function hexToDec(hexString){
return parseInt(hexString, 16);
}
//https://gist.github.com/Jozo132/2c0fae763f5dc6635a6714bb741d152f
function HexToFloat32(str) {
var int = parseInt(str, 16);
if (int > 0 || int < 0) {
var sign = (int >>> 31) ? -1 : 1;
var exp = (int >>> 23 & 0xff) - 127;
var mantissa = ((int & 0x7fffff) + 0x800000).toString(2);
var float32 = 0
for (i = 0; i < mantissa.length; i += 1) { float32 += parseInt(mantissa[i]) ? Math.pow(2, exp) : 0; exp-- }
return float32 * sign;
} else return 0
}
//modified from https://www.thethingsnetwork.org/forum/t/eastron-sdm230-lora-lorawan-issues/45126/48?page=2
function decode(str) {
var decoded = {};
decoded.SERIAL_NO = hexToDec(str.slice(0, 8));
decoded.MSG_TYP = hexToDec(str.slice(8,10)); //important, because vals are different for each typ
//decoded.VAL_COUNT = hexToDec(str.slice(10,12))/4; //not using this - eastron SDM230 always sends 3 data items but maybe SDM630 sends more?
decoded.VAL1 = HexToFloat32(str.slice(12,20));
decoded.VAL2 = HexToFloat32(str.slice(20,28));
decoded.VAL3 = HexToFloat32(str.slice(28,36));
return decoded;
}
The key to interpreting what each VAL is, depends on MSG_TYP. Note that I said ‘data elements’ above, because in my case, the meter is spitting out 6 different messages in sequence, and the order is the same as in table 1 of the published protocol document Eastron_SDM230-LoRaWAN_protocol_V1.0-combined.pdf which you can get off the Eastron-Europe website (after you log in to it).
So in my case, when MSG_TYP=5 then VAL1=Import kWh, VAL2=Export kWh and VAL3=Total kWh
Below Table 1 there’s a short paragraph which shows how the register in the SDM20 which determines what messages are sent, and in which order, is set. In my case, the register is obviously set as per Table 1 and I’m getting nearly all of what the meter is capable of sending out.
I don’t really need to collect all this stuff and it would be nice to be able to change it so I’m getting just 2 messages (ie 6 data items) but I don’t know how to do this.
Suggestions welcome!