Skip to content

Implement MQTT IoT telemetry client #560

Description

@Oluwaseyi89

Summary

Implement MQTT IoT telemetry client — pkg/iot/mqtt_client.go is future-gated and no soil sensor or methane detector data can flow in via MQTT broker.

Social Media Link

Let's collaborate on Discord. And ensure to star our repo.

Problem Statement

Confirmed in project-portal/project-portal-backend/pkg/iot/mqtt_client.go and project-portal/project-portal-backend/internal/monitoring:

  1. File is entirely stubbed out: mqtt_client.go contains only //go:build future / // +build future tags, package iot, and // Implementation pending — zero exported types or functions.

  2. No MQTT client library dependency: No eclipse/paho.mqtt.golang (or equivalent) import exists in go.mod for this package.

  3. No broker connection configuration: No MQTT_BROKER_URL, TLS certificate, or client-ID configuration surfaced in internal/config for connecting to a broker.

  4. No topic subscription model: There is no defined topic scheme (e.g. sensors/{project_id}/{sensor_type}) for soil moisture, methane, or biomass sensor payloads.

  5. No payload decoding: No struct or JSON schema exists to decode MQTT sensor payloads into monitoring.SystemMetric or a project-specific telemetry record.

  6. internal/monitoring/processing/biomass_estimator.go has no ingestion source: The biomass estimator (also future-gated per the backlog) has no upstream sensor feed since MQTT ingestion doesn't exist.

  7. No QoS or reconnect handling: Since there is no client, there is naturally no at-least-once QoS handling or automatic reconnect-with-backoff on broker disconnects.

  8. No TLS/mutual-auth support: No certificate-based device authentication path exists for IoT devices connecting to the broker.

  9. No persistence of raw telemetry: There is no table or repository method for storing raw sensor readings before they are aggregated into monitoring metrics.

  10. No backpressure or buffering: A stub means there is also no bounded queue or worker pool to absorb bursts of sensor messages without blocking the broker connection.

  11. No health/status reporting: MQTT connection health is not exposed on the /health endpoint or as a Prometheus-style metric.

  12. No test coverage: No mqtt_client_test.go exists, and no integration test exercises a local/mock broker.

Required Changes

  1. Remove the //go:build future tag and implement a real MQTT client using github.com/eclipse/paho.mqtt.golang.

  2. Add MQTT_BROKER_URL, MQTT_CLIENT_ID, and TLS certificate configuration to internal/config.

  3. Define topic subscription patterns for soil moisture, methane, and biomass sensor data.

  4. Define payload structs and JSON decoding for each supported sensor type.

  5. Wire decoded telemetry into the monitoring ingestion pipeline (internal/monitoring/ingestion) so it becomes queryable SystemMetric data.

  6. Add automatic reconnect with exponential backoff on broker disconnect.

  7. Add TLS mutual-auth support for device certificate-based authentication.

  8. Add a bounded in-memory queue (or worker pool) to buffer bursts of incoming sensor messages.

  9. Add a repository method to persist raw sensor readings before aggregation.

  10. Expose MQTT connection health via the /health endpoint.

  11. Add structured logging for connect/disconnect/subscribe events.

  12. Add mqtt_client_test.go with unit tests against a mocked or embedded test broker.

Acceptance Criteria

  1. mqtt_client.go compiles in normal (non-future) builds.
  2. The client connects to a configured MQTT broker and subscribes to defined sensor topics.
  3. Incoming sensor payloads are decoded and persisted as raw telemetry.
  4. Decoded telemetry flows into the monitoring ingestion pipeline as queryable metrics.
  5. The client reconnects automatically with backoff after a broker disconnect.
  6. TLS mutual-auth is supported for device connections.
  7. MQTT connection status is visible via the /health endpoint.
  8. Message bursts are buffered without blocking the broker connection.
  9. Unit tests cover connect, subscribe, decode, and reconnect behavior.
  10. No //go:build future tag remains on this file.

Directory to Work on:

project-portal/project-portal-backend/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AWSThis issue integrates AWS services.backendThis issue is about building backend API services.ginThis issue is to be implemented with the `golang` `gin` framework for backend APIs.golangThis issue is to be implemented with `golang` programming language.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions