Skip to content

Built-in Drivers

Muxit ships with five built-in drivers that are always available — no installation or DLL files needed. These cover testing, cameras, file storage, and IoT.

TestDevice

A simulated instrument for learning and testing. No hardware required — all values are stored in memory. Always available, doesn't count against your connector limit.

Properties

PropertyTypeAccessUnitDescription
labelstringR/WDevice label (default: "Test Device")
countintR/WEvent counter (increments with each stream tick)
temperaturedoubleR/W°CSimulated temperature (default: 22.5)
enabledboolR/WWhether the device is active
streamingboolR/WEnable/disable stream output
thresholddoubleR/WAlert threshold value (default: 50.0)
uptimedoubleRsSeconds since initialization
spectrumdouble[]RSample spectrum data (10 points, sine-wave based)
histogramint[]RSample histogram (8 random bins, 0–100)
logsstring[]RRecent log messages (last 20 entries)
statusobjectRComposite status: { label, enabled, temperature, count, uptime }

Actions

ActionArgsDescription
resetReset all values to defaults
setThreshold{ value: double }Set the alert threshold
configure{ key: string, value: string }Set a named config value (logged only)
loadProfile{ values: double[] }Load a numeric profile array
calculate{ a: double, b: double }Add two numbers and return the result

Streams

StreamDescription
dataJSON objects every 500ms: { timestamp, temperature, count, enabled }

Config Options

OptionTypeDefaultDescription
dashboardPortint9999Port for the built-in HTTP test dashboard
labelstring"Test Device"Initial label value
temperaturedouble22.5Initial temperature value

Example Connector

javascript
// workspace/connectors/test-device.js
export default {
  driver: "TestDevice",
  config: {
    label: "My Test",
    temperature: 25.0,
  },
  poll: ["temperature", "count", "enabled", "threshold"],
};

Example Script

javascript
const dev = connector("test-device");

await dev.temperature(50);
log.info(`Temperature: ${await dev.temperature()}°C`);

const result = await dev.calculate({ a: 3, b: 4 });
log.info(`3 + 4 = ${result}`);

await dev.reset();

Webcam

USB webcam/video capture using OpenCV. Streams base64-encoded JPEG frames at a configurable framerate.

Properties

PropertyTypeAccessUnitDescription
widthintR/WpxFrame width
heightintR/WpxFrame height
fpsintR/WTarget framerate
qualityintR/WJPEG quality (1–100)
brightnessintR/WBrightness (0–100)
contrastintR/WContrast (0–100)
flipHboolR/WHorizontal flip (mirror)
flipVboolR/WVertical flip
deviceintRCamera device index
streamingboolRWhether capture is active
resolutionstringRCurrent resolution string (e.g., "640x480")

Actions

ActionArgsDescription
startStart video capture and streaming
stopStop video capture and streaming
snapshotCapture a single frame, return as base64 JPEG

Streams

StreamDescription
videoBase64 JPEG frames at the configured FPS

Config Options

OptionTypeDefaultDescription
deviceint0Camera device index (0 = first camera)
widthint640Capture width in pixels
heightint480Capture height in pixels
fpsint15Target framerate
qualityint75JPEG quality (1–100)
brightnessint50Brightness (0–100)
contrastint50Contrast (0–100)

Example Connector

javascript
// workspace/connectors/webcam.js
export default {
  driver: "Webcam",
  config: {
    device: 0,
    width: 1280,
    height: 720,
    fps: 15,
    quality: 80,
  },
  poll: ["streaming", "resolution"],
};

Dashboard Integration

Display the webcam feed with a canvas widget:

json
{
  "type": "canvas",
  "config": {
    "label": "Webcam",
    "mode": "image",
    "stream": "webcam:video"
  }
}

Take a snapshot from a script:

javascript
const cam = connector("webcam");
await cam.start();
const frame = await cam.snapshot();  // base64 JPEG string
log.info(`Captured frame: ${frame.length} chars`);

