index.html
6.49 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<html>
<head>
<title>Home</title>
<meta charset="UTF-8"/>
<style>
#user {
font-size: 20px;
color: red
}
</style>
<script>
function onBleConnectStart() {
document.getElementById("user").innerHTML = "开始连接";
}
function onBleConnectFailure(value) {
document.getElementById("user").innerHTML = "连接失败\n"+value;
}
function onBleConnectSuccess(value) {
document.getElementById("user").innerHTML = "连接成功\n"+value;
}
function onBleDisconnect(isActiveDisConnected) {
document.getElementById("user").innerHTML = "断开连接\n"+isActiveDisConnected;
}
function onBleOpenNotifySuccess() {
document.getElementById("user").innerHTML = "订阅通知成功\n";
}
function onBleOpenNotifyFailure(value) {
document.getElementById("user").innerHTML = "订阅通知失败\n"+value;
}
function onBleStopNotifyFailure(value) {
document.getElementById("user").innerHTML = "取消订阅通知失败\n"+value;
}
function onBleNotifyCheckExceptionResult(value) {
document.getElementById("user").innerHTML = "通知返回\n"+value;
}
function onBleOpenIndicateSuccess() {
document.getElementById("user").innerHTML = "订阅Indicate成功\n";
}
function onBleOpenIndicateFailure(value) {
document.getElementById("user").innerHTML = "订阅Indicate失败\n"+value;
}
function onBleStopIndicateFailure(value) {
document.getElementById("user").innerHTML = "取消订阅Indicate失败\n"+value;
}
function onBleIndicateCheckExceptionResult(value) {
document.getElementById("user").innerHTML = "Indicate返回\n"+value;
}
function onBleWriteSuccess(value) {
document.getElementById("user").innerHTML = "写成功\n"+value;
}
function onBleWriteFailure(value) {
document.getElementById("user").innerHTML = "写失败\n"+value;
}
function onBleReadSuccess(value) {
document.getElementById("user").innerHTML = "读取成功\n"+value;
}
function onBleReadFailure(value) {
document.getElementById("user").innerHTML = "读取失败\n"+value;
}
function onBleReadRssiSuccess(value) {
document.getElementById("user").innerHTML = "读取信号成功\n"+value;
}
function onBleReadRssiFailure(value) {
document.getElementById("user").innerHTML = "读取信号失败\n"+value;
}
function onBleSetMtuSuccess(value) {
document.getElementById("user").innerHTML = "设置Mtu成功\n"+value;
}
function onBleSetMtuFailure(value) {
document.getElementById("user").innerHTML = "设置Mtu失败\n"+value;
}
function onBleScaning(value) {
document.getElementById("user").innerHTML = value;
}
function onBleScanFinished(value) {
document.getElementById("user").innerHTML = value;
}
function onBleNullError(value) {
document.getElementById("user").innerHTML = value;
}
function onBleCreateBonding() {
document.getElementById("user").innerHTML = “配对中”;
}
function onBleCreateBondFailure(value) {
document.getElementById("user").innerHTML = value;
}
function onBleCreateBondSuccess() {
document.getElementById("user").innerHTML = “配对成功”;
}
function Str2Bytes(str){
var pos = 0;
var len = str.length;
if(len %2 != 0)
{
return null;
}
len /= 2;
var hexA = new Array();
for(var i=0; i<len; i++)
{
var s = str.substr(pos, 2);
var v = parseInt(s, 16);
hexA.push(v);
pos += 2;
}
return hexA;
}
function getStr2Bytes(){
var str = '{"mac":"1C:99:57:BE:9D:A7"}';
return str;
}
</script>
</head>
<body>
<p id="user">原生WebView</p>
<button type="button" onclick="window.myble.bleConnect(getStr2Bytes())"/>
连接</button>
<button type="button"
onclick="window.myble.bleOpenNotify('0000FFF0-0000-1000-8000-00805F9B34FB','0000FFF1-0000-1000-8000-00805F9B34FB')"/>
订阅通知</button>
<button type="button"
onclick="window.myble.bleStopNotify('0000FFF0-0000-1000-8000-00805F9B34FB','0000FFF1-0000-1000-8000-00805F9B34FB')"/>
取消订阅通知</button>
<button type="button"
onclick="window.myble.bleOpenIndicate('0000FFF0-0000-1000-8000-00805F9B34FB','0000FFF1-0000-1000-8000-00805F9B34FB')"/>
订阅Indicate</button>
<button type="button"
onclick="window.myble.bleStopIndicate('0000FFF0-0000-1000-8000-00805F9B34FB','0000FFF1-0000-1000-8000-00805F9B34FB')"/>
取消订阅Indicate</button>
<button type="button"
onclick="window.myble.bleWrite('0000FFF0-0000-1000-8000-00805F9B34FB','0000FFF2-0000-1000-8000-00805F9B34FB',Str2Bytes('7B3083AD47D74921E96D88F9A8979A429ED2B87D'))"/>
写入</button>
<button type="button"
onclick="window.myble.bleRead('0000FFF0-0000-1000-8000-00805F9B34FB','0000FFF2-0000-1000-8000-00805F9B34FB')"/>
读取</button>
<button type="button"
onclick="window.myble.bleReadRssi()"/>
获取信号强度Rssi</button>
<button type="button"
onclick="window.myble.bleSetMtu(50)"/>
设置Mtu</button>
<button type="button" onclick="window.myble.bleDisConnect()"/>
断开连接</button>
<button type="button" onclick="window.myble.bleDisConnectAllDevice()"/>
断开所有连接</button>
<button type="button" onclick="window.myble.bleScan()"/>
开始扫描</button>
<button type="button" onclick="window.myble.bleCancelScan()"/>
取消扫描</button>
</body>
<button type="button" onclick="window.myble.bleInitScanRule(null,[],null,false,10000)"/>
配置扫描规则</button>
</body>
</html>