@lifefinder/vsm-mqtt-client-open-source 0.0.60 → 0.0.61
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.
- package/integrations/chirpstack4.js +18 -3
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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 (!
|
|
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
|
-
|
|
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"));
|