mqtt-devices-parser 1.0.4 → 1.0.6

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,3 +1,9 @@
1
+ # 1.0.6
2
+ - device: updates project if mismatch
3
+
4
+ # 1.0.5
5
+ - db: adds mqtt user passed on mqtt struct and grants admin privileges
6
+
1
7
  # 1.0.4
2
8
  - mqtt: adds retain to project state
3
9
 
package/Readme.md CHANGED
@@ -33,3 +33,7 @@
33
33
 
34
34
  The default configuration uses ./config/index.js file\
35
35
  In your program set the same struct and pass it as argument on the module init call.
36
+
37
+ An mqtt account will be created using the following settings
38
+ mqtt.user - mqtt user login
39
+ mqtt.pwd - mqtt pwd login
package/index.js CHANGED
@@ -92,12 +92,13 @@ var self = module.exports = {
92
92
  await $.models.dropTableIndexes();
93
93
  await $.models.sync();
94
94
 
95
- let user = await $.models.insertUser("admin","admin",5); // ads user
96
- //console.log(user);
95
+ // adds user for mqtt with admin credentials
96
+ let user = await $.models.insertUser($.config.mqtt.user,$.config.mqtt.pwd,5);
97
97
  let user_id = user.dataValues.id;
98
98
  await $.models.insertUser("device","device",3);
99
99
  await $.models.insertUser("client","client_pwd",3);
100
- await $.models.insertClient("admin","admin",user_id); // ads client with credentials admin@admin
100
+ // adds client with credentials admin@admin
101
+ await $.models.insertClient("admin","admin",user_id); // dashboard login
101
102
  }
102
103
 
103
104
  // project tables
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mqtt-devices-parser",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -62,11 +62,11 @@ var self = module.exports = {
62
62
  .catch( (err) => {});
63
63
  }
64
64
 
65
- if(device?.project_id == null){
66
- let res = await $.db_project.getByName(project_name);
67
- let project_id = res?.id;
68
- if(project_id != null) $.db_device.updateProject(uid,project_id);
69
- }
65
+ // update project id if needed
66
+ let res = await $.db_project.getByName(project_name);
67
+ let project_id = res?.id;
68
+ if(project_id != null && project_id != device?.project_id)
69
+ $.db_device.updateProject(uid,project_id);
70
70
 
71
71
  if(topic.endsWith("status")){
72
72
  if(payload == "online" || payload == "offline")