25 lines
556 B
Go
25 lines
556 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"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})
|
|
}
|