A modular and configurable IoT agent designed to support a variety of services and operate on any Unix-based system. It enables secure communication and interaction with an MQTT backend. You can use IOT-Cloud or build your own MQTT backend.
- Modular service-based architecture
- Secure communication via MQTT
- Supports multiple services (Registration, Metrics, SSH, Updates, etc.)
- Configurable through YAML files
- Designed for low-resource IoT devices
git clone https://github.com/BenMeehan/iot-agent.git
cd iot-agent
Modify config/config.yaml
to suit your requirements. Ensure correct MQTT broker settings and service configurations.
go run cmd/agent/main.go
The agent is configured via config/config.yaml
. Each service has its own parameters, such as MQTT topics, intervals, and authentication details.
For detailed service-specific documentation, refer to the /docs
folder.
- Cross-Compilation: Simplify compilation for different architectures.
To add a new service, follow these steps:
-
Update Configuration
- Add the necessary configurations in
config/config.yaml
.
- Add the necessary configurations in
-
Create Service Logic
- Add a new file in
internal/services
(e.g.,new_service.go
). - Implement the service logic, following the pattern of existing services (e.g.,
heartbeat_service.go
).
- Add a new file in
- Handles the JWT based authentication at a central place.
- Retries Auth requests and refreshes expired tokens.
Detailed service documentation is available in the /docs
directory.
- Handles secure device registration via MQTT using JWT authentication.
- Implements exponential backoff for retries.
- Sends periodic heartbeat messages to indicate device activity.
- Collects system metrics (CPU, memory, disk usage, network in/out, process metrics) and sends them via MQTT.
- Executes commands on the IoT device and publishes output via MQTT.
- Retrieves device location via GPS or Google Geolocation API.
- Establishes a secure reverse SSH tunnel for remote access.
- Handles OTA (Over-the-Air) updates for firmware or software.
- Use camel case for variables and constants (e.g.,
deviceId
,maxRetries
). - Use snake case for files and folders (e.g.,
heartbeat_service.go
).
- Maintain clean and readable code.
- Comments should explain why something is done, not just what it does.
- Use structured logs with relevant context.
- Ensure logs provide meaningful information for debugging.
This project is licensed under the Non-Commercial Software License 1.0.