Note: Requires OpenCV native libraries. Not available on Raspberry Pi (ARM64).


ONVIF (IP Camera)

ONVIF-compatible IP camera driver with live video streaming, snapshots, and PTZ (pan/tilt/zoom) control. Uses ONVIF SOAP for device control and OpenCV for RTSP stream capture.

Properties

PropertyTypeAccessUnitDescription
ipstringRCamera IP address
portintRONVIF service port
fpsintR/WTarget capture framerate
qualityintR/WJPEG encoding quality (1–100)
streamingboolRWhether RTSP capture is active
connectedboolRWhether camera is reachable
resolutionstringRStream resolution (e.g., "1920x1080")
profilesstring[]RAvailable media profile names

Actions

ActionArgsDescription
startConnect to RTSP stream and start video capture
stopStop RTSP capture and streaming
snapshotCapture a single frame, return as base64 JPEG
discoverFind ONVIF devices on the local network
getProfilesFetch available media profiles from the camera
ptzMove{ pan, tilt, zoom }PTZ relative move (values -1.0 to 1.0)
ptzStopStop PTZ movement
gotoPreset{ preset: string }Go to a PTZ preset position

Streams

StreamDescription
videoBase64 JPEG frames from RTSP stream at configured FPS

Config Options

OptionTypeDefaultDescription
ipstring""Camera IP address (required)
portint80ONVIF service port
usernamestring""Authentication username
passwordstring""Authentication password
profileint0Media profile index (0 = main stream)
fpsint10Target capture framerate (1–30)
qualityint75JPEG encoding quality (1–100)

Example Connector

javascript
// workspace/connectors/camera.js
export default {
  driver: "Onvif",
  config: {
    ip: "192.168.1.100",
    port: 80,
    username: "admin",
    password: "password",
    profile: 0,
    fps: 10,
  },
  poll: ["connected", "streaming", "resolution"],

  methods: {
    lookLeft:  { fn: c => c.ptzMove({ pan: -0.5, tilt: 0, zoom: 0 }), description: "Pan left" },
    lookRight: { fn: c => c.ptzMove({ pan: 0.5, tilt: 0, zoom: 0 }),  description: "Pan right" },
    zoomIn:    { fn: c => c.ptzMove({ pan: 0, tilt: 0, zoom: 0.5 }),  description: "Zoom in" },
    zoomOut:   { fn: c => c.ptzMove({ pan: 0, tilt: 0, zoom: -0.5 }), description: "Zoom out" },
    stopMove:  { fn: c => c.ptzStop(), description: "Stop PTZ movement" },
  },
};

Note: Requires OpenCV native libraries. Not available on Raspberry Pi (ARM64). If no IP is configured, use the discover action to find cameras on your network.


FileAccess

Sandboxed file I/O restricted to a single directory (typically workspace/data/). Allows scripts and AI to read and write files without exposing the full filesystem.

Properties

PropertyTypeAccessUnitDescription
basePathstringRResolved absolute base path
fileCountintRTotal number of files (recursive)
totalSizeBytesintRbytesTotal size of all files
existsboolRWhether the base directory exists

Actions

ActionArgsDescription
listFiles{ path? }List files in a directory (default: root)
listDirs{ path? }List subdirectories
readText{ path }Read a text file
writeText{ path, content }Write text to a file (creates parent dirs)
appendText{ path, content }Append text to a file
readBinary{ path }Read a binary file as base64
writeBinary{ path, content }Write base64-decoded bytes to a file
deleteFile{ path }Delete a file
rename{ from, to }Rename or move a file within the sandbox
fileInfo{ path }Get file metadata (name, size, created, modified, extension)
mkdir{ path }Create a directory (recursive)
deleteDir{ path }Delete an empty directory

Config Options

