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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# PT3SBT Workflow
## Import PT3SBT Module
```js
import {
PT3SBTModule,
PT3SBTProfileModule
} from '@ihealth/ihealthlibrary-react-native';
```
## APIs
### Add and remove listener
```js
// add
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
console.log(event);
});
// remove
notifyListener.remove();
```
### set time
```js
PT3SBTModule.setTime(mac);
// response
// {status: "success", type: "PT3SBT", mac: "004D320C41BE", action: "action_set_time"}
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_SET_TIME) {
console.log(event[NT13BProfileModule.STATUS]);
}
});
```
### get battery
```js
PT3SBTModule.getBattery(mac);
// response
// { battery: 70, type: "PT3SBT", mac: "004D320C41BE", action: "action_get_battery"}
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_GET_BATTERY) {
console.log(event[PT3SBTProfileModule.BATTERY]);
}
});
```
### set unit
```js
// 1: centigrade, 2: fahrenheit
PT3SBTModule.setUnit(mac, unit);
// response
// {status: "success", type: "PT3SBT", mac: "004D320C41BE", action: "action_set_unit"}
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_SET_UNIT) {
console.log(event[PT3SBTProfileModule.STATUS]);
}
});
```
### get unit
```js
PT3SBTModule.getUnit(mac);
// response
// {unit: 2, type: "PT3SBT", mac: "004D320C41BE", action: "action_get_unit"}
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_GET_UNIT) {
console.log(event[PT3SBTProfileModule.UNIT]);
}
});
```
### get history data count
```js
PT3SBTModule.getHistoryCount(mac);
// response
// {count: 37, type: "PT3SBT", mac: "004D320C41BE", action: "action_get_history_count"}
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_GET_HISTORY_COUNT) {
console.log(event[PT3SBTProfileModule.COUNT]);
}
});
```
### get history data
**Note: After call get history data, must to delele history data. If don't, the PT3SBT will keep on offline mode.**
```js
PT3SBTModule.getHistoryData(mac);
// response
// {history: Array, type: "PT3SBT", mac: "004D320C41BE", action: "action_get_history_data"}
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_GET_HISTORY_DATA) {
const arr = event[PT3SBTProfileModule.HISTORY];
arr.foreach(item => {
console.log(item[PT3SBTProfileModule.TEMPERATURE]);
console.log(item[PT3SBTProfileModule.TS]);
})
}
});
```
### delete history data
```js
PT3SBTModule.deleteHistoryData(mac);
// response
// {status: "success", type: "PT3SBT", mac: "004D320C41BE", action: "action_delete_history_data"}
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_DELETE_HISTORY_DATA) {
console.log(event[PT3SBTProfileModule.STATUS]);
}
});
```
### online measurement
```js
// response
// {Tbody: 3845", type: "PT3SBT", mac: "004D320C41BE", action: "action_temperature_measurement"}
// the real temperature is Tbody / 100, this is centigrade
notifyListener = DeviceEventEmitter.addListener(PT3SBTModule.Event_Notify, (event) => {
if (event.action === PT3SBTProfileModule.ACTION_TEMPERATURE_MEASUREMENT) {
console.log(event[PT3SBTProfileModule.TEMPERATURE]);
}
});
```
|