mqtt-devices-parser 1.0.13 → 1.0.14
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 +3 -0
- package/Release.md +3 -0
- package/models/fota.models.js +3 -0
- package/package.json +1 -1
- package/src/db/fota.js +17 -17
- package/src/device/device.js +21 -9
package/Changelog.md
CHANGED
package/Release.md
CHANGED
package/models/fota.models.js
CHANGED
package/package.json
CHANGED
package/src/db/fota.js
CHANGED
|
@@ -7,7 +7,7 @@ var self = module.exports = {
|
|
|
7
7
|
|
|
8
8
|
return new Promise((resolve,reject) => {
|
|
9
9
|
|
|
10
|
-
let query = `SELECT
|
|
10
|
+
let query = `SELECT * FROM ?? where
|
|
11
11
|
device_id = ? and
|
|
12
12
|
target_version = ? and
|
|
13
13
|
target_app_version = ? and
|
|
@@ -91,13 +91,13 @@ var self = module.exports = {
|
|
|
91
91
|
obj['createdAt'] = moment().utc().format('YYYY-MM-DD HH:mm:ss');
|
|
92
92
|
obj['device_id'] = deviceId;
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
$.db.insert("fota",obj)
|
|
95
|
+
.then (rows => {
|
|
96
|
+
return resolve(rows[0]);
|
|
97
|
+
})
|
|
98
|
+
.catch(error => {
|
|
99
|
+
return reject(error);
|
|
100
|
+
});
|
|
101
101
|
|
|
102
102
|
}else{
|
|
103
103
|
|
|
@@ -106,18 +106,18 @@ var self = module.exports = {
|
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
$.db.update("fota",obj,filter)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
.then (rows => {
|
|
110
|
+
return resolve(rows[0]);
|
|
111
|
+
})
|
|
112
|
+
.catch(error => {
|
|
113
|
+
return reject(error);
|
|
114
|
+
});
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
});
|
|
118
118
|
},
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
getFotaLastLog : async(deviceId)=>{
|
|
121
121
|
|
|
122
122
|
return new Promise((resolve,reject) => {
|
|
123
123
|
|
|
@@ -127,7 +127,7 @@ var self = module.exports = {
|
|
|
127
127
|
LIMIT 1`;
|
|
128
128
|
|
|
129
129
|
let table = [
|
|
130
|
-
"
|
|
130
|
+
"logs_fota",
|
|
131
131
|
deviceId,
|
|
132
132
|
];
|
|
133
133
|
query = mysql.format(query,table);
|
|
@@ -195,7 +195,7 @@ var self = module.exports = {
|
|
|
195
195
|
|
|
196
196
|
return new Promise(async (resolve,reject) => {
|
|
197
197
|
|
|
198
|
-
const log = await
|
|
198
|
+
const log = await self.getFotaLastLog(deviceId);
|
|
199
199
|
|
|
200
200
|
if(log?.createdAt != log?.updatedAt)
|
|
201
201
|
|
package/src/device/device.js
CHANGED
|
@@ -314,12 +314,15 @@ var self = module.exports = {
|
|
|
314
314
|
|
|
315
315
|
for (const model of models) {
|
|
316
316
|
|
|
317
|
+
console.log("model:",model?.name);
|
|
317
318
|
if(!model?.id)
|
|
318
319
|
continue;
|
|
319
320
|
|
|
320
321
|
try{
|
|
321
322
|
const latestVersion = await $.db_firmware.getLatestVersion(model.id,release);
|
|
322
323
|
const latestAppVersion = await $.db_firmware.getLatestAppVersion(model.id,release);
|
|
324
|
+
console.log("latestVersion:",latestVersion?.version);
|
|
325
|
+
console.log("latestAppVersion:",latestAppVersion?.app_version);
|
|
323
326
|
|
|
324
327
|
const devices = await $.db_device.listByModel(model.id);
|
|
325
328
|
|
|
@@ -356,12 +359,21 @@ var self = module.exports = {
|
|
|
356
359
|
};
|
|
357
360
|
}
|
|
358
361
|
if(obj != null){
|
|
359
|
-
try{
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
362
|
+
try {
|
|
363
|
+
|
|
364
|
+
let res = await $.db_fota.getEntry(device.id, obj);
|
|
365
|
+
|
|
366
|
+
if (res == null) {
|
|
367
|
+
try {
|
|
368
|
+
console.log("add fota entry for device:", device.uid);
|
|
369
|
+
await $.db_fota.update(device.id, obj);
|
|
370
|
+
} catch (err) {
|
|
371
|
+
console.error("Error updating FOTA entry:", err);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
} catch (error) {
|
|
376
|
+
console.error("Error getting or processing FOTA entry:", error);
|
|
365
377
|
}
|
|
366
378
|
}
|
|
367
379
|
}
|
|
@@ -409,7 +421,7 @@ var self = module.exports = {
|
|
|
409
421
|
topic = mqtt_prefix+"/fw/fota/update/set";
|
|
410
422
|
}
|
|
411
423
|
let link = `${$.config.web.protocol}${$.config.web.domain}${$.config.web.fw_path}${firmware?.filename}/download?token=${firmware?.token}`;
|
|
412
|
-
console.log(`Requesting firmware update
|
|
424
|
+
console.log(`Requesting firmware update for ${device.uid} to ${firmware?.filename}`);
|
|
413
425
|
$.mqtt_client.publish(topic,`{"url":"${link}"}`,{qos:1,retain:false});
|
|
414
426
|
|
|
415
427
|
let obj = {
|
|
@@ -448,14 +460,14 @@ var self = module.exports = {
|
|
|
448
460
|
object = {
|
|
449
461
|
success : 1,
|
|
450
462
|
}
|
|
451
|
-
await $.db_fota.updateLog(deviceId,
|
|
463
|
+
await $.db_fota.updateLog(deviceId,object);
|
|
452
464
|
},
|
|
453
465
|
|
|
454
466
|
handleFotaError : async (deviceId, error) => {
|
|
455
467
|
let object = {
|
|
456
468
|
error : error,
|
|
457
469
|
}
|
|
458
|
-
await $.db_fota.updateLog(deviceId,
|
|
470
|
+
await $.db_fota.updateLog(deviceId,object);
|
|
459
471
|
}
|
|
460
472
|
}
|
|
461
473
|
|