Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Introduction

The Internet of Things (IoT) is continuously evolving, driving the need for more adaptable and sophisticated sensor management systems. Recognizing this, myDevices has introduced an innovative feature in their platform: the Codec Editor and Device Template Editor. These tools offer unprecedented customization of sensor data handling, enabling device manufacturers and partners to fine-tune their IoT solutions for various applications.

Add device templates and codecs for various devices, such as sensors, actuators, gateways, tags, and more, as well as services for storing data, setting up alerts, visualizing data using custom dashboards, and transmitting data to other business intelligence (BI), artificial intelligence (AI), computerized maintenance management system (CMMS), or asset management software. Users can create templates and codecs for any use case or customer requirement, and manufacturers can easily onboard their complete hardware catalog and make it publicly available for widespread use. The possibilities are limitless. Follow the steps below to get started.

What is a Device Template?
A Device Template is a configuration blueprint that lets users define the representation, capabilities and management settings for an IoT device, sensor, or gateway.  This includes configuring device attributes, setting up data channels, and defining alert conditions. It provides a structured way to define and manage the characteristics and capabilities of that device within myDevices' application.

A Device Template is comprised of the following:

  1. General

...

  1. : Information about the device, such as name, description, and manufacturer, etc.

  2. Codec: used to decode or parse the payload of the device

...

  1. . It allows users to create and modify the logic (in JavaScript) that interprets sensor data.

  2. Capabilities: Sensors or Actuators the device supports.

  3. Attributes: UI settings conditions for specific use cases.

  4. Alert Types: Alerts are generated based on capabilities.

  5. Device Uses: used to define the use case of the device.


What is a Codec?
A codec for a device template is a script or set of instructions used to decode the raw data payload from IoT devices into a more meaningful and structured format. This ensures that the incoming data can be correctly interpreted and utilized by myDevicescan include encoding and decoding data packets, adapting to different communication protocols, and handling data in various formats.

Why do I need a Device Template and Codec?
Device templates and codecs are required to onboard devices into myDevices. They are used to define the capabilities of the device, how the data is decoded, and how the data is displayed in the UI. Device templates and codecs are also used to define the use case of the device, which is used to determine the appropriate alert types and attributes for the device.

Get Started Steps

  1. Log into console.mydevices.com

  2. Create a Device Template (add screenshot): Go to the Device Templates Tab. Here, you can access all templates you've created for your applications and organization. You'll also find example templates that can serve as starting points. To begin, click on "Add Device Template" in the top-right corner.

...

Adding a Device Template: Defining the Capabilities

Data capabilities represent the data transmitted by the device and are decoded by the codec. Add capabilities like temperature reading, motion detection, etc., ensuring each capability has a unique data channel. These capabilities determine how data appears in the management screen, gets stored in history, and enables alert creation. Click "Add Capability" to begin defining capabilities.

...

Fill out all fields including Template Type, Data Type, Name (Data Label in app), Channel ID, Chart, Icon and Widget.

...

  • Not all attributes are required, with only the Broadcast interval and Device Type being mandatory.

    • Broadcast interval should be set to match how often the device periodically checks in. If a device checks in only once a day, its broadcast interval should be set to 1440. By default we would recommend at least 60 minutes and no greater then 1440 minutes.

    • Device Type appears next to the device name in the UI.

...

...

    • Testing the Template: Use the simulator attribute to test how your template behaves with simulated sensor data.

Alert Types: Whenever you add a capability using either a Value or Status template type, the corresponding alert is generated. The alert notification text is editable, but the alert template is not editable currently.

  • For capabilities using Value template type, a Min/Max Threshold alert will automatically be created for that particular capability.

  • For capabilities using Status template type, distinct alert types are generated for each unique status. For instance, if you have a Status-based Door sensor that transmits 0 for "closed" and 1 for "open," an alert type is created for both "Open" and "Closed" states.

...

  • Personalizing Alert Notification Text: You have the ability to modify the text of alert notifications that will be transmitted for a specific alert type.

  • Enabling/Disabling Alert Type Settings: In certain scenarios, there may be data points where the end-user does not require an alert. In such cases, you can deactivate the display of the alert type (e.g., the "Panic Button Press" alert is visible in the user interface, while the "Not Pressed" alert can be toggled to a hidden status and will not be displayed).

Device Uses: This feature allows you to include predefined alerts set up pre defined alerts that get added automatically during the device setup process. This is particularly valuable when you already have specific alert requirements in mind for a given use case.

...

  1. Import or create a Codec into Codec Editor

...

Sample and Minimal Codec

Here is a minimal source code for the decoder.js file, with included comments explaining things.

Since it’s a JavaScript file running in a Node.JS sandbox, it allows us define a special context with dedicated data and functions.

In opposite to LoRaWAN type-of Codec, myDevices Engine doesn’t expect any specific function (although it could use a LoRaWAN type-of Codec), but provides tools to write Codec like any Node.JS script instead.

...

breakoutModewide
languagejs

...

The Codec Editor provides a flexible environment to write and edit JavaScript for custom codec creation.
Key functions include setting up data interpretation rules, handling different data types, and integrating various sensor models. Example Use Case: Tailoring a codec for a specific temperature sensor to interpret data for a greenhouse environment, converting raw readings into actionable insights like temperature trends and anomaly detection.

...


Getting Started with the Codec Editor
Creating a New Codec: Click on 'Create New Codec'. Enter a name for your codec and it will automatically generate an ID.


Editing the Codec: Use the JavaScript-based interface to input or modify the code. This may include setting up data decoding functions for incoming data from sensors.


