Create a custom codec/product

µWiotys already supported numerous references of LoRaWAN devices on the market but in case your device is still not supported, you can create your own product in the catalog and its proper decoder.

  • Go to the Product Catalog menu and click on "Add Product Catalog"

image-20241218-132437.png
image-20250114-105033.png
  • Click the "Select device-profile template" and choose
    CUSTOM-uWiotys profile.

  • Then update the name and the description of your sensor:

  • Finally you can use your codec in the codec tab

Decoded data must be return in JSON format.

For Modbus, decoded data are stored in registers with the address defined at Custom registers

Advance development for your codec:

Your codec must follow several principles in order to work with µWiotys.

The sample code is below provides the default implementation. We advice to test your codec with a NodeJS application such as NodeJS Online Compiler.

// Decode uplink function. // // !!! IMPORTANT !!! // MAKE SURE THE "Tags" OPTION OF YOUR PRODUCT IS SET TO: // key : "reference" ------ value : "CUSTOM" // PLEASE LOOK AT UWIOTYS DOCUMENTATION FOR MORE INFORMATION // // Input is an object with the following fields: // - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0] // - fPort = Uplink fPort. // - recvTime = Uplink message timestamp as Date object. // - variables = Object containing the configured device variables. // // Output must be an object with the following fields so it can be compatible // with uWiotys: // Output values must be put in different registers. Possible values are: // - reg_u16_0 to reg_u16_15 : default modbus register for unsigned values (2 bytes) // - reg_i16_0 to reg_i16_15 : default modbus register for signed values (2 bytes) // - reg_u32_0 to reg_u32_15 : modbus register for long unsigned values (4 bytes) // - reg_i32_0 to reg_i32_15 : modbus register for long signed values (4 bytes) // - reg_f32_0 to reg_f32_15 : modbus register for long float signed values (4 bytes) // // - In this simple exemple, the sensor send a frame with temperature and humidity values // Temperature value is put in reg_u32_0 and humidity in reg_u16_1 function decodeUplink(input) { var byte = input.bytes; var temperature = ((byte[0] << 24) | (byte[1] << 16) | (byte[2] << 8) | (byte[3])).toString(); var humidity = ((byte[4] << 8) | (byte[5])).toString(); return { data: { reg_u32_0:temperature, reg_u16_1:humidity } }; } // Encode downlink function. // // Input is an object with the following fields: // - data = Object representing the payload that must be encoded. // - variables = Object containing the configured device variables. // // Output must be an object with the following fields: // - bytes = Byte array containing the downlink payload. function encodeDownlink(input) { return { bytes: [225, 230, 255, 0] }; } //NEXT LINES ARE USED TO TEST YOUR CODEC WITH AN EXTERNAL APPLICATION. //DO NOT INCLUDE THESE LINES WHEN YOU WILL IMPORT THE CODEC ON UWIOTYS // Convert a hex string to a byte array function hexToBytes(hex) { let bytes = []; for (let c = 0; c < hex.length; c += 2) bytes.push(parseInt(hex.substr(c, 2), 16)); return bytes; } /* data="0000000A0022" var data_in = {}; data_in.bytes = hexToBytes(data); decoded = decodeUplink(data_in); console.log(JSON.stringify(decoded, null, 4)); */

Output:

{ "data": { "reg_u32_0": "10", "reg_u16_1": "34" } }