A Go-based application designed to integrate wearable device data using MQTT and InfluxDB. This project allows for real-time collection and storage of health-related metrics such as heart rate and oxygen levels.
- Real-time Data Processing: Collects health data from wearable devices via MQTT.
- InfluxDB Integration: Saves processed data into InfluxDB for efficient time-series data storage and analysis.
- Graceful Shutdown: Handles system signals for graceful application termination.
Go MQTT (Eclipse Paho) InfluxDB
Prerequisites:
Go (version 1.16 or higher)
InfluxDB
MQTT Broker (e.g., Mosquitto)
Create a .env file in the root directory and add your InfluxDB token:
INFLUXDB_TOKEN=your_influxdb_token
go run main.goRun the MQTT broker (if you haven't done so already):
If using Mosquitto, you can install it via Homebrew (on macOS) or download it from Mosquitto's official website
Run the application:
go run main.goThe application listens for MQTT messages published to the wearable/data topic.
Data format (JSON) expected in the payload:
{
"device_id": "device_199",
"heart_rate": 175,
"oxygen_level": 75
}The application processes the incoming data and saves it to InfluxDB.
To test the MQTT integration, you can publish test messages using an MQTT client or command-line tool. For example, using mosquitto_pub:
mosquitto_pub -h localhost -t wearable/data -m '{"device_id": "device_199", "heart_rate": 175, "oxygen_level": 75}'