BFC BFC Docs
Automation

Run Lua automations

Structure, test, upload, and operate a Lua automation in BFC Console.

Lua is the primary automation mode in the supplied examples. Each script defines a lifecycle that BFC Console calls:

function Startup()
    -- Connect and initialize once.
end

function Loop()
    -- Repeat until a stop is requested.
end

function Teardown()
    -- Leave devices and connections in a safe state.
end

Start from _volumes/__lua_scripts/__TEMPLATE.lua or a relevant example.

A minimal Gateway script

The following pattern connects to the Gateway, publishes a value once per second, and performs a clean shutdown:

local SourceName = "myAutomation"
local Counter = 0

function Startup()
    Gateway:Connect("http://bfc-gateway:5000")
    Gateway:Login("admin", "admin")
end

function Loop()
    Counter = Counter + 1
    Gateway:SetInt(
        SourceName,
        "cycleCount",
        Counter,
        GatewayValueValidity.VALID,
        "ct"
    )
    App.Wait(1000)
end

function Teardown()
    App:Log("Automation stopped")
end

Replace preview credentials before using the system outside a controlled test network.

Device-oriented examples use the built-in Master object:

Master:OpenRest("192.168.1.20")
Master:LogIn("MASTER_USER", "MASTER_PASSWORD")
Master:SetPort(2)

Generated IODD drivers expose device-specific methods. The generated object name and port setup depend on the driver shipped in _volumes/_plugins. Generic scripts can use Master:ReadProcessData(), ReadISDU, and WriteISDU.

Always add a delay or yield in a continuous loop. An unthrottled loop can overload the device, Gateway, database, and controller CPU.

Publish typed values

Gateway values are identified by a source name and key name:

Gateway:SetInt("line1", "count", 12)
Gateway:SetFloat("line1", "temperature", 23.5, GatewayValueValidity.VALID, "°C")
Gateway:SetString("line1", "state", "running")

A key's type is fixed after its first value. Writing a different type to the same source/key pair returns an error. Keep names stable because Node-RED and API clients use them as identifiers.

Upload through the Setup Tool

The selected Lua file must be inside a directory named _volumes. The tool:

  1. Finds that _volumes root.
  2. Uploads the entire tree, not only the selected file.
  3. Creates ~/.bfc/containers/BFC-SCRIPT_NAME/_volumes.
  4. Mounts the container workspace at /mnt/fog.
  5. Starts balluff/bfc-console with the script path relative to _volumes.

If the base container name already exists, the tool adds a numeric suffix.

Stop safely

Use Stop in the Setup Tool and wait for the container to exit. BFC translates the first stop signal into a graceful stop request and runs Teardown(). Use teardown to close a master connection, reset outputs, or show a safe SmartLight state.

Inspect Runtime files before removing files from _volumes; plugins, generated headers, and dependencies may be required even if the script does not refer to them by path.

Built with ASP.NET Core and Markdig. BFC user documentation · preview release