mqtt-devices-parser 1.0.14 → 1.0.16

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,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.16
4
+ changes db tables:
5
+ - models/devices.models: removes endpoint, adds protocol and psk.
6
+ - adds mqtt_password
7
+
8
+ ## 1.0.15
9
+ src/device/device: fixes fota for sniffer model
10
+ changes DB tables:
11
+ - adds level to modelPermissions
12
+ - adds project_id to model
13
+ - adds projectPermissions table
14
+ - deletes file modelPermissions.js
15
+
3
16
  ## 1.0.14
4
17
  Fixes check FOTA mechanism and response
5
18
 
package/Release.md CHANGED
@@ -3,6 +3,7 @@
3
3
  ## Before release
4
4
 
5
5
  increases version on package.json
6
+ run npm install
6
7
  edit changelog
7
8
  commit and push to repo
8
9
 
@@ -20,6 +20,10 @@ module.exports = (sequelize,DataTypes)=>{
20
20
  type: DataTypes.STRING,
21
21
  allowNull: true
22
22
  },
23
+ mqtt_password: {
24
+ type: DataTypes.STRING(24),
25
+ allowNull: true
26
+ },
23
27
  gmail: {
24
28
  type: DataTypes.STRING(64),
25
29
  //unique: true,
@@ -59,11 +59,14 @@ module.exports = (sequelize,DataTypes)=>{
59
59
  type: DataTypes.INTEGER,
60
60
  allowNull: true
61
61
  },
62
- endpoint: { // info about protocol communication
63
- type: DataTypes.JSON,
62
+ protocol: { // protocol communication to be used
63
+ type: DataTypes.STRING,
64
+ allowNull: false
65
+ },
66
+ psk: { // pre shared key
67
+ type: DataTypes.STRING,
64
68
  allowNull: true
65
69
  },
66
-
67
70
  },
68
71
  {
69
72
  tableName: 'devices',
@@ -14,6 +14,9 @@ module.exports = (sequelize,DataTypes)=>{
14
14
  model: 'models',
15
15
  key: 'id'
16
16
  }
17
+ },
18
+ level: {
19
+ type: DataTypes.INTEGER,
17
20
  }
18
21
  },
19
22
  {
@@ -16,6 +16,10 @@ module.exports = (sequelize,DataTypes)=>{
16
16
  type: DataTypes.STRING,
17
17
  allowNull: true
18
18
  },
19
+ project_id: {
20
+ type: DataTypes.INTEGER,
21
+ allowNull: false
22
+ },
19
23
  fw_enabled: {
20
24
  type: DataTypes.BOOLEAN,
21
25
  defaultValue: false
@@ -1,6 +1,6 @@
1
1
 
2
2
  module.exports = (sequelize,DataTypes)=>{
3
- return sequelize.define("modelPermissions", {
3
+ return sequelize.define("projectPermissions", {
4
4
  client_id: {
5
5
  type: DataTypes.INTEGER,
6
6
  references: {
@@ -8,16 +8,19 @@ module.exports = (sequelize,DataTypes)=>{
8
8
  key: 'id'
9
9
  }
10
10
  },
11
- model_id: {
11
+ project_id: {
12
12
  type: DataTypes.INTEGER,
13
13
  references: {
14
- model: 'models',
14
+ model: 'projects',
15
15
  key: 'id'
16
16
  }
17
+ },
18
+ level: {
19
+ type: DataTypes.INTEGER,
17
20
  }
18
21
  },
19
22
  {
20
- tableName: 'modelPermissions',
23
+ tableName: 'projectPermissions',
21
24
  freezeTableName: true
22
25
  })
23
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mqtt-devices-parser",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -401,19 +401,22 @@ var self = module.exports = {
401
401
  const model_name = model?.name;
402
402
  let topic = "";
403
403
  if(model_name == "sniffer"){
404
- resolve();
405
- // !! This cannot be handled on this way
406
404
 
407
405
  // get sniffer info associated to device
408
- const sniffer = await $.db_data.getAssociatedToDevice("sniffer",device.id);
409
- if(sniffer == null) return;
406
+ const associatedDevice = await $.db_device.getAssociatedDevice(device.id);
407
+ if(associatedDevice == null) return;
408
+
410
409
  // get device_uid from devices table
411
- const gw = await $.db_device.getById(sniffer?.id)
410
+ const gw = await $.db_device.getById(associatedDevice)
412
411
  if(gw == null) return;
413
- let mqtt_prefix = `${project_name}/${gw.uid}`;
414
- if (semver.gt(sniffer.version, "2.0.1"))
412
+
413
+ const gwProject = await $.db_project.getById(gw?.project_id);
414
+ const gwProjectName = project?.name;
415
+
416
+ let mqtt_prefix = `${gwProjectName}/${gw?.uid}`;
417
+ if (semver.gt(gw.app_version, "1.0.5"))
415
418
  topic = mqtt_prefix+`/app/sniffer/${sniffer.uid}/fota/update/set`;
416
- else
419
+ else // deprecate it as soon as all gws are updated
417
420
  topic = mqtt_prefix+`/app/sniffer/fota/update/set`;
418
421
  }
419
422
  else{