subscribe: set client_id for MQTT subscriber to ensure unique identification

This commit is contained in:
2025-12-28 19:13:44 +01:00
parent fc3350efcc
commit 6fab87e35c
2 changed files with 16 additions and 15 deletions
+15 -15
View File
@@ -1,24 +1,24 @@
package handler
import (
"net/http"
"os"
"time"
"net/http"
"os"
"time"
"github.com/gin-gonic/gin"
"git.piskot.si/SeminarM2/lambdaiot-core/internal/mqtt"
"git.piskot.si/SeminarM2/lambdaiot-core/internal/mqtt"
"github.com/gin-gonic/gin"
)
// MQTTPing publishes the current timestamp to the configured MQTT topic
func MQTTPing(c *gin.Context) {
ts := time.Now().Format(time.RFC3339)
topic := os.Getenv("MQTT_TOPIC")
if topic == "" {
topic = "lambdaiot"
}
if err := mqtt.PublishDefault(topic, []byte(ts)); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"timestamp": ts})
ts := time.Now().Format(time.RFC3339)
topic := os.Getenv("MQTT_TOPIC")
if topic == "" {
topic = "lambdaiot"
}
if err := mqtt.PublishDefault(topic, []byte(ts)); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"timestamp": ts})
}