mqtt-devices-parser 1.0.11 → 1.0.13
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 +10 -0
- package/index.js +24 -3
- package/models/devices.models.js +20 -3
- package/models/firmwares.models.js +2 -10
- package/models/fota.models.js +32 -0
- package/models/logs_actions.models.js +17 -0
- package/models/logs_device.models.js +62 -0
- package/models/logs_fota.models.js +41 -0
- package/models/{sensor_logs.models.js → logs_sensor.models.js} +2 -2
- package/models/modelPermissions.models.js +23 -0
- package/models/models.js +238 -211
- package/models/projects.models.js +8 -0
- package/package.json +1 -1
- package/src/db/data.js +91 -87
- package/src/db/db.js +24 -0
- package/src/db/device.js +288 -7
- package/src/db/firmware.js +30 -5
- package/src/db/fota.js +219 -0
- package/src/device/Readme.md +39 -4
- package/src/device/device.js +374 -152
package/Changelog.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.13
|
|
4
|
+
adds 2 new tables to db:
|
|
5
|
+
Adds 5 new columns to devices
|
|
6
|
+
Registers device logs, records device settings..
|
|
7
|
+
fixes: ws affected by a DoS when handling a request with many HTTP headers !breaking change
|
|
8
|
+
Updates npm
|
|
9
|
+
|
|
10
|
+
## 1.0.12
|
|
11
|
+
Adds module fota
|
|
12
|
+
|
|
3
13
|
## 1.0.11
|
|
4
14
|
index: MQTT
|
|
5
15
|
- makes mqtt client global,
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ $.db_device = require('./src/db/device');
|
|
|
14
14
|
$.db_model = require('./src/db/model');
|
|
15
15
|
$.db_firmware = require('./src/db/firmware');
|
|
16
16
|
$.db_sensor = require('./src/db/sensor');
|
|
17
|
+
$.db_fota = require('./src/db/fota');
|
|
17
18
|
$.mqtt_client = null;
|
|
18
19
|
|
|
19
20
|
const packageJson = require(__dirname+'/package.json');
|
|
@@ -63,6 +64,7 @@ var self = module.exports = {
|
|
|
63
64
|
})
|
|
64
65
|
|
|
65
66
|
let counter_help = 0;
|
|
67
|
+
let project = {}
|
|
66
68
|
files.forEach( async(name,counter) => {
|
|
67
69
|
if($.config.projects[name]){
|
|
68
70
|
project[name] = {};
|
|
@@ -82,7 +84,7 @@ var self = module.exports = {
|
|
|
82
84
|
|
|
83
85
|
},
|
|
84
86
|
|
|
85
|
-
deploy: async(_config,projectsPath)=>{
|
|
87
|
+
deploy: async(_config,projectsPath, projects)=>{
|
|
86
88
|
|
|
87
89
|
if(_config != null)
|
|
88
90
|
$.config = _config;
|
|
@@ -104,6 +106,15 @@ var self = module.exports = {
|
|
|
104
106
|
await $.models.insertUser("client","client_pwd",3);
|
|
105
107
|
// adds client with credentials admin@admin
|
|
106
108
|
await $.models.insertClient("admin","admin",user_id); // dashboard login
|
|
109
|
+
|
|
110
|
+
for(name of projects){
|
|
111
|
+
project = $.config[name];
|
|
112
|
+
if (project) {
|
|
113
|
+
// Make a copy if you don't want to modify the original config object
|
|
114
|
+
const projectData = { ...project, name: name };
|
|
115
|
+
await $.models.insertProject(projectData);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
107
118
|
}
|
|
108
119
|
|
|
109
120
|
// project tables
|
|
@@ -154,9 +165,19 @@ function mqtt_connect(){
|
|
|
154
165
|
$.mqtt_client.subscribe(project+"/#")
|
|
155
166
|
})
|
|
156
167
|
|
|
168
|
+
// Update 'dev' devices at each 5 min
|
|
157
169
|
checkFota = setInterval(async ()=>{
|
|
158
|
-
await $.device.checkFota();
|
|
159
|
-
|
|
170
|
+
await $.device.checkFota("dev");
|
|
171
|
+
await $.device.triggerFota("dev");
|
|
172
|
+
},5*60*1000);
|
|
173
|
+
|
|
174
|
+
// Update 'prod' devices at each hour
|
|
175
|
+
checkFota = setInterval(async ()=>{
|
|
176
|
+
await $.device.checkFota("prod");
|
|
177
|
+
await $.device.triggerFota("prod");
|
|
178
|
+
},60*60*1000);
|
|
179
|
+
|
|
180
|
+
// Devices not set as dev or prod must be triggered manually
|
|
160
181
|
|
|
161
182
|
});
|
|
162
183
|
|
package/models/devices.models.js
CHANGED
|
@@ -35,18 +35,35 @@ module.exports = (sequelize,DataTypes)=>{
|
|
|
35
35
|
type: DataTypes.STRING,
|
|
36
36
|
allowNull: true
|
|
37
37
|
},
|
|
38
|
-
|
|
38
|
+
accept_release: {
|
|
39
39
|
type: DataTypes.STRING,
|
|
40
40
|
allowNull: true
|
|
41
41
|
},
|
|
42
|
-
|
|
42
|
+
tech: {
|
|
43
43
|
type: DataTypes.STRING,
|
|
44
44
|
allowNull: true
|
|
45
45
|
},
|
|
46
|
-
|
|
46
|
+
remote_settings: { // device settings
|
|
47
|
+
type: DataTypes.JSON,
|
|
48
|
+
allowNull: true
|
|
49
|
+
},
|
|
50
|
+
local_settings: { // server settings
|
|
51
|
+
type: DataTypes.JSON,
|
|
52
|
+
allowNull: true
|
|
53
|
+
},
|
|
54
|
+
settings_ref: { // settings to be used, can be a uid, deviceId, default..
|
|
47
55
|
type: DataTypes.STRING,
|
|
48
56
|
allowNull: true
|
|
49
57
|
},
|
|
58
|
+
associatedDevice: {
|
|
59
|
+
type: DataTypes.INTEGER,
|
|
60
|
+
allowNull: true
|
|
61
|
+
},
|
|
62
|
+
endpoint: { // info about protocol communication
|
|
63
|
+
type: DataTypes.JSON,
|
|
64
|
+
allowNull: true
|
|
65
|
+
},
|
|
66
|
+
|
|
50
67
|
},
|
|
51
68
|
{
|
|
52
69
|
tableName: 'devices',
|
|
@@ -10,10 +10,6 @@ module.exports = (sequelize,DataTypes)=>{
|
|
|
10
10
|
allowNull: true,
|
|
11
11
|
unique: true
|
|
12
12
|
},
|
|
13
|
-
fw_version: { // deprecated
|
|
14
|
-
type: DataTypes.STRING,
|
|
15
|
-
allowNull: true
|
|
16
|
-
},
|
|
17
13
|
version: {
|
|
18
14
|
type: DataTypes.STRING,
|
|
19
15
|
allowNull: true
|
|
@@ -22,15 +18,11 @@ module.exports = (sequelize,DataTypes)=>{
|
|
|
22
18
|
type: DataTypes.STRING,
|
|
23
19
|
allowNull: true
|
|
24
20
|
},
|
|
25
|
-
|
|
26
|
-
type: DataTypes.STRING,
|
|
27
|
-
allowNull: true
|
|
28
|
-
},
|
|
29
|
-
release: {
|
|
21
|
+
build_release: {
|
|
30
22
|
type: DataTypes.STRING,
|
|
31
23
|
allowNull: true
|
|
32
24
|
},
|
|
33
|
-
model_id: {
|
|
25
|
+
model_id: {
|
|
34
26
|
type: DataTypes.INTEGER,
|
|
35
27
|
references: {
|
|
36
28
|
model: 'models',
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module.exports = (sequelize,DataTypes)=>{
|
|
2
|
+
return sequelize.define("fota", {
|
|
3
|
+
device_id: {
|
|
4
|
+
type: DataTypes.INTEGER,
|
|
5
|
+
unique: true,
|
|
6
|
+
},
|
|
7
|
+
target_version: {
|
|
8
|
+
type: DataTypes.STRING,
|
|
9
|
+
},
|
|
10
|
+
target_app_version: {
|
|
11
|
+
type: DataTypes.STRING,
|
|
12
|
+
},
|
|
13
|
+
target_release: {
|
|
14
|
+
type: DataTypes.STRING,
|
|
15
|
+
},
|
|
16
|
+
firmware_id: {
|
|
17
|
+
type: DataTypes.INTEGER,
|
|
18
|
+
},
|
|
19
|
+
nAttempts: {
|
|
20
|
+
type: DataTypes.INTEGER,
|
|
21
|
+
default: 0
|
|
22
|
+
},
|
|
23
|
+
fUpdate: {
|
|
24
|
+
type: DataTypes.BOOLEAN,
|
|
25
|
+
default: 0
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
tableName: 'fota',
|
|
30
|
+
freezeTableName: true
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = (sequelize,DataTypes)=>{
|
|
3
|
+
return sequelize.define("logs_actions", {
|
|
4
|
+
client_id: {
|
|
5
|
+
type: DataTypes.INTEGER,
|
|
6
|
+
allowNull: false
|
|
7
|
+
},
|
|
8
|
+
action: {
|
|
9
|
+
type: DataTypes.STRING,
|
|
10
|
+
allowNull: true
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
tableName: 'logs_actions',
|
|
15
|
+
freezeTableName: true
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = (sequelize,DataTypes)=>{
|
|
3
|
+
return sequelize.define("logs_devices", {
|
|
4
|
+
device_id: {
|
|
5
|
+
type: DataTypes.INTEGER,
|
|
6
|
+
},
|
|
7
|
+
status: {
|
|
8
|
+
type: DataTypes.STRING,
|
|
9
|
+
allowNull: true
|
|
10
|
+
},
|
|
11
|
+
project_id: {
|
|
12
|
+
type: DataTypes.INTEGER,
|
|
13
|
+
references: {
|
|
14
|
+
model: 'projects',
|
|
15
|
+
key: 'id'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
model_id: {
|
|
19
|
+
type: DataTypes.INTEGER,
|
|
20
|
+
references: {
|
|
21
|
+
model: 'models',
|
|
22
|
+
key: 'id'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
version: {
|
|
26
|
+
type: DataTypes.STRING,
|
|
27
|
+
allowNull: true
|
|
28
|
+
},
|
|
29
|
+
app_version: {
|
|
30
|
+
type: DataTypes.STRING,
|
|
31
|
+
allowNull: true
|
|
32
|
+
},
|
|
33
|
+
tech: {
|
|
34
|
+
type: DataTypes.STRING,
|
|
35
|
+
allowNull: true
|
|
36
|
+
},
|
|
37
|
+
associatedDevice: {
|
|
38
|
+
type: DataTypes.INTEGER,
|
|
39
|
+
allowNull: true
|
|
40
|
+
},
|
|
41
|
+
local_settings: { // server settings
|
|
42
|
+
type: DataTypes.JSON,
|
|
43
|
+
allowNull: true
|
|
44
|
+
},
|
|
45
|
+
remote_settings: { // server settings
|
|
46
|
+
type: DataTypes.JSON,
|
|
47
|
+
allowNull: true
|
|
48
|
+
},
|
|
49
|
+
settings_ref: { // settings to be used, can be a uid, deviceId, default..
|
|
50
|
+
type: DataTypes.STRING,
|
|
51
|
+
allowNull: true
|
|
52
|
+
},
|
|
53
|
+
endpoint: { // info about protocol communication
|
|
54
|
+
type: DataTypes.JSON,
|
|
55
|
+
allowNull: true
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
tableName: 'logs_devices',
|
|
60
|
+
freezeTableName: true
|
|
61
|
+
})
|
|
62
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module.exports = (sequelize,DataTypes)=>{
|
|
2
|
+
return sequelize.define("logs_fota", {
|
|
3
|
+
device_id: {
|
|
4
|
+
type: DataTypes.INTEGER,
|
|
5
|
+
},
|
|
6
|
+
model_id: {
|
|
7
|
+
type: DataTypes.STRING,
|
|
8
|
+
},
|
|
9
|
+
local_version: {
|
|
10
|
+
type: DataTypes.STRING,
|
|
11
|
+
},
|
|
12
|
+
local_app_version: {
|
|
13
|
+
type: DataTypes.STRING,
|
|
14
|
+
},
|
|
15
|
+
target_version: {
|
|
16
|
+
type: DataTypes.STRING,
|
|
17
|
+
},
|
|
18
|
+
target_app_version: {
|
|
19
|
+
type: DataTypes.STRING,
|
|
20
|
+
},
|
|
21
|
+
target_file: {
|
|
22
|
+
type: DataTypes.STRING,
|
|
23
|
+
},
|
|
24
|
+
error: {
|
|
25
|
+
type: DataTypes.STRING,
|
|
26
|
+
allowNull: true
|
|
27
|
+
},
|
|
28
|
+
success: {
|
|
29
|
+
type: DataTypes.BOOLEAN,
|
|
30
|
+
default: 0
|
|
31
|
+
},
|
|
32
|
+
nAttempt: {
|
|
33
|
+
type: DataTypes.INTEGER,
|
|
34
|
+
default: 0
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
tableName: 'logs_fota',
|
|
39
|
+
freezeTableName: true
|
|
40
|
+
})
|
|
41
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = (sequelize,DataTypes)=>{
|
|
2
|
-
return sequelize.define("
|
|
2
|
+
return sequelize.define("logs_sensor", {
|
|
3
3
|
device_id: {
|
|
4
4
|
type: DataTypes.INTEGER,
|
|
5
5
|
unique: false,
|
|
@@ -34,7 +34,7 @@ module.exports = (sequelize,DataTypes)=>{
|
|
|
34
34
|
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
tableName: '
|
|
37
|
+
tableName: 'logs_sensor',
|
|
38
38
|
freezeTableName: true
|
|
39
39
|
})
|
|
40
40
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = (sequelize,DataTypes)=>{
|
|
3
|
+
return sequelize.define("modelPermissions", {
|
|
4
|
+
client_id: {
|
|
5
|
+
type: DataTypes.INTEGER,
|
|
6
|
+
references: {
|
|
7
|
+
model: 'clients',
|
|
8
|
+
key: 'id'
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
model_id: {
|
|
12
|
+
type: DataTypes.INTEGER,
|
|
13
|
+
references: {
|
|
14
|
+
model: 'models',
|
|
15
|
+
key: 'id'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
tableName: 'modelPermissions',
|
|
21
|
+
freezeTableName: true
|
|
22
|
+
})
|
|
23
|
+
}
|