@lifefinder/vsm-mqtt-client-open-source 0.0.60 → 0.0.62

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.
@@ -62,6 +62,11 @@ module.exports.api = {
62
62
  }
63
63
  const client = mqtt.connect(args.s, mqttOpts);
64
64
 
65
+ client.on('error', (e) => {
66
+ console.log("MQTT ChirpStack 4 Connection Error", e);
67
+ process.exit(1);
68
+ });
69
+
65
70
  client.on('connect', () => {
66
71
  args.v && console.log("Connected to chirpstack server");
67
72
 
@@ -103,9 +108,19 @@ module.exports.api = {
103
108
  // message is Buffer
104
109
  args.v && console.log(topic, message.toString());
105
110
 
106
- const obj = JSON.parse(message.toString('utf-8'));
111
+ let obj;
112
+ try {
113
+ obj = JSON.parse(message.toString('utf-8'));
114
+ } catch (e) {
115
+ console.log("Chirpstack: failed to parse message: " + e.message);
116
+ return;
117
+ }
107
118
  if (!obj.data)
108
119
  return;
120
+ if (!obj.deviceInfo || !obj.deviceInfo.devEui) {
121
+ console.log("Chirpstack: message missing deviceInfo.devEui, skipping");
122
+ return;
123
+ }
109
124
  const data = Buffer.from(obj.data, "base64");
110
125
  const port = obj.fPort;
111
126
  const id = obj.deviceInfo.devEui;
@@ -122,7 +137,7 @@ module.exports.api = {
122
137
  }
123
138
  date = new Date(gwinfo.time);
124
139
  }
125
- if (! (date && isDate(date)))
140
+ if (!(date && isDate(date) && !isNaN(date.getTime())))
126
141
  date = new Date()
127
142
 
128
143
  await onUplinkDevicePortBufferDateLatLng(client, id, port, data, date, lat, lng, maxSize, extractLoraInfo(obj));
@@ -142,7 +157,7 @@ module.exports.api = {
142
157
  devEui: devEUI,
143
158
  confirmed,
144
159
  fPort: port,
145
- payload: data.toString('base64'),
160
+ data: data.toString('base64'),
146
161
  };
147
162
  client.publish(topic, JSON.stringify(obj));
148
163
  args.v && console.log("Publish downlink on port " + port + " data: " + data.toString("hex"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifefinder/vsm-mqtt-client-open-source",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "description": "MQTT client for vsm sensors",
5
5
  "main": "vsm-mqtt-client.js",
6
6
  "author": "Lars Mats",
@@ -103,7 +103,7 @@ exports.getMqttClient = () => {
103
103
  return mqtt_client;
104
104
  }
105
105
 
106
- exports.sendDownlink = async (args, deveui, port, buffer) => {
106
+ exports.sendDownlink = async (args, deveui, port, buffer, confirmed = false) => {
107
107
  if (!args || !deveui || !port || !buffer)
108
108
  throw { message: "sendDownlink: Required argument missing"};
109
109
 
@@ -115,7 +115,7 @@ exports.sendDownlink = async (args, deveui, port, buffer) => {
115
115
  if (!this.getMqttClient())
116
116
  throw { message: "sendDownlink: MQTT not initialized."};
117
117
 
118
- await integration.api.sendDownlink(this.getMqttClient(), args, deveui, port, Buffer.from(buffer, "hex"), false /* confirmed */ );
118
+ await integration.api.sendDownlink(this.getMqttClient(), args, deveui, port, Buffer.from(buffer, "hex"), confirmed === true);
119
119
  }
120
120
 
121
121
  const run = async () => {