Skip to content

Commit c08ce0c

Browse files
committed
Adding Node Red
1 parent 390d588 commit c08ce0c

6 files changed

Lines changed: 233 additions & 1 deletion

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,7 @@ pnpm-debug.log*
142142
# Storybook
143143
storybook-static/
144144

145+
# Node-RED
146+
.node-red/
147+
package-lock.json
148+

CLAUDE.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ Each device runs in its own worker thread with per-device RLock for thread safet
2020

2121
## Common Commands
2222

23+
### Starting the Full System
24+
25+
```bash
26+
# From repository root - starts everything (API, Frontend, Node-RED)
27+
./start.sh
28+
29+
# Services will be available at:
30+
# - Frontend: http://localhost:57666
31+
# - API Docs: http://localhost:57666/docs
32+
# - Node-RED: http://localhost:1880
33+
```
34+
2335
### Backend Development
2436

2537
```bash
@@ -32,7 +44,7 @@ pip install -r requirements.txt
3244
python -m benchmesh_service.main --config config.yaml
3345

3446
# Run with FastAPI (includes frontend auto-start)
35-
uvicorn benchmesh_service.api:app --host 0.0.0.0 --port 57666
47+
PYTHONPATH=src uvicorn benchmesh_service.api:app --host 0.0.0.0 --port 57666
3648

3749
# Run tests
3850
pytest tests/
@@ -44,6 +56,21 @@ pytest tests/test_serial_manager.py
4456
pytest -v tests/
4557
```
4658

59+
### Node-RED
60+
61+
```bash
62+
# From repository root
63+
64+
# Install Node-RED (first time only)
65+
npm install
66+
67+
# Start Node-RED standalone
68+
npm run start:nodered
69+
70+
# Node-RED runs on port 1880
71+
# Data stored in .node-red/ directory
72+
```
73+
4774
### Frontend Development
4875

4976
```bash

STARTUP.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# BenchMesh System Startup Guide
2+
3+
## Quick Start
4+
5+
To start the entire BenchMesh system (Backend, Frontend, and Node-RED):
6+
7+
```bash
8+
./start.sh
9+
```
10+
11+
This will launch:
12+
- **BenchMesh API & Frontend** on `http://localhost:57666`
13+
- **Node-RED Automations** on `http://localhost:1880`
14+
15+
Press `Ctrl+C` to stop all services.
16+
17+
## First Time Setup
18+
19+
### 1. Install Python Dependencies
20+
21+
```bash
22+
cd benchmesh-serial-service
23+
pip install -r requirements.txt
24+
cd ..
25+
```
26+
27+
### 2. Install Node.js Dependencies
28+
29+
```bash
30+
npm install
31+
```
32+
33+
### 3. Install Frontend Dependencies
34+
35+
```bash
36+
cd benchmesh-serial-service/frontend
37+
npm ci
38+
cd ../..
39+
```
40+
41+
## Individual Services
42+
43+
### Start Backend Only
44+
45+
```bash
46+
cd benchmesh-serial-service
47+
PYTHONPATH=src uvicorn benchmesh_service.api:app --host 0.0.0.0 --port 57666
48+
```
49+
50+
### Start Node-RED Only
51+
52+
```bash
53+
npm run start:nodered
54+
```
55+
56+
### Start Frontend Development Server
57+
58+
```bash
59+
cd benchmesh-serial-service/frontend
60+
npm run dev
61+
```
62+
63+
## Service Ports
64+
65+
| Service | Port | URL |
66+
|---------|------|-----|
67+
| Frontend | 57666 | http://localhost:57666 |
68+
| API | 57666 | http://localhost:57666/docs |
69+
| Node-RED | 1880 | http://localhost:1880 |
70+
71+
## Node-RED Data
72+
73+
Node-RED configuration and flows are stored in `.node-red/` directory in the repository root.
74+
75+
## Troubleshooting
76+
77+
### Port Already in Use
78+
79+
If you get "address already in use" errors:
80+
81+
```bash
82+
# Check what's using port 57666
83+
lsof -i :57666
84+
85+
# Check what's using port 1880
86+
lsof -i :1880
87+
88+
# Kill the process
89+
kill <PID>
90+
```
91+
92+
### Node-RED Not Starting
93+
94+
```bash
95+
# Check Node-RED logs
96+
cat .node-red/nodered.log
97+
98+
# Test Node-RED manually
99+
./node_modules/.bin/node-red --userDir ./.node-red --port 1880
100+
101+
# Check if Node-RED is installed
102+
ls -la node_modules/.bin/node-red
103+
```
104+
105+
### Frontend Not Building
106+
107+
```bash
108+
cd benchmesh-serial-service/frontend
109+
rm -rf node_modules
110+
npm ci
111+
npm run build
112+
```

