Node-RED Deployment Guide
This guide covers deploying and using Node-RED with Tafy Studio for visual robot programming.
Local Development Setup
Prerequisites
- k3d installed (
brew install k3d) - kubectl installed (
brew install kubectl) - helm installed (
brew install helm)
Quick Start
-
Create k3s cluster:
k3d cluster create tafy-dev --servers 1 --agents 2 -
Deploy NATS:
helm repo add nats https://nats-io.github.io/k8s/helm/charts/
helm repo update
helm install nats nats/nats -f charts/nats/values.yaml \
--create-namespace --namespace tafy-system -
Deploy Node-RED:
helm install node-red ./charts/node-red \
--namespace tafy-system -
Access Node-RED UI:
kubectl port-forward service/node-red-tafy-node-red 1880:1880 -n tafy-systemThen open http://localhost:1880 in your browser.
Creating Robot Control Flows
Basic Motor Control Flow
-
Import Example Flow:
- Copy the contents of
packages/node-red-contrib-tafy/examples/motor-teleop-flow.json - In Node-RED UI, click menu → Import → Clipboard
- Paste and import
- Copy the contents of
-
Key Components:
- Inject Nodes: Trigger motor commands (Forward, Rotate, Stop)
- HAL Envelope Function: Wraps commands in HAL format
- MQTT Out: Publishes to NATS (configured as MQTT broker)
- MQTT In: Subscribes to motor telemetry
- Dashboard Gauges: Visual feedback of motor speeds
NATS Connection
Node-RED connects to NATS using the MQTT protocol:
- Broker:
nats.tafy-system.svc.cluster.local - Port: 4222
- Topics: HAL subjects like
hal.v1.motor.cmd
HAL Message Format
Motor commands follow the HAL envelope format:
{
"hal_major": 1,
"hal_minor": 0,
"schema": "tafylabs/hal/motor/differential/1.0",
"device_id": "esp32-a4cf12",
"caps": ["motor.differential:v1.0"],
"ts": "2024-03-14T10:30:00.000Z",
"payload": {
"linear_meters_per_sec": 0.5,
"angular_rad_per_sec": 0
}
}
Custom Tafy Nodes
The custom Node-RED nodes for Tafy are in development and will provide:
- tafy-nats-pub/sub: Native NATS publish/subscribe
- tafy-motor-control: Motor command helper
- tafy-sensor-range: Range sensor data handler
- tafy-device-discovery: Automatic device discovery
- tafy-gamepad: Gamepad input for teleop
To build and use custom nodes:
cd packages/node-red-contrib-tafy
docker build -t tafystudio/node-red-tafy:latest .
Then enable in charts/node-red/values.yaml:
customNodes:
enabled: true
repository: tafystudio/node-red-tafy
tag: "latest"
Production Deployment
For production:
- Enable authentication in
values.yaml - Use persistent storage with backup
- Configure ingress for external access
- Enable NATS authentication
- Set resource limits appropriately
Troubleshooting
Node-RED Pod Not Starting
Check service account:
kubectl get sa -n tafy-system
kubectl describe deployment node-red-tafy-node-red -n tafy-system
Cannot Connect to NATS
Verify NATS is running:
kubectl get pods -n tafy-system
kubectl logs nats-0 -n tafy-system
Test connection:
kubectl exec -it nats-box-xxx -n tafy-system -- nats sub ">"
Flows Not Persisting
Check PVC:
kubectl get pvc -n tafy-system
kubectl describe pvc node-red-tafy-node-red -n tafy-system
Dashboard Access
Node-RED Dashboard is available at: http://localhost:1880/ui
Features:
- Real-time motor telemetry
- Joystick control widget
- Sensor data visualization
- System health monitoring
Next Steps
- Connect ESP32 robot to same network
- Configure ESP32 with NATS server address
- Create teleop flow with gamepad input
- Add obstacle avoidance logic
- Implement autonomous behaviors