Stage 4: Registering Your End Node with the Network Server
Update the Device Profile Codec to Decode the Payload
Click Device profiles in the menu on the left.
-
Click the Device profile link to the device profile you created earlier.
-
Select the Codec tab.
-
Choose JavaScript functions from the Payload codec options, as shown in Figure 13.
-
Paste the following code into the Codec functions field that appears, replacing all the boilerplate code:
// 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) { let data = {}; // check that this is an application message, which is sent over Frame Port 1 in our code if (input.fPort === 1) { // decode the encoded moisture reading data.moisture = input.bytes[0] + input.bytes[1] * 256; } // return the object containing the data field, conforming to the specification return { data: data } }
-
Click the Submit button to save the codec to the device profile.