Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions vendor/fencyboy/fencyboy-v1-3-1-codec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Uplink decoder decodes binary data uplink into a JSON object (optional)
# For documentation on writing encoders and decoders, see: https://www.thethingsindustries.com/docs/integrations/payload-formatters/javascript/
uplinkDecoder:
fileName: fencyboy-v1-3-1_payload_decoder_ttn.js
# Examples (optional)
examples:
- description: Normal operation but 0 V on electric fence
input:
fPort: 1
bytes: [28, 14, 4, 0, 0, 14, 16, 70, 60, 253, 139, 12, 97]
output:
data:
ACTIVE_MODE: false
IMPULSES: 0
FENCEVOLTAGE: 0
FENCE_VOLTAGE_STD: 0
FENCEVOLTAGEMIN: 0
FENCEVOLTAGEMAX: 0
BATTERYVOLTAGE: 3.6
REMAINING_CAPACITY: 12095.3857421875
TEMPERATURE: 31.69
DEBUG:
ADC_LAST_READ_OKAY: true
ADC_VERIFY: true
errors: []
warnings: []
- description: Normal operation with 10860 V on electric fence
input:
fPort: 1
bytes: [29, 13, 254, 1, 217, 42, 108, 4, 115, 41, 108, 43, 83, 14, 9, 70, 61, 2, 56, 13, 75]
output:
data:
ACTIVE_MODE: true
IMPULSES: 473
FENCEVOLTAGE: 10860
FENCE_VOLTAGE_STD: 113.9
FENCEVOLTAGEMIN: 10604
FENCEVOLTAGEMAX: 11091
BATTERYVOLTAGE: 3.593
REMAINING_CAPACITY: 12096.5546875
TEMPERATURE: 34.03
DEBUG:
ADC_LAST_READ_OKAY: true
ADC_VERIFY: true
errors: []
warnings: []
47 changes: 47 additions & 0 deletions vendor/fencyboy/fencyboy-v1-3-1-profile-eu868.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# LoRaWAN MAC version: 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4 or 1.1
macVersion: '1.0.2'
# LoRaWAN Regional Parameters version. Values depend on the LoRaWAN version:
# 1.0: TS001-1.0
# 1.0.1: TS001-1.0.1
# 1.0.2: RP001-1.0.2 or RP001-1.0.2-RevB
# 1.0.3: RP001-1.0.3-RevA
# 1.0.4: RP002-1.0.0 or RP002-1.0.1
# 1.1: RP001-1.1-RevA or RP001-1.1-RevB
regionalParametersVersion: 'RP001-1.0.2-RevB'

# Whether the end device supports join (OTAA) or not (ABP)
supportsJoin: true
# If your device is an ABP device (supportsJoin is false), uncomment the following fields:
# RX1 delay
#rx1Delay: 5
# RX1 data rate offset
#rx1DataRateOffset: 0
# RX2 data rate index
#rx2DataRateIndex: 0
# RX2 frequency (MHz)
#rx2Frequency: 869.525
# Factory preset frequencies (MHz)
#factoryPresetFrequencies: [868.1, 868.3, 868.5, 867.1, 867.3, 867.5, 867.7, 867.9]

# Maximum EIRP
maxEIRP: 14
# Whether the end device supports 32-bit frame counters
supports32bitFCnt: true

# Whether the end device supports class B
supportsClassB: false
# If your device supports class B, uncomment the following fields:
# Maximum delay for the end device to answer a MAC request or confirmed downlink frame (seconds)
#classBTimeout: 60
# Ping slot period (seconds)
#pingSlotPeriod: 128
# Ping slot data rate index
#pingSlotDataRateIndex: 0
# Ping slot frequency (MHz). Set to 0 if the band supports ping slot frequency hopping.
#pingSlotFrequency: 869.525

# Whether the end device supports class C
supportsClassC: false
# If your device supports class C, uncomment the following fields:
# Maximum delay for the end device to answer a MAC request or confirmed downlink frame (seconds)
#classCTimeout: 60
192 changes: 192 additions & 0 deletions vendor/fencyboy/fencyboy-v1-3-1_payload_decoder_ttn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/**
* Fencyboy v1.3.1 Payload Decoder TTN
*
*/

