Skip to content

Unlocking Custom Node-RED Data Decoding with JEDI

JEDI streamlines integration with your Node-RED flows by providing flexible custom decoding capabilities. Enhance data compatibility and tailor your metrics through JavaScript codecs specifically designed for your Node-RED data structures.

Note

This features is available in Machinechat JEDI v3.8.5 or newer.

Why JEDI for Decoding Your Node-RED Messages?

While Node-RED excels at building event-driven applications, it often lacks features crucial for enterprise deployments. JEDI bridges this gap by seamlessly integrating with Node-RED, providing a robust and feature-rich environment for managing and visualizing your IoT data. Here's what JEDI brings to the table:

  • Web-Based Multi-User Dashboards: Effortlessly create stunning and informative dashboards to visualize real-time and historical data from your Node-RED flows. Collaborate with your team and share insights through user-friendly web interfaces.

  • Rules and Monitoring: Define rules to trigger actions based on sensor data or other events within your Node-RED flows. JEDI's monitoring capabilities enable you to proactively identify and address issues in your system.

  • Data Logging and Storage: JEDI securely stores your sensor data, allowing for historical analysis and trend identification. Gain valuable insights from your data over extended periods.

  • Enterprise-Level Features: JEDI adds essential features like role-based user access control, data encryption, and scalability, making it suitable for mission-critical deployments.

Leverage Existing Node-RED Workflows & Community Nodes

JEDI's beauty lies in its complementary nature. You can continue to leverage the vast ecosystem of community-developed Node-RED nodes for data ingestion and specific functionalities within your Node-RED flows. Focus on your core Node-RED logic, while JEDI handles the data visualization, rules management, and enterprise-grade features.

Getting Started with Machinechat Bridge

For detailed instructions on setting up and using the "Machinechat Bridge" Node-RED node to stream data to JEDI and utilize custom decoding, refer to the official documentation: Machinechat Bridge for Node-RED

Empowering Node-RED with JEDI's Decoding Power

Unlock the full potential of your Node-RED workflows with JEDI's custom decoding capabilities. Streamline your data handling, gain valuable insights, and build robust and scalable IoT applications – all while leveraging the familiar Node-RED development environment.

Integrating with the "Machinechat Bridge" Node

  1. "Machinechat Bridge" Configuration: When configuring your "Machinechat Bridge" node in Node-RED, assign a "unique_indentifier". JEDI will use this ID to dynamically load the correct JavaScript codec.

  2. HTTP Endpoint: The "Machinechat Bridge" node automatically forwards raw Node-RED "msg" objects to JEDI's HTTP data collector at the route /v1/node-red/msg.

  3. Codec Lookup: JEDI searches for a file named nodered-{unique_indentifier}.js in your JEDI installation's "codecs" folder ({unique_indentifier} is replaced with the value you configured in the bridge node).

Inside the JavaScript Codec

Your codec file will have the following structure:

function decode(context, input) {
    // Your decoding logic here

    // Add decoded metrics to the input
    input.machinechat_context["mc"] = {
        nodeID: "YourNodeID", 
        metrics: {
            // Your metrics in the structure explained below        
        }
    };

    // No need to return anything
}

Decoding the "msg" Object

  • JEDI provides the full Node-RED payload in the input variable.
  • The input.msg property contains the original Node-RED "msg" object.
  • Extract and process the values from input.msg as needed.

The "mc" Object (Output)

Structure the decoded data within the new "mc" object you add back to input.machinechat_context:

"mc": {
    "nodeID": {Your Node ID}, // String representing the data source
    "metrics": {
        "metric_name_1": { "value": ..., "stype": ..., "ptype": ..., "units": ..., "precision": ...},
        "metric_name_2": {... },
        ... // Additional metrics
    }
}

The Metric Object

The "metrics" key in the decoded JSON response is a map that contains individual metric objects. Each metric object serves as a structured representation of a single data point you're sending to JEDI. Here's a detailed look at the properties within a metric object:

  • value (required): This is the core measurement or data point you're sending. The data type can be a number (representing integers or floating-point values), a string, or a boolean (true or false).

  • stype (optional): This stands for "semantic type" and is a user-defined string that provides additional context or meaning to your metric. It helps categorize and organize your data within JEDI for better analysis. For instance, you could define a semantic type of "room_temperature" for a temperature sensor reading.

  • ptype (required): This represents the primitive data type of the value property. Supported values are:

    • "float64": For double-precision floating-point numbers (e.g., sensor readings, percentages).
    • "string": For text data (e.g., descriptive labels, IDs).
    • "boolean": For true/false values (e.g., device on/off status).
  • units (optional): A string specifying the measurement units associated with the value. This helps in interpreting the data correctly (e.g., "°C" for temperature, "%" for humidity).

  • precision (optional): An integer specifying the number of decimal places to display when presenting the value. This provides control over the level of detail shown for floating-point numbers.

Example Metric Object

Here's an example of a metric object representing a temperature reading:

"temperature": {
    "value": 25.4,
    "ptype": "float64",
    "units": "Celsius",
    "precision": 1  // Display one decimal place
}

By providing these properties within your metric objects, you ensure JEDI can correctly interpret, store, and visualize your custom data from various sources.

Example nodered-sensor-data.js

Example (nodered-sensor-data.js)

function decode(context, input) {
   const msg = input.msg;

   input.machinechat_context["mc"] = {
        nodeID: msg.deviceId.toString(),  
        metrics: {
            "temperature": { "value": msg.payload.temperature, "ptype": "float64", "units": "Celsius" }, 
            "humidity": { "value": msg.payload.humidity, "ptype": "float64", "units": "%" }
        }
    };
}

Need help? Contact our support team: support@machinechat.io