Skip to main content

The Notebook Workflow

LoT Notebooks provide a direct connection between your VS Code editor and the Coreflux broker. When you run a cell, your code is sent to the broker and executed immediately—no separate deployment step required.
Like sending a text message. You type your code, hit run, and it’s instantly delivered to the broker. The broker responds with success or an error message, which appears right below your cell.

Cell Types and Execution

LoT Notebooks support three types of cells, each with different behavior:

Markdown Cells

Markdown cells are for documentation only—they don’t execute. Use them to:
  • Explain what your code does and why
  • Document configuration requirements
  • Add diagrams, tables, and formatted text
  • Create section headers and navigation

LoT Code Cells

LoT cells contain executable LoT (Language of Things) code. When you run a LoT cell:
  1. The extension parses your code
  2. Sends it to the connected broker via MQTT
  3. The broker compiles and registers the definition
  4. You receive confirmation or error feedback
DEFINE ACTION TemperatureMonitor
ON TOPIC "sensors/+/temperature" DO
    IF PAYLOAD > 80 THEN
        PUBLISH TOPIC "alerts/high-temp" WITH "Warning: " + PAYLOAD + "°C"
What you can define:
DefinitionPurpose
DEFINE ACTIONEvent-driven or time-based automation
DEFINE MODELStructured data transformation
DEFINE ROUTEExternal system integration (databases, APIs, bridges)
DEFINE RULEAccess control and permissions

Python Cells

Python cells contain scripts that run inside the broker when called from LoT Actions. The broker’s Python runtime executes your functions.
# Script Name: DataProcessor
def calculate_average(values):
    """Calculate average from a list of numbers"""
    if not values:
        return 0
    return sum(values) / len(values)

def format_alert(sensor_id, value, threshold):
    """Generate formatted alert message"""
    return f"ALERT: Sensor {sensor_id} exceeded {threshold} with value {value}"
Python scripts require a specific format with # Script Name: YourScriptName as the first line. Without this header, the script won’t be recognized.

Execution Flow

When you click the Run button on a cell, here’s what happens:

Success Response

When your code is valid and the broker accepts it:
  • A green checkmark appears next to the cell
  • The entity (Action, Model, Route, Rule) is registered
  • For Actions, execution begins immediately based on triggers

Error Response

When something goes wrong:
  • An error message appears below the cell
  • The message includes details about what failed
  • Common issues: syntax errors, missing dependencies, connection problems

Broker Communication

The extension maintains an MQTT connection to your Coreflux broker. All notebook operations use this connection:
OperationMQTT TopicDescription
Deploy code$SYS/Coreflux/CommandSend definitions to the broker
Receive response$SYS/Coreflux/Command/OutputGet success/error feedback
List entities$SYS/Coreflux/Actions, etc.View registered Actions, Models, Routes

Connection Configuration

Configure your broker connection through the Command Palette:
  1. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac)
  2. Type “LoT Notebook: Change Credentials”
  3. Enter your broker details:
SettingExample
URLmqtt://localhost:1883 or mqtts://broker.example.com:8883
Usernameroot
PasswordYour broker password
The extension securely stores your credentials. You only need to configure them once per workspace.

Available Commands

Access these commands through the VS Code Command Palette (Ctrl+Shift+P):

Notebook Commands

CommandDescription
LoT Notebook: Change CredentialsConfigure broker connection
LoT Notebook: Run All CellsExecute all code cells in order
LoT Notebook: Clear All OutputsRemove output from all cells

Entity Management

CommandDescription
Coreflux: List ActionsView all registered Actions
Coreflux: List ModelsView all registered Models
Coreflux: List RoutesView all registered Routes
Coreflux: Remove EntityDelete an Action, Model, or Route

Bulk Operations

CommandDescription
Coreflux: Deploy AllUpload all definitions from notebook
Coreflux: Export DefinitionsSave definitions to separate files

Working with Output

Each code cell can display output after execution:

Viewing Results

  • Success: Shows confirmation message with entity name
  • Error: Displays error details and line numbers when available
  • Logs: For debugging, check the Output panel (View > Output > LoT Notebooks)

Clearing Output

  • Click the X on individual cell outputs
  • Use “LoT Notebook: Clear All Outputs” command for all cells
  • Outputs are not saved with the notebook file

Best Practices

Use markdown cells liberally to explain your code. Future you (and teammates) will appreciate the context.
Keep each Action, Model, or Route in its own cell. This makes debugging easier and allows selective execution.
Run cells one at a time when developing. This helps isolate issues and understand system behavior.
Name your Actions, Models, and Routes clearly. They appear in the broker’s entity lists and should be self-explanatory.

Troubleshooting

  • Check that you’re connected to the broker (look for connection status in status bar)
  • Verify your credentials are correct
  • Ensure the broker is running and accessible
  • Confirm the first line is # Script Name: YourScriptName
  • Check for syntax errors in the Python code
  • Ensure function names match what you’re calling from LoT
  • Check the output for error messages
  • Verify no syntax errors in your LoT code
  • Use the Coreflux Entities panel to refresh the list

Next Steps