@machhub-dev/node-red-nodes 1.0.10-test → 1.0.11-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -153,12 +153,12 @@ class MQTTService {
153
153
  }
154
154
  }
155
155
  // Publishes a message to a specific topic
156
- publish(topic, message) {
156
+ publish(topic, message, qos = 2) {
157
157
  try {
158
158
  const payload = JSON.stringify(message);
159
159
  // console.log("Publishing to ", topic, ", with payload : ", payload)
160
160
  this.client.publish(topic, payload, {
161
- qos: 2, retain: true,
161
+ qos: qos, retain: true,
162
162
  properties: {
163
163
  contentType: "json",
164
164
  }
@@ -4,6 +4,7 @@
4
4
  color: '#c777f1',
5
5
  defaults: {
6
6
  name: { value: "" },
7
+ qos: { value: 2 },
7
8
  useConfigNode: { value: false }, // Toggle between JSON file and config node
8
9
  machhub: {
9
10
  value: "",
@@ -55,11 +56,16 @@
55
56
  } else {
56
57
  $machhub.val(node.machhub);
57
58
  }
59
+
60
+ // Sync QoS dropdown to saved value
61
+ const savedQos = node.qos !== undefined ? node.qos : 2;
62
+ $("#node-input-qos").val(String(savedQos));
58
63
  },
59
64
 
60
65
  oneditsave: function () {
61
66
  this.useConfigNode = $("#node-input-useConfigNode").is(":checked");
62
67
  this.machhub = $("#node-input-machhub").val();
68
+ this.qos = parseInt(String($("#node-input-qos").val()), 10);
63
69
  }
64
70
  });
65
71
  </script>
@@ -69,6 +75,14 @@
69
75
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
70
76
  <input type="text" id="node-input-name" placeholder="Name">
71
77
  </div>
78
+ <div class="form-row">
79
+ <label for="node-input-qos"><i class="fa fa-signal"></i> QoS</label>
80
+ <select id="node-input-qos" style="width: auto;">
81
+ <option value="0">0 - At most once</option>
82
+ <option value="1">1 - At least once</option>
83
+ <option value="2" selected>2 - Exactly once</option>
84
+ </select>
85
+ </div>
72
86
  <div class="form-row">
73
87
  <label for="node-input-useConfigNode" style="width: auto; padding-right: 10px;">
74
88
  <i class="fa fa-cog"></i> Use Config Node
@@ -20,6 +20,7 @@ function default_1(RED) {
20
20
  let isInitializing = false;
21
21
  let initializationPromise = null;
22
22
  node.useConfigNode = config.useConfigNode || false;
23
+ node.qos = (config.qos !== undefined && config.qos !== null) ? Number(config.qos) : 2;
23
24
  // Determine configuration source
24
25
  let machhubConfig;
25
26
  if (node.useConfigNode) {
@@ -75,7 +76,7 @@ function default_1(RED) {
75
76
  }
76
77
  Object.keys(msg.payload).forEach(function (key) {
77
78
  try {
78
- mqttService.publish(key, msg.payload[key]);
79
+ mqttService.publish(key, msg.payload[key], node.qos);
79
80
  }
80
81
  catch (error) {
81
82
  node.status({ fill: "red", shape: "dot", text: "Failed to publish to '" + key + "': " + error.toString() });
@@ -5,6 +5,7 @@
5
5
  defaults: {
6
6
  name: { value: "" },
7
7
  selectedTag: { value: "", required: true }, // Store selected tag
8
+ qos: { value: 2 },
8
9
  useConfigNode: { value: false }, // Toggle between JSON file and config node
9
10
  machhub: { value: "", type: "machhub-config" }
10
11
  },
@@ -50,6 +51,10 @@
50
51
  $machhub.val(node.machhub);
51
52
  }
52
53
 
54
+ // Sync QoS dropdown to saved value
55
+ const savedQos = node.qos !== undefined ? node.qos : 2;
56
+ $("#node-input-qos").val(String(savedQos));
57
+
53
58
  async function fetchTags() {
54
59
  try {
55
60
  // Get the selected machhub config
@@ -133,6 +138,7 @@
133
138
  this.useConfigNode = $("#node-input-useConfigNode").is(":checked");
134
139
  this.machhub = $("#node-input-machhub").val();
135
140
  this.selectedTag = $("#node-input-selectedTag").val(); // Save selected value
141
+ this.qos = parseInt(String($("#node-input-qos").val()), 10);
136
142
  }
137
143
  });
138
144
  </script>
@@ -147,6 +153,14 @@
147
153
  <input type="text" id="node-input-selectedTag" list="node-input-selectedTag-datalist" placeholder="Start typing or select a tag...">
148
154
  <datalist id="node-input-selectedTag-datalist"></datalist>
149
155
  </div>
156
+ <div class="form-row">
157
+ <label for="node-input-qos"><i class="fa fa-signal"></i> QoS</label>
158
+ <select id="node-input-qos" style="width: auto;">
159
+ <option value="0">0 - At most once</option>
160
+ <option value="1">1 - At least once</option>
161
+ <option value="2" selected>2 - Exactly once</option>
162
+ </select>
163
+ </div>
150
164
  <div class="form-row">
151
165
  <label for="node-input-useConfigNode" style="width: auto; padding-right: 10px;">
152
166
  <i class="fa fa-cog"></i> Use Config Node
@@ -22,6 +22,7 @@ function default_1(RED) {
22
22
  const node = this;
23
23
  node.name = config.name;
24
24
  node.selectedTag = config.selectedTag;
25
+ node.qos = (config.qos !== undefined && config.qos !== null) ? Number(config.qos) : 2;
25
26
  node.useConfigNode = config.useConfigNode || false;
26
27
  let machhubConfig;
27
28
  if (node.useConfigNode) {
@@ -74,7 +75,7 @@ function default_1(RED) {
74
75
  node.status({ fill: "red", shape: "dot", text: "MQTT service not initialized" });
75
76
  return;
76
77
  }
77
- yield mqttService.publish(node.selectedTag, msg.payload);
78
+ yield mqttService.publish(node.selectedTag, msg.payload, node.qos);
78
79
  node.status({ fill: "green", shape: "dot", text: "Payload Sent" });
79
80
  }
80
81
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/node-red-nodes",
3
- "version": "1.0.10-test",
3
+ "version": "1.0.11-test",
4
4
  "description": "Node-RED API for MACHHUB EDGE",
5
5
  "scripts": {
6
6
  "build": "yarn clean && npx tsc && yarn copy-files",