-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreateDevice.js
More file actions
47 lines (45 loc) · 1.16 KB
/
Copy pathcreateDevice.js
File metadata and controls
47 lines (45 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var request = require('request');
var base = "http://eu.thethings.network:8084";
var setDeviceUrl = "/applications/lorabike/devices";
let config = require('config');
module.exports = function(devId, devEui, description, callback){
var device = {
app_id: "lorabike",
dev_id: devId,
lorawan_device: {
activation_constraints: "local",
app_eui: "70B3D57EF00041F8",
app_id: "lorabike",
app_key: "6F5A76EE295FB19C6E51095DD606498D",
dev_addr: devEui.substring(0,8),
dev_eui: devEui,
dev_id: devId,
disable_f_cnt_check: false,
f_cnt_down: 0,
f_cnt_up: 0,
last_seen: 0,
uses32_bit_f_cnt: true
}
}
var options = {
url : base+setDeviceUrl,
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "key "+config.ttnAccessKey
},
json: device
};
request(options, function(err, res, body){
console.log(err);
console.log("Status = " + res.statusCode);
console.log(body);
if(res.statusCode == 200){
console.log("Success!");
callback(null);
}else{
console.log("Failed");
callback(body);
}
});
};