SPS30
1.1 SPS30 Software Handling Logic
Function: HandleSPS30Logic()
Purpose: Periodically reads the SPS30 sensor, updates LED visualization, generates JSON payloads for debug and network posting, and manages a post queue with retry logic.
1.2 Measurement Timing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
-
Explanation:
-
Reads the SPS30 sensor into an
SPS30_measurementstruct. spsData.availableindicates if the measurement is valid.- During warm-up (~5 s) or communication errors, data is unavailable, and the function exits.
- Updates
last_measurementtimestamp on success.
1.4 LED Update
1 | |
-
Explanation:
-
Converts PM2.5 mass concentration to an LED color.
- Only executed if update interval has elapsed (
can_update). - Provides real-time air quality visualization.
1.5 JSON Payloads
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
-
Explanation:
-
Builds a pretty-printed JSON for debug logging.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
-
Explanation:
-
Creates a compact JSON payload for network transmission.
1.6 Post Queue Management
1 2 3 4 5 6 | |
-
Explanation:
-
Adds payload to a queue for network posting.
- Ensures queue size does not exceed
kMaxQueueSize.
1 2 3 4 5 6 7 8 9 10 11 12 | |
-
Explanation:
-
Attempts to send each queued payload.
- Stops at the first failure; retries on next loop.
- Ensures reliable data transmission without blocking measurements.
1.7 Key Notes
- Warm-up behavior: SPS30 measurements are invalid for ~5 s after power-up;
spsData.availableensures no invalid data is used. - Non-blocking I²C: The function returns if intervals are not reached; communication itself does not block.
- Decoupled intervals: Measurement and LED/JSON updates are independently timed.
- Error handling: Logs warnings for failed reads and full queue but continues operation.