Skip to content

Commit 484c44b

Browse files
committed
minor fixed text and add screenshots
1 parent 09a48ed commit 484c44b

File tree

5 files changed

+30
-47
lines changed

5 files changed

+30
-47
lines changed

_includes/docs/pe/user-guide/integrations/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Converter may also output array of device values and/or contain timestamps in th
224224
##### Example
225225

226226
Let's assume a complex example where payload is encoded in hex "value" field and there is a timestamp associated with each record.
227-
First two bytes of "value" field contain battery and second two bytes contain temperature. See payload example and metadata on a screen shoot below:
227+
First two bytes of "value" field contain battery and second two bytes contain temperature. See payload example and metadata on a screen shoot below.
228228

229229
{% include templates/tbel-vs-js.md %}
230230

_includes/templates/integration/overview/uplink-data-converter-example-java.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ The full source code of javascript function used in converter:
55
```shell
66
// decode payload to JSON
77
var data = decodeToJson(payload);
8-
98
var result = [];
10-
119
for (var i in data){
12-
var report = data[i];
13-
var deviceName = report.serialNumber;
14-
var deviceType = metadata.deviceType;
15-
10+
var report = data[i];
11+
var deviceName = report.serialNumber;
12+
var deviceType = metadata.deviceType;
1613
var raw = report.value;
17-
1814
var decoded = hexStringToByte(raw);
1915
// Result object with device attributes/telemetry data
2016
result.push({
2117
deviceName: deviceName,
2218
deviceType: deviceType,
23-
attributes: { model: metadata.model},
19+
attributes: {
20+
model: metadata.model
21+
},
2422
telemetry: {
25-
ts : report.timestamp,
23+
ts: report.timestamp,
2624
values: {
2725
battery: dataConverter(decoded, 0, 2, 100),
2826
temperature: dataConverter(decoded, 2, 4, 100),
@@ -36,7 +34,7 @@ var deviceType = metadata.deviceType;
3634
/** Helper functions **/
3735

3836
function decodeToString(payload) {
39-
return String.fromCharCode.apply(String, payload);
37+
return String.fromCharCode.apply(String, payload);
4038
}
4139

4240
function decodeToJson(payload) {
Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
![image](/images/user-guide/integrations/uplink-converter-example.png)
1+
![image](/images/user-guide/integrations/uplink-converter-example-tbel.png)
22

33
The full source code of TBEL function used in converter:
44

55
```shell
66
// decode payload to JSON
77
var data = decodeToJson(payload);
8-
98
var result = [];
10-
11-
for (var i in data){
12-
var report = data[i];
13-
var deviceName = report.serialNumber;
14-
var deviceType = metadata.deviceType;
15-
9+
for (var i = 0; i < data.length; i++) {
10+
var report = data[i];
11+
var deviceName = report.serialNumber;
12+
var deviceType = metadata.deviceType;
1613
var raw = report.value;
17-
1814
var decoded = hexStringToByte(raw);
1915
// Result object with device attributes/telemetry data
2016
result.push({
2117
deviceName: deviceName,
2218
deviceType: deviceType,
23-
attributes: { model: metadata.model},
19+
attributes: {
20+
model: metadata.model
21+
},
2422
telemetry: {
25-
ts : report.timestamp,
23+
ts: report.timestamp,
2624
values: {
2725
battery: dataConverter(decoded, 0, 2, 100),
2826
temperature: dataConverter(decoded, 2, 4, 100),
@@ -36,44 +34,31 @@ var deviceType = metadata.deviceType;
3634
/** Helper functions **/
3735

3836
function decodeToString(payload) {
39-
return String.fromCharCode.apply(String, payload);
40-
}
41-
42-
function decodeToJson(payload) {
43-
// covert payload to string.
44-
var str = decodeToString(payload);
45-
46-
// parse string to JSON
47-
var data = JSON.parse(str);
48-
return data;
37+
return String.fromCharCode.apply(String, payload);
4938
}
5039

5140
function hexStringToByte(str) {
52-
if (!str) {
53-
return new Uint8Array();
54-
}
55-
5641
var a = [];
57-
for (var i = 0, len = str.length; i < len; i+=2) {
58-
a.push(parseInt(str.substr(i,2),16));
42+
if (str == null) {
43+
return a;
5944
}
60-
61-
return new Uint8Array(a);
45+
for (var j = 0; j < str.length; j += 2) {
46+
a.push(parseInt(str.substring(j, j + 2), 16));
47+
}
48+
return a;
6249
}
6350

6451
function dataConverter(decoded, byteIdxFrom, byteIdxTo, divided) {
65-
var bytes = decoded.subarray(byteIdxFrom, byteIdxTo);
66-
52+
// var bytes = decoded.subarray(byteIdxFrom, byteIdxTo);
6753
var val = 0;
68-
for (var j = 0; j < bytes.length; j++) {
69-
val += bytes[j];
70-
if (j < bytes.length - 1) {
54+
for (var j = byteIdxFrom; j < byteIdxTo; j++) {
55+
val += decoded[j];
56+
if (j < byteIdxTo - 1) {
7157
val = val << 8;
7258
}
7359
}
74-
return val/divided;
60+
return val / divided;
7561
}
76-
7762
return result;
7863
```
7964
{: .copy-code}
Loading
Loading

0 commit comments

Comments
 (0)