feat: add endpoints for triggering sensor reads and actor writes

This commit is contained in:
2026-01-12 10:43:03 +01:00
parent ac9fd3ffdc
commit 66ba68c39f
3 changed files with 134 additions and 11 deletions
+3 -10
View File
@@ -2,23 +2,16 @@ 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 (h *Handler) 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()})
ts := time.Now().UTC().Format(time.RFC3339)
if !h.publishMQTT(c, gin.H{"type": "ping", "timestamp": ts}) {
return
}
c.JSON(http.StatusOK, gin.H{"timestamp": ts})
c.JSON(http.StatusOK, gin.H{"timestamp": ts, "topic": h.mqttTopic()})
}