mini_program_gizwits_sdk 3.0.7 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,24 @@
1
1
  <a href='https://coveralls.io/github/gizwits/mini_program_gizwits_sdk?branch=master'><img src='https://coveralls.io/repos/github/gizwits/mini_program_gizwits_sdk/badge.svg?branch=master' alt='Coverage Status' /></a><img alt="npm" src="https://img.shields.io/npm/v/mini_program_gizwits_sdk">[![Build Status](https://travis-ci.org/gizwits/mini_program_gizwits_sdk.svg?branch=master)](https://travis-ci.org/gizwits/mini_program_gizwits_sdk)
2
2
 
3
- # 机智云小程序 SDK
3
+ # 机智云小程序蓝牙 SDK
4
4
 
5
5
  ## 🔧 安装
6
6
 
7
7
  ```bash
8
+ npm install mini_program_gizwits_sdk
9
+ // or
8
10
  yarn add mini_program_gizwits_sdk
9
11
  ```
10
12
 
13
+ ## 📑 代码示例
14
+ > 采用小程序代码片段,安装新版小程序开发工具,点击链接即可打开
15
+
16
+ ### 蓝牙和softAp配网
17
+ [点击打开微信开发者工具](https://developers.weixin.qq.com/s/SWjCmLmF72y0)
18
+
19
+ ### 设备控制
20
+ [点击打开微信开发者工具](https://developers.weixin.qq.com/s/Cqu8RMmO7pyO)
21
+
11
22
  ## 🏍 初始化 Sdk
12
23
 
13
24
  ```ts
@@ -25,10 +36,10 @@ export default class Index extends Component {
25
36
  productInfo: [
26
37
  {
27
38
  productKey: 'productKey',
28
- productSecrets: 'productSecrets',
39
+ productSecret: 'productSecret',
29
40
  },
30
41
  ],
31
- uid: 'giz_uid',// 必填
42
+ uid: 'giz_uid', // 必填
32
43
  token: 'giz_token', // 必填
33
44
  });
34
45
  }
@@ -39,28 +50,17 @@ export default class Index extends Component {
39
50
  }
40
51
  ```
41
52
 
42
- ## 📖 API
53
+ ## 📖 BLE API
43
54
 
44
- ### sdk.initBle()
55
+ 小程序 BLE 相关 API。
45
56
 
46
- 初始化 sdk 蓝牙能力。
57
+ ### sdk.initBle()
47
58
 
48
- ### sdk.addEventListener(type:K,func:TListenerType[K])
59
+ 初始化 sdk 蓝牙能力。使用其他`BLE API`前**必须**进行初始化。
49
60
 
50
- 注册事件监听。事件种类见下表。
51
- | 事件种类 type | 回调参数类型 | 回调参数描述 |
52
- | ---------- | ------ | ------------------ |
53
- | "OnScanListChange" | IDevice[] | 扫描设备列表 |
54
- | "TDeviceStatusNotifications" | IDeviceStatusNoti | 设备状态变更通知 |
55
- | "TDeviceAttrsNotifications" | IDeviceAttrsNoti | 设备数据点变更通知 |
56
- | "OnBleHandleError" | IError | ble 错误通知 |
61
+ ### sdk.scanBleDevice(delay?:number)
57
62
 
58
- ### sdk.removeEventListener(type:K,func:TListenerType[K])
59
- 销毁事件监听。
60
-
61
- ### sdk.scanBleDevice(delay:number)
62
-
63
- 搜索蓝牙设备。搜索到的蓝牙设备会被`OnScanListChange`监听。
63
+ 搜索蓝牙设备。搜索到的蓝牙设备会被 [onScanListChange](#onScanListChange) 事件监听。
64
64
 
65
65
  #### 参数
66
66
 
@@ -92,12 +92,204 @@ export default class Index extends Component {
92
92
  | mac | string | 待绑定设备 mac |
93
93
  | productKey | string | 待绑定设备所属产品 |
94
94
 
95
- ### sdk.subscribe(device:IDevice)
95
+ ### sdk.subscribe(device:[IDevice](#IDevice) )
96
96
 
97
97
  订阅目标设备,订阅成功后可控制设备。返回值中可以拿到订阅结果。
98
- ### sdk.write(cmd:{[key]:value})
99
- 控制设备。 其中`key`为数据点名称,value为数据点的值。
100
98
 
101
- ### sdk.unSubscribe(device:IDevice)
99
+ ### sdk.write(device:[IDevice](#IDevice),cmd:{[key]:value})
100
+
101
+ 向目标设备发送指令。 其中`key`为数据点名称,value 为数据点的值。
102
+
103
+ ### sdk.unSubscribe(device:[IDevice](#IDevice))
102
104
 
103
105
  取消订阅目标设备。蓝牙设备会断开连接。返回值中可拿到取消订阅结果。
106
+
107
+ ### sdk.addEventListener(type,listener)
108
+
109
+ #### 概览
110
+
111
+ | 事件种类 type | 回调参数类型 | 回调参数描述 |
112
+ | --------------------------- | ------------------------------------- | -------------------- |
113
+ | onScanListChange | [IDevice[]](#IDevice) | 扫描设备列表变更通知 |
114
+ | GizDeviceAttrsNotifications | [IDeviceAttrsNoti](#IDeviceAttrsNoti) | 设备数据点变更通知 |
115
+ | onBleHandleError | [IError](#IError) | ble 错误通知 |
116
+
117
+ - <a id="onScanListChange">onScanListChange</a>
118
+
119
+ ```ts
120
+ const initBle = () => {
121
+ this.gizSdk.initBle();
122
+ };
123
+
124
+ const scanBle = async () => {
125
+ const data = await this.gizSdk.scanBleDevice(60000);
126
+ console.log('scanBle', data);
127
+ };
128
+
129
+ this.gizSdk.addEventListener('onScanListChange', (deviceList: IDevice[]) => {
130
+ console.log('扫描列表发生变化', deviceList);
131
+ deviceListModal.updateScan(deviceList);
132
+ });
133
+
134
+ initBle();
135
+ scanBle();
136
+ ```
137
+
138
+ - <a id="GizDeviceAttrsNotifications">GizDeviceAttrsNotifications</a>
139
+
140
+ 监听设备上报数据。
141
+
142
+ ```ts
143
+ this.gizSdk.addEventListener(
144
+ 'GizDeviceAttrsNotifications',
145
+ ({ device, data }) => {
146
+ console.log("====设备状态发生变化====", device,data);
147
+ };
148
+ );
149
+ ```
150
+
151
+ #### 类型定义
152
+
153
+ - <a id="IDevice">IDevice</a>
154
+
155
+ ```ts
156
+ interface IDevice {
157
+ mac: string; // 设备mac
158
+ productKey: string; // 机智云pk
159
+ did?: string; // 云平台did
160
+ name: string; // 设备名称
161
+ isBind: boolean; // 是否绑定
162
+ bleDeviceID?: string; // 本地蓝牙设备id
163
+ isOnline: boolean; // 代表大循环在线
164
+ isLanOnline: boolean; // 代表小循环在线
165
+ isBleOnline: boolean; // 代表蓝牙在线
166
+ }
167
+ ```
168
+
169
+ - <a id="IDeviceAttrsNoti">IDeviceAttrsNoti</a>
170
+
171
+ ```ts
172
+ interface IDeviceAttrsNoti {
173
+ device: IDevice;
174
+ data: object; // 设备上报数据点
175
+ }
176
+ ```
177
+
178
+ - <a id="IError">IError</a>
179
+
180
+ ```ts
181
+ interface IError {
182
+ errorCode: number;
183
+ errorMessage?: string; // 错误信息
184
+ }
185
+ ```
186
+
187
+ ### sdk.removeEventListener(type:K,func:TListenerType[K])
188
+
189
+ 销毁事件监听。
190
+
191
+ # 机智云小程序 wifi SDK
192
+
193
+ ## 使用方法
194
+
195
+ ```javascript
196
+ import GizwitsSdk, { errorCode } from 'mini_program_gizwits_sdk';
197
+
198
+ const sdk = new GizwitsSdk({
199
+ appID: '8f187b1deb9e44b6aa1374b8f13bccb1',
200
+ appSecret: 'd73fa6d6d7c04d37b6b2cc13a18a9f37',
201
+ specialProductKeys: ['00e7e327afa74a3d8ff1cc190bad78c0'],
202
+ specialProductKeySecrets: ['aa3d301fa291466fbed20e4204609abc'],
203
+ token: token,
204
+ uid: uid,
205
+ cloudServiceInfo: null,
206
+ });
207
+
208
+ try {
209
+ const data = await sdk.setDeviceOnboardingDeploy({
210
+ ssid: SSID,
211
+ password: password,
212
+ mode:3,// 蓝牙配网
213
+ // mode:0 // softAp
214
+ timeout: 60,
215
+ softAPSSIDPrefix: 'XPG-GAgent-',
216
+ });
217
+ } catch (error) {
218
+ console.log(error);
219
+ }
220
+ ```
221
+
222
+ 其中`data`代表配网成功的设备。
223
+
224
+ 如果失败的话会返回数据
225
+
226
+ ```javascript
227
+ {
228
+ success: false,
229
+ err: {
230
+ errorCode: 'code',
231
+ errorMessage: 'message',
232
+ }
233
+ }
234
+ ```
235
+
236
+ ```ts
237
+ const errorCode: IErrorCode = {
238
+ GIZ_OPENAPI_DEVICE_NOT_BOUND: {
239
+ errorCode: 9017,
240
+ errorMessage: 'not bind',
241
+ },
242
+ GIZ_SDK_HTTP_REQUEST_FAILED: {
243
+ errorCode: 8099,
244
+ errorMessage: '网络请求失败',
245
+ },
246
+ GIZ_SDK_SDK_NOT_INITIALIZED: {
247
+ errorCode: 8300,
248
+ errorMessage: 'not init',
249
+ },
250
+ CONFIG_TIME_OUT: {
251
+ errorCode: 8023,
252
+ errorMessage: 'Config Timeout',
253
+ },
254
+ WECHAT_ERROR: {
255
+ errorCode: 10000,
256
+ errorMessage: 'wechat error',
257
+ },
258
+ GIZ_SDK_ONBOARDING_STOPPED: {
259
+ errorCode: 8318,
260
+ errorMessage: '配网中断',
261
+ },
262
+ GIZ_SDK_DEVICE_CONFIG_IS_RUNNING: {
263
+ errorCode: 8022,
264
+ errorMessage: '配置正在进行中',
265
+ },
266
+ GIZ_OPENAPI_TOKEN_INVALID: {
267
+ errorCode: 9004,
268
+ errorMessage: 'token 失效',
269
+ },
270
+ GIZ_SDK_BIND_DEVICE_FAILED: {
271
+ errorCode: 8039,
272
+ errorMessage: '设备绑定失败',
273
+ },
274
+ GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON: {
275
+ errorCode: 8281,
276
+ errorMessage: '蓝牙未启用',
277
+ },
278
+ GIZ_SDK_OTHERWISE: {
279
+ errorCode: 8100,
280
+ errorMessage: '',
281
+ },
282
+ GIZ_SDK_DEVICE_NOT_SUBSCRIBED: {
283
+ errorCode: 8029,
284
+ errorMessage: '设备还未订阅',
285
+ },
286
+ GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY: {
287
+ errorCode: 8250,
288
+ errorMessage: '产品类型不在指定范围内',
289
+ },
290
+ };
291
+ ```
292
+
293
+ ## 🔴 破坏性更新
294
+
295
+ * 原 `productSecrets ` 字段变更为 `productSecret`