mqtt-devices-parser 1.0.29 → 1.0.30
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/Changelog.md +7 -1
- package/Release.md +2 -1
- package/package.json +1 -1
- package/src/db/fota.js +8 -1
- package/src/device/device.js +16 -3
- package/src/device/device.test.js +2 -1
package/Changelog.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.30
|
|
4
|
+
fix: tests, recover "settings" parsing, deal with new call addMqttMsgLog
|
|
5
|
+
doc: update Release
|
|
6
|
+
fix: handle ER_DUP_ENTRY race condition in fota.update() (#14)
|
|
7
|
+
perf(src/device/device): clean and parse mqtt payload
|
|
8
|
+
|
|
3
9
|
## 1.0.29
|
|
4
10
|
fix(models/sensors): allow null model_id
|
|
5
11
|
fix: synching mqtt topics
|
|
@@ -11,7 +17,7 @@
|
|
|
11
17
|
doc(device): recover readme add test.md file
|
|
12
18
|
fix(models/variants): remove unique true from column name
|
|
13
19
|
ci: fix vulnerabilities
|
|
14
|
-
|
|
20
|
+
|
|
15
21
|
## 1.0.27
|
|
16
22
|
feat(db): adds variants table
|
|
17
23
|
|
package/Release.md
CHANGED
package/package.json
CHANGED
package/src/db/fota.js
CHANGED
|
@@ -96,7 +96,14 @@ var self = module.exports = {
|
|
|
96
96
|
return resolve(rows[0]);
|
|
97
97
|
})
|
|
98
98
|
.catch(error => {
|
|
99
|
-
|
|
99
|
+
if(error.code === 'ER_DUP_ENTRY'){
|
|
100
|
+
let filter = { device_id : deviceId };
|
|
101
|
+
$.db.update("fota",obj,filter)
|
|
102
|
+
.then(rows => { return resolve(rows[0]); })
|
|
103
|
+
.catch(err => { return reject(err); });
|
|
104
|
+
}else{
|
|
105
|
+
return reject(error);
|
|
106
|
+
}
|
|
100
107
|
});
|
|
101
108
|
|
|
102
109
|
}else{
|
package/src/device/device.js
CHANGED
|
@@ -335,7 +335,6 @@ var self = module.exports = {
|
|
|
335
335
|
|
|
336
336
|
$.db_device.updateLocalTopic(dbTopic.id,payload)
|
|
337
337
|
.then(()=>{
|
|
338
|
-
// set as not synched
|
|
339
338
|
if(isDeepStrictEqual(payload, dbTopic?.remoteData))
|
|
340
339
|
$.db_device.setSynchedTopic(dbTopic.id,true);
|
|
341
340
|
else
|
|
@@ -420,6 +419,7 @@ async function parseMqttMessage(client, project_name, device, topic, payload, re
|
|
|
420
419
|
|
|
421
420
|
try{
|
|
422
421
|
payload = JSON.parse(payload);
|
|
422
|
+
payload = cleanAndParse(payload);
|
|
423
423
|
}catch(error){}
|
|
424
424
|
|
|
425
425
|
let word = $.parser.getFirstWord(topic);
|
|
@@ -515,7 +515,6 @@ async function parseMqttMessage(client, project_name, device, topic, payload, re
|
|
|
515
515
|
}
|
|
516
516
|
break;
|
|
517
517
|
case "settings": // deprecated
|
|
518
|
-
break;
|
|
519
518
|
if(topic.endsWith("/set")){
|
|
520
519
|
updateLocalSettings(device,topic,payload);
|
|
521
520
|
}else{
|
|
@@ -726,4 +725,18 @@ function handleFotaError (deviceId, error){
|
|
|
726
725
|
$.db_fota.updateLog(deviceId,object);
|
|
727
726
|
}
|
|
728
727
|
|
|
729
|
-
|
|
728
|
+
function cleanAndParse(payload) {
|
|
729
|
+
if (typeof payload === 'string') {
|
|
730
|
+
let cleaned = payload.trim();
|
|
731
|
+
if (cleaned.startsWith('"') && cleaned.endsWith('"')) {
|
|
732
|
+
cleaned = cleaned.slice(1, -1);
|
|
733
|
+
}
|
|
734
|
+
cleaned = cleaned.replace(/\\"/g, '"');
|
|
735
|
+
try {
|
|
736
|
+
return JSON.parse(cleaned);
|
|
737
|
+
} catch (e) {
|
|
738
|
+
return payload; // fallback: return original if still invalid
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return payload;
|
|
742
|
+
}
|