SMART Project – MQTT Protocol Stack Documentation

Date: 2025-06-23

Status: MQTT-based Shelly Gateway → Server bridge is operational

1. Architecture Overview

The current protocol stack consists of:

2. Shelly → Gateway (Local MQTT Broker)

The gateway starts a local Aedes MQTT broker. The Shelly Pro 3EM publishes JSON messages to this broker.

Example payload:

{
  "src": "shellypro3em-a0dd6c9f4d5c",
  "dst": "shellypro3em-a0dd6c9f4d5c/events",
  "method": "NotifyStatus",
  "params": {
    "ts": 1750612659.62,
    "em:0": {
      "voltage": 234.2,
      "current": 2.09,
      "act_power": 100.9
    }
  }
}

The gateway flattens this structure and stores it as the most recent buffer.

3. Gateway → Server (MQTTS)

The gateway connects to mqtts://nippari.com:60012 using TLS (no certificate check).

Once connected, the gateway:

4. Flattening Logic

All nested objects in params["em:0"] are flattened using prefix notation:

{
  "src": "...",
  "dst": "...",
  "method": "NotifyStatus",
  "ts": 1750612659.62,
  "em:0_voltage": 234.2,
  "em:0_current": 2.09,
  ...
}

This ensures the buffer is easy to parse and index.

5. Protocol Summary

6. Next Steps

  1. Store incoming messages to PostgreSQL database on the server
  2. Implement rate-limiting and history buffer for each Shelly
  3. Add config broadcast mechanism from server to gateway