Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
visualcloud
/
Vmatrix-client-taro
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0f9ec355
authored
Aug 22, 2019
by
lirandong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接通 设备端连接WiFi功能
parent
332c60fe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
src/common/bluetooth.ts
+6
-5
src/common/utils.ts
+18
-3
No files found.
src/common/bluetooth.ts
View file @
0f9ec355
...
...
@@ -89,7 +89,7 @@ class Bluetooth {
// 获取 WiFi 列表
this
.
formatWifiList
(
deviceId
,
value
)
break
case
WIFI_CHARACTERISTIC
_ID
:
case
POST_WIFI_PASS
_ID
:
// WiFi 连接状态回调
this
.
formatWifiLine
(
value
)
default
:
...
...
@@ -134,12 +134,13 @@ class Bluetooth {
}
}
/** 整理WiFi连接信息 */
/** 整理WiFi连接
状态
信息 */
formatWifiLine
(
value
:
arrayBuffer
)
{
console
.
log
(
'ArrayBufferToString'
,
ArrayBufferToString
(
value
))
const
str
=
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
value
))
console
.
log
(
'ArrayBufferToString'
,
str
)
}
/** 向
蓝牙
发送WiFi密码 */
/** 向
设备端
发送WiFi密码 */
async
postWifiPassword
(
id
:
number
,
pass
:
string
,
deviceId
:
string
)
{
await
bluetooth
.
notifyBLECharacteristicValueChange
({
deviceId
,
...
...
@@ -150,7 +151,7 @@ class Bluetooth {
return
bluetooth
.
writeBLECharacteristicValue
({
deviceId
,
serviceId
:
BLE_SERVICE_ID
,
value
:
strToAb
(
id
+
pass
),
value
:
strToAb
(
id
,
pass
),
characteristicId
:
POST_WIFI_PASS_ID
})
}
...
...
src/common/utils.ts
View file @
0f9ec355
...
...
@@ -48,14 +48,28 @@ export function getWindiwHeight() {
return
windowHeight
-
HeaderHeight
}
/** ArrayBuffer转16进
度
字符串 */
export
function
ArrayBufferToString
(
buffer
:
ArrayBuffer
)
{
/** ArrayBuffer转16进
制
字符串 */
export
function
ArrayBufferToString
(
buffer
:
ArrayBuffer
,
toText
:
boolean
=
false
)
{
const
hexArr
:
any
[]
=
Array
.
prototype
.
map
.
call
(
new
Uint8Array
(
buffer
),
bit
=>
{
return
(
'00'
+
bit
.
toString
(
16
)).
slice
(
-
2
)
})
if
(
toText
)
{
hexArr
.
forEach
(
element
=>
{
element
=
element
.
charAt
()
console
.
log
(
'element.charAt()'
,
element
)
})
}
return
hexArr
.
join
(
''
)
}
// /** ArrayBuffer转文字 */
// export function ArrayBufferToText(buffer: ArrayBuffer) {
// const hexArr: any[] = Array.prototype.map.call(new Uint8Array(buffer), bit => {
// return ('00' + bit.toString(16)).slice(-2)
// })
// return hexArr.join('')
// }
/** 解析蓝牙接收到的 十六进制 状态 */
export
function
getBLEState
(
buffer
:
ArrayBuffer
)
{
return
new
Uint8Array
(
buffer
)[
0
]
...
...
@@ -73,12 +87,13 @@ export function getAdverts(BleInfo: Taro.onBluetoothDeviceFound.ParamParamPropDe
}
/** 字符串转 ArrayBuffer */
export
function
strToAb
(
str
:
string
)
{
export
function
strToAb
(
id
:
number
,
str
:
string
)
{
const
codeArr
:
number
[]
=
[]
console
.
log
({
str
})
for
(
let
i
=
0
;
i
<
str
.
length
;
i
++
)
{
codeArr
.
push
(
str
.
charCodeAt
(
i
))
}
console
.
log
({
codeArr
})
codeArr
.
unshift
(
id
)
return
new
Uint8Array
(
codeArr
).
buffer
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment