forked from TheThingsArchive/node-app-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
64 lines (55 loc) · 1.53 KB
/
example.js
File metadata and controls
64 lines (55 loc) · 1.53 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import ttn from "."
// This package provides a sample to test the sdk.
// Replace the app-id and the dev-id and provide your credentials to test it
var options = {
region: "eu" // Your region (eu or us),
key: "", // Your app access key
}
var client = new ttn.manager.HTTP(options)
client.getDevice("app-id", "dev-id"
.then(function (device) {
console.log(device)
})
.catch(function (error) {
console.error("Got error", error)
})
client.getDevicesForApplication("app-id")
.then(function (devices) {
console.log(devices)
})
.catch(function (error) {
console.error("Got error", error)
})
client.registerApplication("app-id", {})
.then(function () {
console.log("Registered!")
})
.catch(function (error) {
console.error("Got error", error)
})
client.setApplication("app-id", {
converter: "function Converter(decoded, port) { return {name: John, lastname: Snow}; }",
decoder: "function Decoder(bytes, port) { return {test: value}; }",
validator: "function Validator(conve, port) { return false; }",
encoder: "function Encoder(object, port) { return []; }",
})
.then(function () {
console.log("Set!")
})
.catch(function (error) {
console.error("Got error", error)
})
client.getApplication("app-id")
.then(function (app) {
console.log(app);
})
.catch(function (error) {
console.error("Got error", error)
})
client.setDevice("app-id", "dev-id", {})
.then(function () {
console.log("Set!")
})
.catch(function (error) {
console.error("Got error", error)
})