API Reference
This page documents the final communication interfaces for our Weather Monitoring & Actuator Control system. It covers both the on-board UART message protocol (between PCBs) and the MQTT-based cloud API. All definitions conform to the EGR 314 class specification and our teamβs final message formats.
1. UART Message Protocol
1.1 Frame Structure
Each inter-PCB message is a fixed 64-byte frame:
| Byte(s) | Field | Description |
|---|---|---|
| 0β1 | Header | 0x41 0x5A |
| 2 | Source ID | uint8_t (βEβ=0x45, βKβ=0x4B, βSβ=0x53, βTβ=0x54) |
| 3 | Destination ID | uint8_t |
| 4β5 | Message Type | uint16_t (see types below) |
| 6β61 | Payload | Up to 56 bytes of data (type-specific encoding) |
| 62β63 | Footer | 0x59 0x42 |
1.2 Message Types & Payloads
- Set Water Flow
- Type:
0x0001 - Payload (bytes 6β7):
uint16_tflow rate in L/min Γ 100 (e.g., 10.5 L/min β 1050). -
Use: ESP32 or Web β Motor board.
-
Request Sensor Data
- Type:
0x0002 - Payload (byte 6):
uint8_tsensor ID (1 = DHT11, 2 = BMP180). -
Use: ESP32 β Sensor board.
-
Sensor Data Response
- Type:
0x0003 - Payload:
- Bytes 6β7:
uint16_ttemperature (Β°C Γ 100) - Bytes 8β9:
uint16_thumidity (% Γ 100) - Bytes 10β11:
uint16_twater flow (L/min Γ 100)
- Bytes 6β7:
-
Use: Sensor board β ESP32/HMI/Motor board.
-
LCD Update Command
- Type:
0x0004 - Payload (bytes 6β61): ASCII text string (max 56 chars) to display, e.g.
Temp: 25.5Β°C, Hum: 50.1%, Flow: 10.5 L/min -
Use: ESP32 β HMI board.
-
Cloud Update
- Type:
0x0005 - Payload (bytes 6β61): ASCII-encoded JSON (max 56 bytes), e.g.:
{"temp":2550,"hum":5010,"flow":1050} -
Use: ESP32 β Cloud gateway.
-
Error Message
- Type:
0x0006 - Payload:
- Byte 6:
uint8_tsubsystem ID (1 = PIC18, 2 = ESP32, 3 = Sensor, 4 = Pump, 5 = LCD) - Bytes 7β62: ASCII error description (max 56 chars)
- Byte 6:
- Use: Any board β ESP32/HMI/Web for fault reporting.
2. MQTT Cloud API
2.1 Topic Structure
| Topic | Direction | Payload Format | Description |
|---|---|---|---|
egr314/teamxyz/request/data |
Subscribed | empty | Trigger on-demand sensor poll |
egr314/teamxyz/response/data |
Published | JSON: { "temp":<int>, "hum":<int>, "flow":<int> } |
Periodic or on-demand sensor readings (Γ100 scaling) |
egr314/teamxyz/command/flow |
Subscribed | JSON: { "flow":<int> } |
Remote pump on/off commands (L/min Γ 100) |
egr314/teamxyz/status/motor |
Published | JSON: { "state":"on"|"off"|"rev" } |
Acknowledge of motor state changes |
egr314/teamxyz/status/error |
Published | JSON: { "subsys":<int>, "msg":"<str>" } |
Error notifications with subsystem ID and message |
2.2 Payload Field Definitions
- temp: Ambient temperature (Β°C Γ 100)
- hum: Relative humidity (% Γ 100)
- flow: Water flow rate (L/min Γ 100)
- state: Motor status string (one of
"on","off","rev") - subsys: Subsystem ID matching UART Error Message IDs
- msg: Human-readable error description
2.3 Quality & Safety
- All JSON messages are published with QoS 1 to ensure reliable delivery.
- Retained flag is off for request/command topics and on for status topics to support late-joining clients.
- Error topics use a distinct namespace (
status/error) to allow dashboard widgets to filter only fault conditions.
Note: All identifiers and topic names use lowercase and no spaces, per the class naming conventions. Scaling factors (Γ100) ensure integer-only encoding on resource-constrained MCUs.