| Topic |
Published Data |
+ Sub-Count |
{{#topics}}
- | {{.getKey()}} |
- {{.getValue()}} |
+ {{.topicName}} |
+ {{.value}} |
+ {{.getSubscriberCount()}} |
{{/topics}}
diff --git a/plugins/hal-mqtt/src/se/hal/plugin/mqtt/page/MqttOverviewPage.java b/plugins/hal-mqtt/src/se/hal/plugin/mqtt/page/MqttOverviewPage.java
index d43d1017..2fd26a4d 100644
--- a/plugins/hal-mqtt/src/se/hal/plugin/mqtt/page/MqttOverviewPage.java
+++ b/plugins/hal-mqtt/src/se/hal/plugin/mqtt/page/MqttOverviewPage.java
@@ -1,3 +1,27 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2025 Ziver Koc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
package se.hal.plugin.mqtt.page;
import se.hal.HalContext;
@@ -17,7 +41,8 @@ import java.util.Map;
public class MqttOverviewPage extends HalWebPage implements MqttSubscriptionListener {
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/mqtt_overview.tmpl";
- private Map
topicData = new HashMap<>();
+ private MqttBroker broker;
+ private Map topicData = new HashMap<>();
public MqttOverviewPage() {
@@ -25,14 +50,18 @@ public class MqttOverviewPage extends HalWebPage implements MqttSubscriptionList
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "MQTT Overview").setWeight(9_000);
HalMqttController controller = HalAbstractControllerManager.getController(HalMqttController.class);
- MqttBroker broker = controller.getBroker();
+ broker = controller.getBroker();
broker.addGlobalSubscriber(this);
}
@Override
public synchronized void dataPublished(String topic, byte[] data) {
- topicData.put(topic, new String(data, StandardCharsets.UTF_8));
+ if (!topicData.containsKey(topic)) {
+ topicData.put(topic, new TopicDTO(topic));
+ }
+
+ topicData.get(topic).value = new String(data, StandardCharsets.UTF_8);
}
@Override
@@ -42,8 +71,26 @@ public class MqttOverviewPage extends HalWebPage implements MqttSubscriptionList
Map request)
throws Exception {
+ if (request.containsKey("topic") && request.containsKey("value")) {
+ broker.publish(request.get("topic"), request.get("value"));
+ }
+
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
- tmpl.set("topics", topicData.entrySet());
+ tmpl.set("topics", topicData.values());
return tmpl;
}
+
+
+ public class TopicDTO {
+ public String topicName;
+ public String value;
+
+ public TopicDTO(String topicName) {
+ this.topicName = topicName;
+ }
+
+ public int getSubscriberCount() {
+ return broker.getSubscriberCount(topicName);
+ }
+ }
}