Testing Your Codec: Utilize the built-in debugger to test your codec. Input sample data payloads to see how your code interprets them.


Saving and Applying the Codec: Once satisfied, save your codec. It can now be linked to a device template for use.

Sample and Minimal Codec

Here is a minimal source code for the decoder.js file, with included comments explaining things.

Since it’s a JavaScript file running in a Node.JS sandbox, it allows us define a special context with dedicated data and functions.

In opposite to LoRaWAN type-of Codec, myDevices Engine doesn’t expect any specific function (although it could use a LoRaWAN type-of Codec), but provides tools to write Codec like any Node.JS script instead.

Code Block
breakoutModewide
languagejs
// Example Payload Decoder
// Test with 00F000C8
//    Temp = 24°C
//    Lum  = 200lux

const multiplier = 0.1;

// Could use console.log to help debugging Codec
console.log("multiplier = %d", multiplier);

// Decoder.data.buffer contains a Node.JS Buffer object with the payload data
// See https://nodejs.org/docs/latest-v18.x/api/buffer.html for more information
console.log("Decoder.data.buffer = %s", Decoder.data.buffer.toString("hex"));
const buffer = Decoder.data.buffer;

// Decoder.data.fport contains LoRaWAN fPort
// Could be used to filter uplink or adapt data decoding accordingly
console.log("Decoder.data.fport = %d", Decoder.data.fport);

// Decoder must send a Sensor Object or Sensor Object Array
Decoder.sendSensors({
    channel: 0,                               // Data Channel, must matches with Template Capability
    type: DataTypes.TYPE.TEMPERATURE,         // Data Type
    unit: DataTypes.UNIT.CELSIUS,             // Data Unit
    value: buffer.readInt16BE(0) * multiplier // Data Value
});

Decoder.sendSensors({
    channel: 2,
    type: DataTypes.TYPE.LUMINOSITY,
    unit: DataTypes.UNIT.LUX,
    value: buffer.readUInt16BE(2)
});

// Complete Decoding process (optional, allows for faster response and prevent Codec timeout)
Decoder.done();


...

Since it’s running in a sandbox, you can also use usual console.log and console.error JavaScript function, and see the result directly in the editor. However those functions will be ignored when decoding real data (from real device) in order to speed up execution time.

Using LoRaWAN Codec API

In order to use LoRaWAN type-of Codec, you just have to include the function in your myDevices codec, call it with proper arguments, and then map and send the result into sensor objects (with channel/type/unit/value).

Code Block
breakoutModewide
languagejs
// Past your decodeUplink function
function decodeUplink(input) {
  // ... do something with input
  return output;
}

// Call it
const result = decodeUplink({
  bytes: Decoder.data.buffer,
  fPort: Decoder.data.fport,
  recvTime: new Date(Decoder.data.timestamp)
});

// Map and send sensor data
Decoder.sendSensors({
    channel: 1,
    type: DataTypes.TYPE.TEMPERATURE,
    unit: DataTypes.UNIT.CELSIUS,
    value: result.temperature
});

Decoder.done();
  1. Registry Device IDs: After creating a Device Template & Codec, you’ll next want to register device ID(s) to the new Device Template. Go to Registry Tab, click Upload Devices to begin.

...

  • Template Catalog

    • If you’re adding device IDs to a public template, choose Public.

    • If you’re adding device IDs to a template you created, choose Application.

  • Device Template

    • Select the appropriate template

  • Registry Type

    • You can choose to register the IDs to a specific application or make it globally available

  • Upload with Text input or CSV File

  1. Add the device to your app and visualize the data

...

Date(Decoder.data.timestamp)
});

// Map and send sensor data
Decoder.sendSensors({
    channel: 1,
    type: DataTypes.TYPE.TEMPERATURE,
    unit: DataTypes.UNIT.CELSIUS,
    value: result.temperature
});

Decoder.done();

  1. Registry Device IDs: After creating a Device Template & Codec, you’ll next want to register device ID(s) to the new Device Template. Go to Registry Tab, click Upload Devices to begin.

...

  • Template Catalog

    • If you’re adding device IDs to a public template, choose Public.

    • If you’re adding device IDs to a template you created, choose Application.

  • Device Template

    • Select the appropriate template

  • Registry Type

    • You can choose to register the IDs to a specific application or make it globally available

  • Upload with Text input or CSV File

  1. Add the device to your app and visualize the data

...

6. Best Practices and Tips

  • Gain a fundamental understanding of JavaScript and familiarize yourself with basic IoT communication protocols for effective use of the Codec Editor.

  • Regularly review and update device templates to stay aligned with evolving sensor technologies and varying data requirements.

  • Addressing Common Concerns: Prioritize data security and privacy when customizing codecs and templates, ensuring that the data handling complies with industry standards and regulations.

  • Iterative Development: Start with a basic setup and gradually add complexity as you become more familiar with the tools.

  • Regular Updates: Continuously revisit and update your codecs and templates to cater to new sensor models and evolving requirements.

  • Documentation and Support: Leverage the myDevices documentation and community forums for troubleshooting and best practices.

By following these steps and tips, users can fully utilize the Codec and Device Template Editors to create customized, efficient IoT solutions tailored to their specific needs.Conclusion

The introduction of the Codec and Device Template Editors in the myDevices platform marks a significant advancement in custom sensor management. By harnessing these features, users can significantly enhance their IoT deployments, ensuring they are robust, adaptable, and tailored to their specific needs.

Real Codec Examples

Dragino LHT65 Temp & Humidity Sensor 2.0 Codec Used

...