OptionTypeDefaultDescription
basePathstringRequired. Root directory for all file operations
maxFileSizeMBint10Maximum file size in MB for read/write
createIfMissingbooltrueCreate base directory if it doesn't exist

Security

All file paths are validated to prevent directory traversal attacks. Operations are confined to the configured basePath — you cannot read or write files outside it.

Example Connector

javascript
// workspace/connectors/files.js
export default {
  driver: "FileAccess",
  config: {
    basePath: "./data",
  },

  methods: {
    saveReading: {
      fn: async (c, args) => {
        const line = `${new Date().toISOString()},${args.value}\n`;
        return c.appendText({ path: "readings.csv", content: line });
      },
      description: "Append a timestamped reading to readings.csv",
    },
  },
};

Example Script

javascript
const files = connector("files");

// Write a text file
await files.writeText({ path: "log.txt", content: "Experiment started\n" });

// Append data
await files.appendText({ path: "log.txt", content: "Reading: 42.5\n" });

// Read it back
const content = await files.readText({ path: "log.txt" });
log.info(content);

// List files
const fileList = await files.listFiles({});
log.info(`Files: ${JSON.stringify(fileList)}`);

MqttBridge

MQTT broker bridge for IoT devices. Connects to any MQTT broker and bridges messages into Muxit as pollable properties and streams. Ideal for ESP32, Arduino, Home Assistant, Node-RED, and Tasmota devices.

For a complete setup guide, see MQTT & IoT Guide.

Properties

PropertyTypeAccessDescription
connectedboolRWhether connected to the broker
hoststringRBroker hostname
portintRBroker port
clientIdstringRMQTT client ID
messageCountintRTotal messages received
subscriptionsstring[]RActive topic subscriptions
topicsobjectRMap of topic → last received value
lastTopicstringRLast topic that received a message
lastPayloadstringRLast payload received

Actions

ActionArgsDescription
connectConnect to the MQTT broker
disconnectDisconnect from the broker
subscribe{ topic, qos? }Subscribe to a topic (supports wildcards: +, #)
unsubscribe{ topic }Unsubscribe from a topic
publish{ topic, payload, qos?, retain? }Publish a message to a topic
get{ topic }Get the last value received on a topic

Streams

StreamDescription
messageEvery received MQTT message: { topic, payload, qos, retain, timestamp }

Config Options

OptionTypeDefaultDescription
hoststring"127.0.0.1"Broker hostname or IP
portint1883Broker port
usernamestringAuthentication username
passwordstringAuthentication password
clientIdstring"muxit-{guid}"MQTT client ID
topicsstring[][]Topics to auto-subscribe on connect
qosint0Default QoS level (0, 1, or 2)
keepAliveint60Keep-alive interval in seconds

Example Connector

javascript
// workspace/connectors/mqtt.js
export default {
  driver: "MqttBridge",
  config: {
    host: "192.168.1.50",
    port: 1883,
    topics: ["sensors/#", "home/#"],
    qos: 0,
  },
  poll: ["connected", "messageCount", "lastTopic", "lastPayload"],

  methods: {
    connect:    [c => c.connect(), "Connect to the MQTT broker"],
    disconnect: [c => c.disconnect(), "Disconnect from the broker"],

    publish: {
      fn: (c, args) => c.publish({
        topic: args.topic,
        payload: typeof args.payload === "object"
          ? JSON.stringify(args.payload)
          : String(args.payload ?? ""),
        qos: args.qos ?? 0,
        retain: args.retain ?? false,
      }),
      description: "Publish a message to a topic",
    },

    getValue: {
      fn: (c, args) => c.get({ topic: typeof args === "string" ? args : args.topic }),
      description: "Get the last received value from a topic",
    },
  },

  properties: {
    temperature: {
      get: c => c.get({ topic: "sensors/temperature" }),
      description: "Temperature from MQTT sensor",
      poll: true,
    },
  },
};

Muxit — Hardware Orchestration Platform