Overview
The Invernaderos API broadcasts real-time greenhouse sensor data through WebSocket topics using the STOMP protocol. This event-driven architecture ensures all connected clients receive instant updates when new sensor readings arrive.Available Topics
/topic/greenhouse/messages
Purpose: Real-time greenhouse sensor data broadcasting
Message Frequency: Varies based on sensor configuration (typically every 5 seconds)
Message Format: RealDataDto JSON object with 22 sensor fields
Subscription Example:
/topic/greenhouse/statistics
Purpose: Aggregated greenhouse statistics and analytics
Message Frequency: On-demand or periodic updates
Use Case: Dashboard summaries, trend analysis, alerts
Subscription Example:
Message Format: RealDataDto
All sensor readings are broadcast asRealDataDto objects containing 22 fields:
Field Descriptions
Temperature & Humidity Fields
Temperature & Humidity Fields
Temperature Fields (3 greenhouses):
TEMPERATURA INVERNADERO 01/02/03: Temperature readings in Celsius- Range: Typically 15-30°C
- Unit: °C
HUMEDAD INVERNADERO 01/02/03: Relative humidity percentage- Range: 40-80%
- Unit: %
Field names use SPACES for temperature/humidity (e.g.,
"TEMPERATURA INVERNADERO 01") to match the physical hardware output format.Sector Control Fields
Sector Control Fields
12 Sector Fields (4 sectors per greenhouse):
INVERNADERO_01_SECTOR_01throughINVERNADERO_03_SECTOR_04- Values: Binary (0 = off, 1 = on)
- Purpose: Irrigation or climate control zones
INVERNADERO_01_SECTOR_01)Extractor Fields
Extractor Fields
3 Extractor Fields (1 per greenhouse):
INVERNADERO_01_EXTRACTOR,INVERNADERO_02_EXTRACTOR,INVERNADERO_03_EXTRACTOR- Values: Binary (0 = off, 1 = on)
- Purpose: Ventilation fan status
Metadata Fields
Metadata Fields
timestamp: ISO 8601 timestamp of sensor readinggreenhouseId: UUID identifier for the greenhousetenantId: Tenant identifier for multi-tenant setupsRESERVA: Reserved field for future use
Event-Driven Broadcasting
Architecture Flow
The WebSocket broadcasting uses Spring’s event-driven architecture:Message Processing
MqttMessageProcessor processes the payload:- Parses JSON to
RealDataDto - Caches in Redis
- Saves to TimescaleDB
- Publishes
GreenhouseMessageEvent
Decoupled Design: The MQTT processing and WebSocket broadcasting are decoupled through Spring Events, preventing MQTT message handling from blocking on WebSocket operations.
Subscription Examples
- Vanilla JavaScript
- React Component
- Vue.js Component
Filtering and Processing Messages
Filter by Greenhouse ID
Filter by Tenant ID
Extract Specific Sensors
Message Handling Best Practices
Parse Safely
Handle Missing Fields
Throttle UI Updates
Buffer Data
Troubleshooting
No messages received
No messages received
Possible causes:
- Not subscribed to correct topic:
/topic/greenhouse/messages - No sensor data being published (check MQTT broker)
- Connection dropped (check
connectedstatus)
Message parsing errors
Message parsing errors
Cause: Unexpected JSON format or encoding issuesSolution:
Missing field values (null/undefined)
Missing field values (null/undefined)
Cause: Optional sensor fields may be null if sensor is offline or not configuredSolution: Use null coalescing or default values
Next Steps
STOMP Setup
Configure WebSocket connection
REST API
Query historical sensor data