benchmesh-serial-service/frontend/src/ui/MeasurementStatusBar.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export function MeasurementStatusBar() {
103103
padding: '8px 16px',
104104
display: 'flex',
105105
gap: '8px',
106+
alignItems: 'center',
106107
zIndex: 100
107108
}}>
108109
<button
@@ -141,6 +142,30 @@ export function MeasurementStatusBar() {
141142
>
142143
📈 Measurements Graph
143144
</button>
145+
<div style={{ marginLeft: 'auto' }}>
146+
<button
147+
onClick={() => {
148+
const nodeRedUrl = `${window.location.protocol}//${window.location.hostname}:1880`
149+
window.open(nodeRedUrl, '_blank', 'noopener,noreferrer')
150+
}}
151+
style={{
152+
padding: '6px 12px',
153+
background: 'rgba(255,68,68,.15)',
154+
color: '#ff6b6b',
155+
border: '1px solid rgba(255,68,68,.35)',
156+
borderRadius: '6px',
157+
cursor: 'pointer',
158+
fontSize: '12px',
159+
fontWeight: 600,
160+
display: 'flex',
161+
alignItems: 'center',
162+
gap: '6px'
163+
}}
164+
title="Open Node-RED Automations in new tab"
165+
>
166+
<span style={{ fontSize: '14px' }}>🔴</span> Node-RED Automations
167+
</button>
168+
</div>
144169
</div>
145170

146171
{recordOpen && (

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "benchmesh",
3+
"version": "0.1.0",
4+
"description": "BenchMesh - Lab Instrument Control System",
5+
"private": true,
6+
"scripts": {
7+
"start:nodered": "node-red --userDir ./.node-red",
8+
"start:all": "./start.sh",
9+
"postinstall": "echo 'Node-RED installed successfully. Run ./start.sh to start all services.'"
10+
},
11+
"dependencies": {
12+
"node-red": "^3.1.0"
13+
},
14+
"engines": {
15+
"node": ">=14.0.0"
16+
}
17+
}

start.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# BenchMesh Startup Script
4+
# Starts FastAPI backend, Frontend, and Node-RED
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
cd "$SCRIPT_DIR"
10+
11+
echo "🚀 Starting BenchMesh System..."
12+
13+
# Create node-red data directory if it doesn't exist
14+
mkdir -p .node-red
15+
16+
# Start Node-RED in background using local installation
17+
echo "📡 Starting Node-RED on port 1880..."
18+
./node_modules/.bin/node-red --userDir "$SCRIPT_DIR/.node-red" > .node-red/nodered.log 2>&1 &
19+
NODERED_PID=$!
20+
echo "Node-RED PID: $NODERED_PID"
21+
22+
# Start FastAPI backend with frontend
23+
echo "🔧 Starting BenchMesh API and Frontend..."
24+
cd benchmesh-serial-service
25+
PYTHONPATH=src uvicorn benchmesh_service.api:app --host 0.0.0.0 --port 57666 &
26+
API_PID=$!
27+
echo "API PID: $API_PID"
28+
29+
# Wait for services to start
30+
echo "⏳ Waiting for services to initialize..."
31+
sleep 3
32+
33+
echo ""
34+
echo "✅ BenchMesh System Started!"
35+
echo ""
36+
echo "📊 Frontend: http://localhost:57666"
37+
echo "🔴 Node-RED: http://localhost:1880"
38+
echo "📡 API: http://localhost:57666/docs"
39+
echo ""
40+
echo "Press Ctrl+C to stop all services"
41+
echo ""
42+
43+
# Trap Ctrl+C to stop all services
44+
trap "echo ''; echo '🛑 Stopping BenchMesh...'; kill $NODERED_PID $API_PID 2>/dev/null; exit 0" INT TERM
45+
46+
# Keep script running
47+
wait

0 commit comments

Comments
 (0)