frugal-iot-client 2.0.4 → 2.0.5

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.
Files changed (3) hide show
  1. package/core.js +8 -5
  2. package/graph.js +1 -1
  3. package/package.json +1 -1
package/core.js CHANGED
@@ -1818,8 +1818,13 @@ class MqttTopic {
1818
1818
  // Creation & initialization =========
1819
1819
  constructor() {
1820
1820
  this.data = []; // Tracks previous values of this topic - used for graphing
1821
- this.qos = 0; // Default to send and not care if received
1822
- this.retain = false; // Default to not retain
1821
+ /* For what this publishes - "set/..." commands to a node. QoS 1 so the broker holds them for a
1822
+ * node that is asleep, until it reconnects to its persistent session; QoS 0 is dropped for anyone
1823
+ * not connected at that moment. Not retained: the node writes a set value to its own flash, and
1824
+ * a retained command would be replayed at every fresh subscribe, e.g. each reboot.
1825
+ */
1826
+ this.qos = 1;
1827
+ this.retain = false;
1823
1828
  this.state = {}; // Dynamic state: value, groupMt roll-up fields (now_wired, out_wired, on, etc.)
1824
1829
  }
1825
1830
 
@@ -2021,8 +2026,6 @@ class MqttTopic {
2021
2026
  case 'toggle':
2022
2027
  //noinspection JSUnresolvedVariable
2023
2028
  elx = el('mqtt-toggle', {color: this.color, graphable: this.graphable });
2024
- this.retain = true;
2025
- this.qos = 1;
2026
2029
  break;
2027
2030
  case 'bar':
2028
2031
  // noinspection JSUnresolvedReference
@@ -2305,7 +2308,7 @@ class MqttTopic {
2305
2308
  }
2306
2309
  publishWired(val) {
2307
2310
  console.log("Publishing ", this.topicWiredPath, val, this.retain ? "retain" : "", this.qos ? `qos=${this.qos}` : "");
2308
- mqtt_client.publish(this.topicWiredPath, val, {retain: true, qos: 1});
2311
+ mqtt_client.publish(this.topicWiredPath, val, {retain: this.retain, qos: this.qos});
2309
2312
  }
2310
2313
  // Adds historical data to the chart - typically chart updates data for each line, then updates the chart.
2311
2314
  addDataFrom(filename, first, cb) {
package/graph.js CHANGED
@@ -503,7 +503,7 @@ customElements.define('mqtt-graphdataset', MqttGraphDataset);
503
503
  // This event is used by custom dashboards to send
504
504
  document.addEventListener('frugaliot:publish', ({detail}) => {
505
505
  if (mqtt_client && detail.topic && detail.value !== undefined)
506
- mqtt_client.publish(detail.topic, String(detail.value), detail.options || {retain: true, qos: 1});
506
+ mqtt_client.publish(detail.topic, String(detail.value), detail.options || {retain: false, qos: 1}); // As for MqttTopic - see its constructor
507
507
  });
508
508
 
509
509
  // Public API for custom dashboards and pages that import this module.
package/package.json CHANGED
@@ -41,5 +41,5 @@
41
41
  "unlink:hee": "rm -f node_modules/html-element-extended && npm install html-element-extended"
42
42
  },
43
43
  "type": "module",
44
- "version": "2.0.4"
44
+ "version": "2.0.5"
45
45
  }