function decodeNormalPayload(bytes) {

// decode status byte
var statusByte = bytes[0];
var isInActiveMode = Boolean(statusByte & 0x01);
var hasBatterySensorData = Boolean(statusByte & 0x04);
var adcLastReadOkay = Boolean(statusByte & 0x08);
var adcVerify = Boolean(statusByte & 0x10);

// baseline size is 5
// optionally 8 bytes for fence voltages
// optionally 8 bytes for battery sensor data with temperature
var validByteLenghts = [
5, // baseline size
13, // baseline + battery sensor with temperature
13, // baseline + fence voltages
21, // baseline + fence voltages + battery sensor with temperature
];
if (!isElementInArray(bytes.length, validByteLenghts)) {
return {
data: { },
warnings: [
"Unexpected length of bytes: " + bytes.length + ". Expected lenght to be one of " + validByteLenghts + "."
],
errors: []
}
}

var idx = 1;
var batteryVoltage = readUInt16BG(bytes.slice(idx, idx+2)) / 1000;
idx += 2;
var impulsecounter = readUInt16BG(bytes.slice(idx, idx + 2));
idx += 2;

var data = {
ACTIVE_MODE: isInActiveMode,
BATTERYVOLTAGE: batteryVoltage,
IMPULSES: impulsecounter,
DEBUG: {
ADC_LAST_READ_OKAY: adcLastReadOkay,
ADC_VERIFY: adcVerify
},
};


data.FENCEVOLTAGE = 0.0;
data.FENCE_VOLTAGE_STD = 0.0;
data.FENCEVOLTAGEMIN = 0.0;
data.FENCEVOLTAGEMAX = 0.0;
if (impulsecounter > 0) {
data.FENCEVOLTAGE = readInt16BG(bytes.slice(idx, idx + 2));
idx += 2;
data.FENCE_VOLTAGE_STD = readInt16BG(bytes.slice(idx, idx + 2)) / 10;
idx += 2;
data.FENCEVOLTAGEMIN = readInt16BG(bytes.slice(idx, idx + 2));
idx += 2;
data.FENCEVOLTAGEMAX = readInt16BG(bytes.slice(idx, idx + 2));
idx += 2;
}

if (hasBatterySensorData) {
data.BATTERYVOLTAGE = readInt16BG(bytes.slice(idx, idx + 2)) / 1000;
idx += 2;

data.REMAINING_CAPACITY = bytesToFloat(bytes.slice(idx, idx + 4));
idx += 4;

data.TEMPERATURE = readInt16BG(bytes.slice(idx, idx + 2)) / 100;
idx += 2;
}

return {
data: data,
warnings: [],
errors: []
};
}

function decodeSettingsPayload(bytes) {

// Unexpected length of bytes: " + bytes.length + ". Expected lenght 12.
if (bytes.length != 12) {

return {
data: { },
warnings: ["Invalid length of Settings payload: " + bytes.length],
errors: []
}
}

return {
data: {
CONFIGURATION_VERSION: bytes[0],
CONFIGURATION_SENDINTERVAL: bytes[1],
CONFIGURATION_STATUSLED_ON: Boolean(bytes[2]),
CONFIGURATION_SMARTSLEEP_ON: Boolean(bytes[3]),
CONFIGURATION_EXPECTED_MS_BETWEEN_IMPULSES: readUInt16BG(bytes.slice(4, 6)),
CONFIGURATION_PERIODIC_RESTART_TIME_MINUTES: readUInt16BG(bytes.slice(6, 8)),
CONFIGURATION_VOLTAGE_DIVIDER_MULTIPLIER: bytesToFloat(bytes.slice(8, 12)),
},
warnings: [],
errors: []
};
}

function decodeMinutesTillRestartPayload(bytes) {

// Unexpected length of bytes: " + bytes.length + ". Expected lenght 2.
if (bytes.length != 2) {

return {
data: { },
warnings: ["Invalid length of MinutesTillRestart payload: " + bytes.length],
errors: []
}
}

return {
data: {
MINUTES_TILL_RESTART: readUInt16BG(bytes.slice(0, 2)),
},
warnings: [],
errors: []
};
}

function decodeUplink(input, x) {

//var metadata = getMetadata(input);

if (input.fPort === 1) {
return decodeNormalPayload(input.bytes);
} else if (input.fPort === 2) {
return decodeSettingsPayload(input.bytes);
} else if (input.fPort === 3) {
return decodeMinutesTillRestartPayload(input.bytes);
}

return {
data: { },
warnings: [],
errors: ["invalid fPort: "+ input.fPort]
};
}

function isElementInArray(element, array) {
for (var index = 0; index < array.length; index++) {
if (element === array[index]) {
return true;
}
}
return false;
}


/* ******************************************
* bytes to number
********************************************/
function readUInt16BG(bytes) {
var value = (bytes[0] << 8) + bytes[1];
return value & 0xffff;
}

function readUInt32BG(bytes) {
var value = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3];
return value & 0xffffffff;
}

function readInt16BG(bytes) {
var ref = readUInt16BG(bytes);
return ref > 0x7fff ? ref - 0x10000 : ref;
}

function readInt32BG(bytes) {
var ref = readUInt32BG(bytes);
return ref > 0x7fffffff ? ref - 0x100000000 : ref;
}

function bytesToFloat(bytes) {
//MSB Format (least significant byte first).
var bits = bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
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;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading