mqtt-devices-parser 1.0.25 → 1.0.27

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.27
4
+ feat(db): adds variants table
5
+
6
+ ## 1.0.26
7
+ feat: src/device/device: request fw/wifi/get
8
+ on device online reporting and if device is connected through wifi
9
+ fix: add logs in json format to logs_fw table
10
+ forces: usage of "ws": "^7.5.10" for websocket-stream package
11
+ vulnerabilities: 0 found
12
+
3
13
  ## 1.0.25
4
14
 
5
15
  Sensors template (#9)
@@ -31,6 +31,13 @@ module.exports = (sequelize,DataTypes)=>{
31
31
  key: 'id'
32
32
  }
33
33
  },
34
+ variant_id: {
35
+ type: DataTypes.INTEGER,
36
+ references: {
37
+ model: 'variants',
38
+ key: 'id'
39
+ }
40
+ },
34
41
  version: {
35
42
  type: DataTypes.STRING,
36
43
  allowNull: true
@@ -29,6 +29,13 @@ module.exports = (sequelize,DataTypes)=>{
29
29
  key: 'id'
30
30
  },
31
31
  },
32
+ variant_id: {
33
+ type: DataTypes.INTEGER,
34
+ references: {
35
+ model: 'variants',
36
+ key: 'id'
37
+ }
38
+ },
32
39
  token: {
33
40
  type: DataTypes.STRING,
34
41
  allowNull: true
@@ -0,0 +1,23 @@
1
+
2
+ module.exports = (sequelize,DataTypes)=>{
3
+ return sequelize.define("variants", {
4
+ name: {
5
+ type: DataTypes.STRING,
6
+ unique: true
7
+ },
8
+ model_id: {
9
+ type: DataTypes.INTEGER,
10
+ references: {
11
+ model: 'models',
12
+ key: 'id'
13
+ }
14
+ },
15
+ description: {
16
+ type: DataTypes.STRING
17
+ },
18
+ },
19
+ {
20
+ tableName: 'variants',
21
+ freezeTableName: true
22
+ })
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mqtt-devices-parser",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,6 +21,14 @@
21
21
  "path": "^0.12.7",
22
22
  "semver": "^7.3.8",
23
23
  "sequelize": "^6.32.1",
24
- "websocket-stream": "^5.3.0"
24
+ "websocket-stream": "^5.4.0"
25
+ },
26
+ "overrides": {
27
+ "websocket-stream": {
28
+ "ws": "^7.5.10"
29
+ },
30
+ "sequelize": {
31
+ "uuid": "^11.1.1"
32
+ }
25
33
  }
26
34
  }
package/src/db/data.js CHANGED
@@ -275,7 +275,7 @@ var self = module.exports = {
275
275
  });
276
276
  },
277
277
 
278
- addJsonLog: async (table, deviceId, dataObject) => {
278
+ addJsonLog: async (table, deviceId, dataObject, column = "") => {
279
279
  return new Promise((resolve, reject) => {
280
280
  if (!dataObject || typeof dataObject !== 'object')
281
281
  return reject("Not an object");
@@ -291,17 +291,22 @@ var self = module.exports = {
291
291
  if (db_columns == null)
292
292
  return reject(`No columns for table: ${table}`);
293
293
 
294
- // Prepare data for insertion
295
- for (let key in dataObject) {
296
- if (db_columns.hasOwnProperty(key)) {
297
- let value = dataObject[key];
294
+ if(column != ""){
295
+ if (db_columns.hasOwnProperty(column))
296
+ obj[column] = JSON.stringify(dataObject);
297
+ }else{
298
+ // Prepare data for insertion
299
+ for (let key in dataObject) {
300
+ if (db_columns.hasOwnProperty(key)) {
301
+ let value = dataObject[key];
302
+
303
+ // Convert object to JSON string if needed
304
+ if (typeof value === 'object') {
305
+ value = JSON.stringify(value);
306
+ }
298
307
 
299
- // Convert object to JSON string if needed
300
- if (typeof value === 'object') {
301
- value = JSON.stringify(value);
308
+ obj[key] = value;
302
309
  }
303
-
304
- obj[key] = value;
305
310
  }
306
311
  }
307
312
 
@@ -412,6 +412,10 @@ async function parseMqttMessage(client, project_name, device, topic, payload, re
412
412
  let topic = `${mqtt_prefix}/settings/mqtt/get`
413
413
  $.mqtt_client.publish(topic,"",{qos:1,retain:false});
414
414
  }
415
+ if(device?.tech.toLowerCase() === "wifi"){
416
+ let topic = `${mqtt_prefix}/fw/wifi/get`
417
+ $.mqtt_client.publish(topic,"",{qos:1,retain:false});
418
+ }
415
419
  }
416
420
  break;
417
421
  case "model":
@@ -446,10 +450,11 @@ async function parseMqttMessage(client, project_name, device, topic, payload, re
446
450
  if(topic === "fota/update/status"){
447
451
  handleFotaError(device.id, payload);
448
452
  }else{
453
+ let word = $.parser.getFirstWord(topic);
449
454
  if(typeof payload === 'object' && payload !== null){
450
455
  try{
451
456
  let rows = await $.db_data.updateJson("fw",device.id,payload);
452
- rows = await $.db_data.addJsonLog("logs_fw",device.id,payload);
457
+ rows = await $.db_data.addJsonLog("logs_fw",device.id,payload,word);
453
458
  }catch(error){
454
459
  console.error(error)
455
460
  }