A real-time, interactive React dashboard for monitoring plant sensor data with WebSocket integration and cookie-based authentication.
The Plant Monitoring System PC Dashboard displays live sensor data (moisture, temperature, humidity, light) from IoT devices monitoring plants/greenhouses. It provides real-time alerts, historical trending, and device control capabilities.
Key Features:
- β Real-time sensor data updates via WebSocket
- β Cookie-based HttpOnly authentication (secure)
- β Multiple simultaneous alerts with configurable thresholds
- β Interactive charts with historical trending
- β Responsive design (desktop, tablet, mobile)
- β Device management and selection
- β Threshold configuration panel
- β CSV export for analysis
- β Graceful fallback with mock data when API unavailable
- β Seasonal visual effects
- Node.js 16+
- npm 7+
# Install dependencies
npm install
# Start development server
npm run dev
# Open browser to http://localhost:5173npm run build
npm run preview # Preview production build locallyThe application uses Cookie-Based HttpOnly Authentication for enhanced security.
-
Login (
POST /get-token)- Send email and secretKey in request body
- Server returns 200 OK with no response body
- JWT and Refresh Token are set as HttpOnly cookies automatically
-
API Requests
- All requests include
withCredentials: true - Browser automatically sends cookies with each request
- No manual token attachment needed
- All requests include
-
Token Refresh (
GET /get-new-token)- Server uses Refresh Token from cookie
- New tokens set as cookies automatically
- Transparent to the application
-
WebSocket Connection
- Connect to
wss://api.protonestconnect.co/ws - No token query parameter needed
- Browser sends cookies with WebSocket handshake
- Connect to
# API Configuration (includes /user path)
VITE_API_BASE_URL=https://api.protonestconnect.co/api/v1/user
# WebSocket Configuration
VITE_WS_URL=wss://api.protonestconnect.co/ws
# Device ID
VITE_DEVICE_ID=your-device-id
# Auto-login credentials (optional)
VITE_USER_EMAIL=your-email@example.com
VITE_USER_SECRET=your-secretKeyLive WebSocket updates for 6 key metrics:
- Moisture (0-100%) - Soil/substrate moisture level with auto pump trigger
- Temperature (Β°C) - Ambient temperature monitoring
- Humidity (0-100%) - Air humidity tracking
- Light (lux) - Light intensity measurement
- Battery (0-100%) - Device battery level
- Pump Status - Real-time pump state (ON/OFF) with mode indicator (auto/manual)
Intelligent pump control based on configurable moisture thresholds:
- Auto Mode - Automatically turns pump ON when moisture < minimum threshold (default: 20%) via HTTP state update
- Auto Mode - Pump automatically turns OFF when moisture β₯ minimum threshold
- Manual Mode Notification - When moisture drops below minimum in manual mode, a notification alerts the user to turn on the pump
- Mode Sync - Mode changes (auto/manual) sent to device via HTTP
pmc/modetopic - HTTP API Flow - PC β
/update-state-details(topic:pmc/pump) β Backend β MQTT β Device β Confirmation β WebSocket β UI Update
User-controlled pump operation with instant feedback:
- Toggle Control - One-click pump ON/OFF from settings panel
- Mode Tracking - Commands sent with
mode: "manual"to distinguish from automation - Status Display - Real-time pump status with color coding (green=ON, red=OFF)
- Loading States - Visual feedback during command processing
Interactive charts showing sensor trends over time:
- Flexible Time Ranges - Presets: 1min, 5min, 15min, 30min, 1h, 3h, 6h, 12h, 24h (default: 24h)
- Custom Ranges - User-definable time range and interval (e.g., last 7h with 1min interval)
- Interval Options - Auto, 1min, 5min, 15min, 30min, 1h
- Multi-Line Chart - All sensors on one graph with Recharts
- CSV Export - Download data for external analysis
- Responsive Design - Zoom, pan, and tooltip interactions
Fully customizable alert and automation thresholds:
- Moisture Thresholds - Min/max for pump automation (default: 20%-70%)
- Temperature Thresholds - Min/max for temperature alerts (default: 10Β°C-35Β°C)
- Humidity Thresholds - Min/max for humidity alerts (default: 30%-80%)
- Light Thresholds - Min/max for light alerts (default: 200-1000 lux)
- Battery Threshold - Minimum battery level alert (default: 20%)
- Auto Mode Toggle - Enable/disable automated pump control
- LocalStorage Persistence - Settings saved per device
Seamless switching between multiple IoT devices:
- Device Selection - Dropdown to switch active device
- Per-Device Settings - Each device has its own threshold configuration
- WebSocket Resubscription - Automatic topic switching when device changes
- Historical Data Reload - Chart data refreshed for new device
ββββββββββββββββ MQTT Publish ββββββββββββββββ
β IoT Device β ββββββββββββββββββ β Backend β
β (MQTTX) β β MQTT Broker β
ββββββββββββββββ ββββββββ¬ββββββββ
β β
β β WebSocket
β MQTT Subscribe β (Cookie Auth)
β β
β ββββββββββββββββ
β ββββ HTTP API βββββββββ β Frontend β
β (with cookies) β Dashboard β
βββββββββββββββββββββββββββββββ (React) β
Device Confirmation ββββββββββββββββ
1. User Login (or Auto-Login from ENV)
POST /get-token β Sets HttpOnly Cookies
β
2. WebSocket Connection
Connect to wss://...ws (cookies sent automatically)
β
3. API Requests
All requests include withCredentials: true
Cookies sent automatically
β
4. Token Refresh (on 400 "Invalid token")
GET /get-new-token β New cookies set automatically
src/
βββ Components/ # React Components
β βββ Dashboard.jsx # Main dashboard with sensor display
β βββ Header.jsx # Navigation bar with device selector
β βββ StatusBar.jsx # Tab navigation component
β βββ DeviceSettingsPage.jsx # Full device settings page
β βββ HistoricalChartTest.jsx # Recharts visualization
β βββ ErrorBoundary.jsx # Error handling wrapper
β βββ ... (reusable components)
β
βββ Service/ # API & Communication Layer
β βββ api.js # Axios client with cookie auth
β βββ authService.js # Login/session management
β βββ deviceService.js # Device & sensor data API
β βββ webSocketClient.js # STOMP WebSocket client
β
βββ Context/ # React Context
β βββ AuthContext.jsx # Authentication state management
β βββ NotificationContext.jsx # App-wide notification system
β
βββ App.jsx # Main app with WebSocket integration
βββ main.jsx # React entry point
βββ index.css # Global styles
- React 18.2.0 - Component-based UI framework
- Vite 7.2.2 - Fast build tool and dev server
- React Router 6.20.0 - Client-side routing
- Tailwind CSS 3.4.0 - Utility-first CSS framework
- Lucide React 0.263.1 - Modern icon library
- @stomp/stompjs 7.2.1 - WebSocket STOMP protocol
- Axios 1.6.2 - HTTP client with cookie support
- Recharts 2.10.3 - Interactive charting library
- WebSocket Server - STOMP over WebSocket for real-time data
- REST API - HTTP endpoints with cookie authentication
- MQTT Broker - Device communication protocol
- HttpOnly Cookies - Secure token storage
Base URL: https://api.protonestconnect.co/api/v1/user
WebSocket URL: wss://api.protonestconnect.co/ws
| Endpoint | Method | Description |
|---|---|---|
/get-token |
POST | Login - sets HttpOnly cookies |
/get-new-token |
GET | Refresh tokens via cookie |
| Endpoint | Method | Description |
|---|---|---|
/get-stream-data/device |
GET | Fetch all historical data for device |
/get-stream-data/device/topic |
POST | Fetch historical data for specific topic |
/get-state-details/device |
POST | Get current device state |
/update-state-details |
POST | Send commands to device (pump, mode) |
| Topic | Description |
|---|---|
pmc/temperature |
Temperature sensor data |
pmc/humidity |
Humidity sensor data |
pmc/moisture |
Soil moisture sensor data |
pmc/light |
Light intensity data |
pmc/battery |
Battery level data |
pmc/pump |
Pump control commands (ON/OFF) |
pmc/mode |
Mode state updates (auto/manual) |
- Stream Data:
/topic/stream/{deviceId}- All sensor updates - State Data:
/topic/state/{deviceId}- Pump/mode status updates
| Document | Purpose |
|---|---|
| MQTTX_TESTING_GUIDE.md | π§ͺ MQTT testing with MQTTX client |
| PROTONEST_SETUP.md | βοΈ ProtoNest platform configuration |
| WEBSOCKET_IMPLEMENTATION.md | π WebSocket client details |
| README.md | π This documentation |
- Verify you're authenticated (login succeeded)
- Check browser console for cookie-related errors
- Ensure
withCredentials: truein requests - For CORS issues, verify server allows credentials
- On 400 "Invalid token" error, automatic refresh is attempted
- If refresh fails, user is logged out
- Re-login to get new session cookies
- Check auto mode enabled in settings
- Verify device ownership
- Check console for API errors
- Verify WebSocket connection status
npm run deploynpm install -g vercel
verceldocker build -t plant-monitoring:latest .
docker run -p 80:80 plant-monitoring:latestStatus: Production Ready
Last Updated: February 2026
Version: 2.1.0 (Cookie-Based Auth + pmc/ Topics)
Auth Method: HttpOnly Cookies
Issues: Open GitHub issue with console logs
Questions: Use GitHub Discussions