Below is an improved and more comprehensive documentation for the LOT Visual Studio Code Extension and its integration with Coreflux Models and Rules. This documentation consolidates installation instructions, usage details, and instructions for uploading models and rules to an MQTT broker, providing a smoother workflow and better clarity.
LOT - Visual Studio Code Extension Documentation
Overview
The LOT Language Support extension for Visual Studio Code provides a first-class development experience for working with the LOT language, which is used within the Coreflux platform. By installing this extension, you gain the following features:
- Syntax Highlighting: Enhanced readability for
.lot
and.cf
files. - Code Snippets: Quickly scaffold
RULE
,MODEL
, andROUTE
definitions. - Language Configuration: Bracket matching, comment toggling, and auto-closing pairs tailored for LOT.
- Integration with MQTT: Directly upload LOT models and rules to an MQTT broker for immediate deployment within Coreflux.
This extension streamlines your development process, allowing you to focus on business logic while the extension handles syntax details and broker interactions.
Installation
1. VS Code Marketplace (Recommended)
- Open Visual Studio Code.
- Go to the Extensions view by clicking the Extensions icon in the Activity Bar or pressing
Ctrl+Shift+X
. - Search for "LOT Language Support by Coreflux".
- Click Install.
2. Manual Installation
- Download the latest
.vsix
file from the GitHub Releases (replace this placeholder with your repository link). - In Visual Studio Code, open the Extensions view.
- Click the three dots (
...
) in the top-right corner and select "Install from VSIX...". - Navigate to the downloaded
.vsix
file and install it.
Features and Usage
Syntax Highlighting
Open any .lot
or .cf
file in Visual Studio Code. The LOT extension automatically applies syntax highlighting, making it easier to read and understand your LOT language code. Keywords, conditions, operations, and string literals are visually distinguished.
Code Snippets
Code snippets speed up the creation of common LOT constructs:
defrule
: Quickly scaffold a rule definition.defmodel
: Insert a model definition template.defroute
: Start a route definition skeleton.
To use a snippet, start typing the snippet prefix and press Tab
to insert it. Edit the placeholders to quickly build out your logic.
Example Snippet for a Rule:
DEFINE RULE AllowUserCreation WITH PRIORITY 1 FOR UserManagementCreation
IF USER HAS AllowedUserManagement OR USER IS "root" THEN
ALLOW
ELSE
DENY
Language Configuration
The LOT extension provides language-configuration features:
- Bracket Matching: Quickly navigate matching braces.
- Auto-Closing Pairs: Automatically close quotes, parentheses, and brackets.
- Comment Support: Toggle line comments with
Ctrl+/
(Windows/Linux) orCmd+/
(macOS).
These features enhance productivity and reduce syntax errors.
Working with Models and Rules in Coreflux
LOT language is heavily used within Coreflux for defining Rules (for permissions and operations) and Models (for data processing and transformations).
Rules: Control user permissions, operations on $SYS
topics, and restrict or allow actions like UserManagementCreation
, Publish
, Subscribe
, etc.
Models: Process incoming MQTT messages, perform calculations, and publish computed results to output topics. You can define constants, triggers, and expressions to transform data in real time.
Adding Models or Rules
You can create models or rules in .lot
files. For example:
Model Example:
DEFINE MODEL LampEnergyCost WITH TOPIC "Coreflux/+/+/+/+/energy"
ADD "total_energy" WITH TOPIC "shellies/+/+/+/+/device/energy" AS TRIGGER
ADD "energy_price" WITH 3
ADD "cost" WITH (total_energy * energy_price)
Rule Example:
DEFINE RULE AllowUserCreation WITH PRIORITY 1 FOR UserManagementCreation
IF USER HAS AllowedUserManagement OR USER IS "root" THEN
ALLOW
ELSE
DENY
Uploading Models and Rules to the MQTT Broker
New in this extension: You can right-click in the editor to upload a model or rule directly to your MQTT broker, saving you the hassle of manually running commands from another tool.
Steps to Upload
-
Prepare Your File:
Open a.lot
or.cf
file containing aDEFINE MODEL
orDEFINE RULE
block. -
Select Content:
Either select the entireDEFINE MODEL
/DEFINE RULE
code block or just ensure your cursor is within the file containing the definition. -
Right-Click and Upload:
Right-click in the editor and choose "Upload Model or Rule to MQTT Broker" from the context menu. -
Broker Address Prompt:
You will be prompted for the broker address (e.g.mqtt://127.0.0.1:1883
). Enter the correct address. -
Password Prompt:
The extension will then prompt you for an MQTT password. Username is fixed toroot
. Enter the password if required. -
Confirmation:
Once submitted, the extension will connect to your MQTT broker and send the-addModel <code>
or-addRule <code>
command to$SYS/Coreflux/Command
. If successful, a confirmation message will appear in VS Code.
Example Workflow:
- Open
myModel.lot
containing aDEFINE MODEL
statement. - Right-click the editor and select "Upload Model or Rule to MQTT Broker".
- Enter
mqtt://127.0.0.1:1883
when prompted. - Enter the MQTT password if prompted.
- Receive a success message indicating the model was uploaded.
Advanced Tips
-
Multiple Models/Rules in One File:
You can define multiple models or rules in a single file. Select just the relevant code block before uploading, or place your cursor where needed, if the extension supports that. -
Wildcard Topics:
Use+
and#
in topics for Unified Namespace scenarios, enabling flexible handling of multiple devices or domains without changing the model or rule. -
Testing Changes:
After uploading a model or rule, you can immediately test the Coreflux environment by publishing to trigger topics and observing the transformed outputs or enforced permissions.
Troubleshooting
-
No Editor Selected:
Ensure you have an active text editor open with.lot
or.cf
content before running the upload command. -
Incorrect Broker Address:
Double-check the MQTT broker address format:mqtt://<host>:<port>
. -
Missing or Unrecognized Code:
Confirm that your file contains a validDEFINE MODEL
orDEFINE RULE
block. The extension checks forDEFINE MODEL
orDEFINE RULE
keywords to determine what to upload. -
Authentication Errors:
If password or connectivity fails, ensure your broker allows connections fromroot
user and verify credentials.