-
Notifications
You must be signed in to change notification settings - Fork 0
Automation
BenchMesh integrates with Node-RED to provide powerful automation capabilities for your lab instruments.
Node-RED is a visual programming tool for wiring together hardware devices, APIs, and online services. With BenchMesh, you can:
- Create automated test sequences
- Log measurements to databases or files
- Build complex workflows with conditional logic
- Integrate with other lab systems
- Schedule periodic measurements
Node-RED runs on port 1880 when started via ./start.sh:
BenchMesh provides custom Node-RED nodes for instrument control:
- benchmesh-status - Get device status and measurements
- benchmesh-call - Call device methods (control instruments)
- benchmesh-instruments - List all configured instruments
BenchMesh nodes are automatically available when starting via ./start.sh.
To install manually in an existing Node-RED instance:
cd ~/.node-red
npm install /path/to/BenchMesh/benchmesh-nodered-nodesRestart Node-RED after installation.
The benchmesh-status node retrieves current device measurements:
- Drag benchmesh-status node to the flow
- Double-click to configure:
-
Device ID: Enter device ID from config (e.g.,
psu-1) -
API Base: Usually
http://localhost:57666
-
Device ID: Enter device ID from config (e.g.,
- Connect to a debug or processing node
- Deploy the flow
Output: Device status object with current measurements
Example output for PSU:
{
"voltage": 5.00,
"current": 0.15,
"output": true
}The benchmesh-call node executes device control commands:
- Drag benchmesh-call node to the flow
- Double-click to configure:
- Device ID: Target device
-
Method: Method name (e.g.,
set_voltage) - Arguments: JSON array of arguments
-
API Base:
http://localhost:57666
Example configurations:
Set PSU voltage to 5V:
- Device ID:
psu-1 - Method:
set_voltage - Arguments:
[5.0]
Set PSU output ON:
- Device ID:
psu-1 - Method:
set_output - Arguments:
[true]
Set voltage with channel:
- Device ID:
psu-dual - Method:
set_voltage - Arguments:
[5.0, {"ch": 1}]
The benchmesh-instruments node returns all configured devices:
- Drag benchmesh-instruments node to the flow
- Configure API base if needed
- Connect to processing nodes
- Deploy
Output: Array of instrument objects with ID, name, driver, and class information
Monitor PSU voltage every 5 seconds and send alerts if out of range:
[inject (5s)] → [benchmesh-status] → [function: check range] → [debug/alert]
- Inject node: Set to repeat every 5 seconds
-
benchmesh-status: Device ID =
psu-1 -
Function node:
const voltage = msg.payload.voltage; if (voltage < 4.9 || voltage > 5.1) { msg.payload = `Voltage out of range: ${voltage}V`; return msg; } return null;
- Debug node: Display alerts
Ramp PSU voltage and log current measurements:
[inject] → [function: ramp] → [benchmesh-call] → [delay 100ms] → [benchmesh-status] → [csv]
- Inject node: Manual trigger
-
Function node (ramp generator):
const voltages = [0, 1, 2, 3, 4, 5]; const messages = voltages.map(v => ({ payload: { device_id: "psu-1", method: "set_voltage", args: [v] } })); return [messages];
- benchmesh-call: Set voltage
- Delay: Wait for settling
- benchmesh-status: Read current
- CSV node: Log to file
Control PSU and monitor with DMM simultaneously:
[inject] → [benchmesh-call: PSU] → [delay] → [benchmesh-status: DMM] → [function: log]
- Set PSU voltage
- Wait for settling time
- Read DMM measurement
- Log correlated data
- Open Node-RED: http://localhost:1880
- Drag nodes from the left palette
- Wire nodes together by connecting output to input
- Double-click nodes to configure
- Click Deploy to activate
- Add debug nodes to outputs
- View output in the right sidebar (bug icon)
- Use catch nodes for error handling
- Enable node status messages
Export:
- Select nodes (or Ctrl+A for all)
- Menu → Export → Clipboard
- Save JSON to file
Import:
- Menu → Import → Clipboard
- Paste JSON
- Click Import
- User Guide: https://nodered.org/docs/user-guide/
- Node Catalog: https://flows.nodered.org/
- Tutorials: https://nodered.org/docs/tutorials/
You can also automate without Node-RED using the REST API directly.
import requests
import time
API_BASE = "http://localhost:57666"
# Set PSU voltage
requests.post(f"{API_BASE}/api/call", json={
"device_id": "psu-1",
"method": "set_voltage",
"args": [5.0]
})
# Wait for settling
time.sleep(0.5)
# Read status
response = requests.get(f"{API_BASE}/instruments")
instruments = response.json()
psu = next(i for i in instruments if i["id"] == "psu-1")
print(f"Voltage: {psu['status']['voltage']}V")API_BASE="http://localhost:57666"
# Set voltage to 3.3V
curl -X POST "$API_BASE/api/call" \
-H "Content-Type: application/json" \
-d '{"device_id":"psu-1","method":"set_voltage","args":[3.3]}'
# Get status
curl "$API_BASE/instruments" | jq '.[] | select(.id=="psu-1") | .status'- Error Handling: Always add catch nodes for error handling
- Rate Limiting: Don't poll too frequently (max 1-2 Hz recommended)
- Logging: Use file or database nodes for persistent logs
- Testing: Test flows with single inject before automation
- Documentation: Add comment nodes to document complex flows
- Backups: Export flows regularly
- Restart Node-RED after installation
- Check
~/.node-red/package.jsonincludes benchmesh nodes - View Node-RED startup logs for errors
- Verify BenchMesh backend is running (http://localhost:57666/docs)
- Check API base URL in node configuration
- Ensure firewall allows local connections
- Verify device ID matches configuration
- Check method name spelling (case-sensitive)
- Ensure arguments match method signature
- View debug output for error messages
Create a Node-RED dashboard for monitoring:
- Install dashboard:
npm install node-red-dashboard - Use dashboard nodes (gauge, chart, button)
- Access at http://localhost:1880/ui
Publish measurements to MQTT:
- Install MQTT nodes
- Configure MQTT broker
- Publish device status to topics
Store measurements in database:
- Install database nodes (MySQL, PostgreSQL, InfluxDB)
- Create logging flow
- Query historical data