MXL - Meddle Expression Language
Overview
Section titled “Overview”MXL (Meddle Expression Language) is a simple expression language used in Meddle connectors for defining conditions and logic.
Used in:
Syntax
Section titled “Syntax”MXL expressions evaluate to boolean values (true/false) based on payload data.
Basic Structure
Section titled “Basic Structure”field_name operator valueExamples
Section titled “Examples”temperature > 80pressure < 10status == "active"count != 0Operators
Section titled “Operators”Comparison Operators
Section titled “Comparison Operators”| Operator | Description | Example |
|---|---|---|
> | Greater than | temperature > 80 |
< | Less than | pressure < 10 |
>= | Greater than or equal | humidity >= 60 |
<= | Less than or equal | speed <= 100 |
== | Equal to | status == "active" |
!= | Not equal to | count != 0 |
Logical Operators
Section titled “Logical Operators”| Operator | Description | Example |
|---|---|---|
&& | AND (both conditions must be true) | temp > 80 && press < 10 |
| ` | ` |
Data Types
Section titled “Data Types”Numbers
Section titled “Numbers”Compare numeric values:
temperature > 25.5pressure >= 101.3count == 100speed != 0Strings
Section titled “Strings”Compare string values (use double quotes):
status == "active"mode != "manual"error_code == "E001"Boolean
Section titled “Boolean”Compare boolean values:
enabled == truefault != falseComplex Expressions
Section titled “Complex Expressions”Multiple Conditions with AND
Section titled “Multiple Conditions with AND”All conditions must be true:
temperature > 20 && temperature < 30pressure > 100 && humidity < 80 && status == "running"Multiple Conditions with OR
Section titled “Multiple Conditions with OR”At least one condition must be true:
temperature > 80 || pressure > 150status == "error" || status == "fault" || status == "stopped"Combining AND and OR
Section titled “Combining AND and OR”Use parentheses for grouping (if supported):
(temperature > 80 || pressure > 150) && status == "active"Common Patterns
Section titled “Common Patterns”Range Check
Section titled “Range Check”Check if value is within range:
temperature >= 20 && temperature <= 30Threshold Alert
Section titled “Threshold Alert”Alert when value exceeds threshold:
temperature > 80pressure > 150vibration > 5.0Status Monitoring
Section titled “Status Monitoring”Check for specific status values:
status == "error"status != "running"mode == "manual"Multi-Parameter Alert
Section titled “Multi-Parameter Alert”Alert on multiple conditions:
temperature > 100 || pressure > 150 || vibration > 5Safety Interlock
Section titled “Safety Interlock”Ensure multiple conditions are met:
temperature > 50 && pressure > 100 && flow > 10Examples by Use Case
Section titled “Examples by Use Case”Temperature Monitoring
Section titled “Temperature Monitoring”// High temperature warningtemperature > 80
// Temperature out of rangetemperature < 15 || temperature > 35
// Critical temperature with pressuretemperature > 100 && pressure > 150Equipment Status
Section titled “Equipment Status”// Machine stopped unexpectedlystatus == "stopped" && runtime > 0
// Error conditionstatus == "error" || status == "fault"
// Not in automatic modemode != "auto"Quality Control
Section titled “Quality Control”// Defect detecteddefect_count > 0
// Out of specificationdimension < 9.9 || dimension > 10.1
// Multiple quality parametershardness < 50 || surface_finish > 2.0 || weight < 100Process Control
Section titled “Process Control”// Process out of controltemperature > 90 || pressure < 95 || flow < 50
// Stable operationtemperature >= 80 && temperature <= 85 && pressure > 100
// Emergency shutdown conditiontemperature > 120 || pressure > 200 || vibration > 10Predictive Maintenance
Section titled “Predictive Maintenance”// Anomaly detectedis_anomaly == true
// High anomaly scoreanomaly_score > 0.8
// Multiple indicatorsvibration > 5 || temperature > 90 || anomaly_score > 0.7Best Practices
Section titled “Best Practices”1. Use Clear Field Names
Section titled “1. Use Clear Field Names”// Goodtemperature > 80machine_status == "running"
// Avoidt > 80s == "r"2. Use Appropriate Operators
Section titled “2. Use Appropriate Operators”// For equality, use ==status == "active"
// For inequality, use !=count != 03. Group Related Conditions
Section titled “3. Group Related Conditions”// Good - related conditions togethertemperature > 80 && pressure > 150
// Good - alternative conditionsstatus == "error" || status == "fault"4. Consider Operator Precedence
Section titled “4. Consider Operator Precedence”AND (&&) has higher precedence than OR (||):
// This checks: (A && B) || Ctemperature > 80 && pressure > 150 || humidity > 90
// Use parentheses for clarity(temperature > 80 && pressure > 150) || humidity > 905. Test Your Expressions
Section titled “5. Test Your Expressions”Test expressions with various input values to ensure they work as expected.
Limitations
Section titled “Limitations”- No arithmetic operations: Cannot do
temperature + 10 > 90 - No function calls: Cannot do
abs(temperature) > 80 - No nested field access: Cannot do
sensor.temperature > 80 - String comparison only: No regex or pattern matching
Troubleshooting
Section titled “Troubleshooting”Expression Not Triggering
Section titled “Expression Not Triggering”Check:
- Field names match payload exactly (case-sensitive)
- Data types match (number vs string)
- Operator is correct (
==not=) - String values use double quotes
Always Triggering
Section titled “Always Triggering”Check:
- Logic is correct (AND vs OR)
- Threshold values are appropriate
- Field exists in payload
Syntax Errors
Section titled “Syntax Errors”Common mistakes:
- Using
=instead of== - Missing quotes around strings
- Typos in field names
- Wrong operator precedence
Examples in Context
Section titled “Examples in Context”Trigger Connector
Section titled “Trigger Connector”{ "type": "MeddleTrigger", "config": { "mode": "DirectDispatch", "condition": "temperature > 80 && status == \"active\"", "payload": { "alert": "high_temperature" } }}Alert Connector
Section titled “Alert Connector”{ "type": "MeddleAlert", "config": { "name": "Critical Alert", "condition": "temperature > 100 || pressure > 200", "minDuration": 10, "cooldown": 300, "notification": { "type": "Email", "toEmails": ["alerts@example.com"] } }}Related Documentation
Section titled “Related Documentation”- Trigger Connector - Use MXL for conditional logic
- Alert Connector - Use MXL for alert conditions
- Anomaly Detection - Combine with MXL for smart alerts