Skip to content

Commit aacb891

Browse files
committed
Set auto provision bucket to true as default and fixed assignment of project
1 parent a68ce2a commit aacb891

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

ttn-stack/CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.2.1] - 2024-03-22
4+
5+
### Fixed
6+
7+
- Auto provision bucket is set true as default
8+
- Assign project to provisioned failing device provisioning
9+
310
## [1.2.0] - 2024-03-08
411

512
### Added
@@ -32,7 +39,8 @@
3239

3340
- Make sure Thinger server is running before starting service
3441

35-
[1.2.0]: https://github.com/thinger-io/plugins/compare/ttn-stack/v1.2.0...ttn-stack/v1.2.0
42+
[1.2.1]: `https://github.com/thinger-io/plugins/compare/ttn-stack/v1.2.0...ttn-stack/v1.2.1`
43+
[1.2.0]: `https://github.com/thinger-io/plugins/compare/ttn-stack/v1.1.0...ttn-stack/v1.2.0`
3644
[1.1.0]: https://github.com/thinger-io/plugins/compare/ttn-stack/v1.0.4...ttn-stack/v1.1.0
3745
[1.0.4]: https://github.com/thinger-io/plugins/compare/ttn-stack/v1.0.3...ttn-stack/v1.0.4
3846
[1.0.3]: https://github.com/thinger-io/plugins/tree/ttn-stack/v1.0.3

ttn-stack/gui/ttn-stack-settings.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ angular.module('TTNStackPlugin', ['uiAce'])
2222
function initSettings(type){
2323
$scope.settings.value[type] = {};
2424
$scope.settings.value[type].auto_provision_resources = false;
25+
$scope.settings.value[type].auto_provision_bucket = true;
2526
$scope.settings.value[type].device_downlink_data = '""';
2627
}
2728

@@ -143,4 +144,4 @@ angular.module('TTNStackPlugin', ['uiAce'])
143144

144145
}]
145146
}
146-
});
147+
});

ttn-stack/plugin.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "ttn-stack",
3-
"version" : "1.2.0",
3+
"version" : "1.2.1",
44
"description" : "Plugin for handling The Things Stack integration",
55
"author" : "Alvaro Luis Bustamante",
66
"license" : "MIT",
@@ -20,13 +20,13 @@
2020
"name" : "Access from TTN Stack plugin to Thinger.io account",
2121
"allow" : {
2222
"Device" : {
23-
"*" : ["CreateDevice", "SetDeviceProperty", "ReadDeviceProperty", "UpdateDeviceCallback", "CallDeviceCallback"]
23+
"*" : ["CreateDevice", "SetDeviceProperty", "ReadDeviceProperty", "UpdateDeviceCallback", "CallDeviceCallback", "UpdateDeviceProjects"]
2424
},
2525
"User" : {
2626
"*" : ["SubscribeUserEvents"]
2727
},
2828
"Bucket" : {
29-
"*" : ["CreateBucket"]
29+
"*" : ["CreateBucket", "UpdateBucketProjects"]
3030
},
3131
"Plugin" : {
3232
"ttn-stack" : "*"

ttn-stack/task/api/api.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports.createHTTPDevice = async function(deviceId, deviceName, deviceDes
2121
};
2222
if(settings.assign_asset_type) data.asset_type = settings.assign_asset_type;
2323
if(settings.assign_asset_group) data.asset_group = settings.assign_asset_group;
24-
if(settings.assign_project) data.project = settings.assign_project;
2524
if(settings.assign_product) data.product = settings.assign_product;
2625
console.log(`creating device: ${JSON.stringify(data)}`);
2726
return axios({
@@ -42,7 +41,6 @@ module.exports.createBucket = async function(bucketId, bucketName, bucketDescrip
4241
}
4342
if(settings.assign_asset_type) data.asset_type = settings.assign_asset_type;
4443
if(settings.assign_asset_group) data.asset_group = settings.assign_asset_group;
45-
if(settings.assign_project) data.project = settings.assign_project;
4644
if(settings.assign_product) data.product = settings.assign_product;
4745
console.log(`creating bucket: ${JSON.stringify(data)}`);
4846
return axios({
@@ -114,3 +112,21 @@ module.exports.getDeviceProperty = async function(deviceId, propertyId){
114112
url: `/v3/users/${USER}/devices/${deviceId}/properties/${propertyId}`,
115113
});
116114
};
115+
116+
module.exports.setDeviceProject = async function(deviceId, project) {
117+
console.log(`setting project ${project} for ${deviceId}`);
118+
return axios({
119+
method: 'put',
120+
url: `/v1/users/${USER}/devices/${deviceId}/projects`,
121+
data: [ `${USER}@${project}` ]
122+
});
123+
}
124+
125+
module.exports.setBucketProject = async function(bucketId, project) {
126+
console.log(`setting project ${project} for ${bucketId}`);
127+
return axios({
128+
method: 'put',
129+
url: `/v1/users/${USER}/buckets/${bucketId}/projects`,
130+
data: [ `${USER}@${project}` ]
131+
});
132+
}

ttn-stack/task/app.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ async function handleDeviceUplink(req) {
320320
if (payload!==undefined && (error.response && error.response.status===404)) {
321321

322322
// no auto provision
323-
if (!settings.auto_provision_resources && !settings.auto_provision_bucket) return reject(error);
323+
if (!settings.auto_provision_resources) return reject(error);
324324

325325
let realBucketId = getBucketId(deviceId, settings);
326326

@@ -338,6 +338,8 @@ async function handleDeviceUplink(req) {
338338
if ( typeof realBucketId !== 'undefined' ) actions["write_bucket"] = realBucketId;
339339
thinger.setDeviceCallback(realDeviceId, actions, {timeout: getDeviceTimeout(settings)})
340340
})
341+
.then(() => settings.assign_project ? thinger.setDeviceProject(realDeviceId, settings.assign_project) : Promise.resolve())
342+
.then(() => settings.assign_project && settings.auto_provision_bucket ? thinger.setBucketProject(realBucketId, settings.assign_project) : Promise.resolve())
341343
.then(() => updateDeviceProperties(req, realDeviceId, payload, settings))
342344
.then(() => thinger.callDeviceCallback(realDeviceId, processedPayload, sourceIP, timestamp))
343345
.then((response) => { resolve(response); })
@@ -509,7 +511,7 @@ function launchServer() {
509511
settings = {
510512
'Default' : {
511513
auto_provision_resources : false,
512-
auto_provision_bucket: false,
514+
auto_provision_bucket: true,
513515
device_downlink_data : '""'
514516
}
515517
};

ttn-stack/task/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ttn-stack/task/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ttn-stack",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Plugin for handling TTN (v3) integration.",
55
"author": "Alvaro Luis Bustamante",
66
"license": "MIT",

0 commit comments

Comments
 (0)