mini_program_gizwits_sdk 3.6.0 → 3.6.2
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 +57 -15
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -3
- package/dist/package.json +55 -0
- package/dist/src/GizLog.d.ts +1 -1
- package/dist/src/errorCode.d.ts +1 -3
- package/dist/src/handler/ble.d.ts +5 -66
- package/dist/src/handler/lan.d.ts +3 -18
- package/dist/src/handler/socket.d.ts +1 -0
- package/dist/src/openApiRequest.d.ts +1 -5
- package/dist/src/productConfigFileManage.d.ts +3 -6
- package/dist/src/protocol/OTA/CheckCanOTA.d.ts +1 -1
- package/dist/src/protocol/{DataPoint.d.ts → dataPoint.d.ts} +0 -34
- package/dist/src/randomCode.d.ts +1 -5
- package/dist/src/sdk.d.ts +9 -104
- package/dist/src/sdk.js +1101 -0
- package/dist/src/services/devices.d.ts +1 -17
- package/dist/src/services/login.d.ts +2 -6
- package/dist/src/services/monitor.d.ts +2 -1
- package/dist/src/services/monitor.js +72 -0
- package/dist/src/services/ota.d.ts +2 -6
- package/dist/src/services/uploadP0.d.ts +2 -1
- package/dist/src/types/index.d.ts +360 -0
- package/dist/src/utils.d.ts +1 -6
- package/dist/src/wechatApi.d.ts +1 -22
- package/dist/src/wifiConfig/ConfigBase.d.ts +2 -9
- package/dist/src/wifiConfig/ap.d.ts +1 -11
- package/dist/src/wifiConfig/ble.d.ts +2 -8
- package/dist/src/wifiConfig/nfc/index.d.ts +2 -2
- package/global.d.ts +3 -19
- package/index.ts +2 -0
- package/package.json +2 -2
- package/src/errorCode.ts +3 -3
- package/src/handler/ble.ts +4 -79
- package/src/handler/lan.ts +3 -24
- package/src/handler/socket.ts +3 -0
- package/src/openApiRequest.ts +2 -14
- package/src/productConfigFileManage.ts +3 -5
- package/src/protocol/OTA/AwaitNoti.ts +0 -2
- package/src/protocol/OTA/CheckCanOTA.ts +1 -2
- package/src/protocol/OTA/OTAPackPackage.ts +1 -1
- package/src/protocol/OTA/PreOTA.ts +2 -3
- package/src/protocol/OTA/ResetPosition.ts +1 -2
- package/src/protocol/dataPoint.ts +1 -42
- package/src/randomCode.ts +1 -12
- package/src/sdk.ts +11 -114
- package/src/services/devices.ts +2 -22
- package/src/services/login.ts +1 -5
- package/src/services/monitor.ts +1 -0
- package/src/services/ota.ts +1 -5
- package/src/services/uploadP0.ts +1 -0
- package/src/types/index.ts +455 -0
- package/src/utils.ts +1 -6
- package/src/wechatApi.ts +1 -22
- package/src/wifiConfig/ConfigBase.ts +2 -10
- package/src/wifiConfig/ap.ts +1 -13
- package/src/wifiConfig/ble.ts +2 -9
- package/src/wifiConfig/nfc/index.ts +1 -4
- package/src/global.d.ts +0 -52
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
import { IServiceResult } from '../
|
|
2
|
-
import { IRandomCodesResult } from '../sdk';
|
|
3
|
-
export interface IOpenApiDevice {
|
|
4
|
-
product_key: string;
|
|
5
|
-
did: string;
|
|
6
|
-
mac: string;
|
|
7
|
-
passcode: string;
|
|
8
|
-
is_online: boolean;
|
|
9
|
-
host: string;
|
|
10
|
-
port: string;
|
|
11
|
-
port_s: string;
|
|
12
|
-
ws_port: number;
|
|
13
|
-
wss_port: number;
|
|
14
|
-
dev_alias: string;
|
|
15
|
-
remark: string;
|
|
16
|
-
type: 'normal' | 'center_control' | 'sub_dev';
|
|
17
|
-
}
|
|
1
|
+
import { IDevice, IOpenApiDevice, IRandomCodesResult, IServiceResult } from '../types';
|
|
18
2
|
export declare const getBindingList: () => Promise<IServiceResult<IDevice[]>>;
|
|
19
3
|
export interface IBindMacParams {
|
|
20
4
|
mac: string;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
expire_at: number;
|
|
3
|
-
token: string;
|
|
4
|
-
uid: string;
|
|
5
|
-
}
|
|
1
|
+
import { ILoginRes } from "../types";
|
|
6
2
|
export declare function AnonymousLogin({ uid }: {
|
|
7
3
|
uid: string;
|
|
8
|
-
}): Promise<import("../
|
|
4
|
+
}): Promise<import("../types").IServiceResult<ILoginRes>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IDevice } from '../types';
|
|
1
2
|
type EventType = "BleDeviceConnectStart" | "BleDeviceConnectEnd" | "BleDeviceConnectBind" | "BleDeviceConnectLogin" | "BleDeviceConnectFinish";
|
|
2
3
|
type FailureType = Omit<EventType, 'BleDeviceConnectStart' | 'BleDeviceConnectFinish'>;
|
|
3
4
|
interface IProps {
|
|
@@ -7,5 +8,5 @@ interface IProps {
|
|
|
7
8
|
success: boolean;
|
|
8
9
|
failureType?: FailureType;
|
|
9
10
|
}
|
|
10
|
-
export declare function reportEvent({ device, eventID, eventType, success, failureType }: IProps): Promise<import("../
|
|
11
|
+
export declare function reportEvent({ device, eventID, eventType, success, failureType }: IProps): Promise<import("../types").IServiceResult<any>>;
|
|
11
12
|
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.reportEvent = void 0;
|
|
16
|
+
const package_json_1 = require("../../package.json");
|
|
17
|
+
const globalData_1 = require("../globalData");
|
|
18
|
+
const openApiRequest_1 = __importDefault(require("../openApiRequest"));
|
|
19
|
+
class BaseInfo {
|
|
20
|
+
constructor() {
|
|
21
|
+
wx.getSystemInfoAsync({
|
|
22
|
+
success: (res) => {
|
|
23
|
+
this.app = {
|
|
24
|
+
wxSdkVersion: res.SDKVersion,
|
|
25
|
+
gizwitsSdkVersion: package_json_1.version,
|
|
26
|
+
appID: 'unknown',
|
|
27
|
+
bluetoothEnabled: res.bluetoothEnabled,
|
|
28
|
+
locationEnabled: res.locationEnabled,
|
|
29
|
+
wifiEnabled: res.wifiEnabled,
|
|
30
|
+
};
|
|
31
|
+
this.mobile = {
|
|
32
|
+
brand: res.brand,
|
|
33
|
+
model: res.model,
|
|
34
|
+
pixelRatio: res.pixelRatio,
|
|
35
|
+
systemVersion: res.system,
|
|
36
|
+
platform: res.platform,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
updateAppId(appId) {
|
|
42
|
+
this.app.appID = appId;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const baseInfo = new BaseInfo();
|
|
46
|
+
function reportEvent({ device, eventID, eventType, success, failureType }) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
baseInfo.updateAppId((0, globalData_1.getGlobalData)('appID') || 'unknown');
|
|
49
|
+
const path = `/v2/products/${device.productKey}/devices/bluetooth-connect-data`;
|
|
50
|
+
const curDate = new Date();
|
|
51
|
+
const eventData = {
|
|
52
|
+
origin: "MINI-WX",
|
|
53
|
+
mobileInfo: baseInfo.mobile,
|
|
54
|
+
userInfo: null,
|
|
55
|
+
appInfo: baseInfo.app,
|
|
56
|
+
eventID,
|
|
57
|
+
eventType,
|
|
58
|
+
monitorTarget: {
|
|
59
|
+
device,
|
|
60
|
+
success,
|
|
61
|
+
failureType,
|
|
62
|
+
},
|
|
63
|
+
time: curDate,
|
|
64
|
+
timeStamp: Math.floor(curDate.getTime() / 1000),
|
|
65
|
+
};
|
|
66
|
+
return (0, openApiRequest_1.default)(path, {
|
|
67
|
+
data: eventData,
|
|
68
|
+
method: 'POST',
|
|
69
|
+
}, true);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.reportEvent = reportEvent;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { IOTAType } from "../
|
|
2
|
-
export interface OTARes {
|
|
3
|
-
download_url: string;
|
|
4
|
-
soft_ver: string;
|
|
5
|
-
}
|
|
1
|
+
import { IOTAType, OTARes } from "../types";
|
|
6
2
|
export declare function checkUpdate({ did, type, hardVersion, softVersion }: {
|
|
7
3
|
did: string;
|
|
8
4
|
type: IOTAType;
|
|
9
5
|
hardVersion: string;
|
|
10
6
|
softVersion: string;
|
|
11
|
-
}): Promise<import("../
|
|
7
|
+
}): Promise<import("../types").IServiceResult<OTARes>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IDevice } from "../types";
|
|
1
2
|
export interface IUploadRes {
|
|
2
3
|
}
|
|
3
4
|
interface IData {
|
|
@@ -9,5 +10,5 @@ interface IProps {
|
|
|
9
10
|
data: IData[];
|
|
10
11
|
productSecret: string;
|
|
11
12
|
}
|
|
12
|
-
export declare function uploadP0({ device, data, productSecret }: IProps): Promise<import("../
|
|
13
|
+
export declare function uploadP0({ device, data, productSecret }: IProps): Promise<import("../types").IServiceResult<IUploadRes>>;
|
|
13
14
|
export {};
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { TCPHandler } from "../handler/lan";
|
|
2
|
+
import DiscoverUDP from "../protocol/DiscoverUDP";
|
|
3
|
+
import { wrapErrorInfo } from "../utils";
|
|
4
|
+
export type TUtf8 = {
|
|
5
|
+
toBytes: (data: any) => any;
|
|
6
|
+
};
|
|
7
|
+
export type TUtils = {
|
|
8
|
+
utf8: TUtf8;
|
|
9
|
+
};
|
|
10
|
+
export interface ecb {
|
|
11
|
+
new (data: any): any;
|
|
12
|
+
}
|
|
13
|
+
export type TModeOfOperation = {
|
|
14
|
+
ecb: ecb;
|
|
15
|
+
};
|
|
16
|
+
export interface IError {
|
|
17
|
+
errorCode: number;
|
|
18
|
+
errorMessage?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ICommonObj {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}
|
|
23
|
+
export interface IDeviceStatusChangedProps {
|
|
24
|
+
did: string;
|
|
25
|
+
attrs: ICommonObj;
|
|
26
|
+
}
|
|
27
|
+
export interface IDeviceRawStatusChangedProps {
|
|
28
|
+
did: string;
|
|
29
|
+
raw: Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
export interface IOnDeviceStatusChanged {
|
|
32
|
+
(data: IDeviceStatusChangedProps | IDeviceRawStatusChangedProps): void;
|
|
33
|
+
}
|
|
34
|
+
export interface IOnSocketStatusChanged {
|
|
35
|
+
(dids: string[], enabled: boolean): void;
|
|
36
|
+
}
|
|
37
|
+
export interface IEmptyFn {
|
|
38
|
+
(): void;
|
|
39
|
+
}
|
|
40
|
+
export interface IDevice {
|
|
41
|
+
mac: string;
|
|
42
|
+
productKey: string;
|
|
43
|
+
did: string;
|
|
44
|
+
bleWorkStatus?: number;
|
|
45
|
+
name: string;
|
|
46
|
+
isBind: boolean;
|
|
47
|
+
rootDeviceId?: string;
|
|
48
|
+
bleDeviceID?: string;
|
|
49
|
+
remark?: string;
|
|
50
|
+
passcode?: string;
|
|
51
|
+
connectType: TConnectType;
|
|
52
|
+
isOnline: boolean;
|
|
53
|
+
isLanOnline: boolean;
|
|
54
|
+
isBleOnline: boolean;
|
|
55
|
+
host?: string;
|
|
56
|
+
wss_port?: number;
|
|
57
|
+
ctime?: number;
|
|
58
|
+
}
|
|
59
|
+
export type TConnectType = 'BLE' | 'BLE_BROADCAST' | 'LAN' | 'WAN' | 'NONE';
|
|
60
|
+
export interface IBluetoothAdapterStateResult {
|
|
61
|
+
discovering: boolean;
|
|
62
|
+
available: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface IWechatResult {
|
|
65
|
+
errMsg: string;
|
|
66
|
+
errCode: number;
|
|
67
|
+
}
|
|
68
|
+
export interface IWXDevicesResult {
|
|
69
|
+
success: true;
|
|
70
|
+
bleDevices: WechatMiniprogram.BlueToothDevice[];
|
|
71
|
+
}
|
|
72
|
+
export interface SyncCallBackParams {
|
|
73
|
+
event: TSyncEvnet;
|
|
74
|
+
currentNum?: number;
|
|
75
|
+
totalNum?: number;
|
|
76
|
+
message?: string;
|
|
77
|
+
}
|
|
78
|
+
export type TSyncEvnet = 'SYNC_START' | 'SYNC_END' | 'SYNC_FAIL' | 'SYNC_CANCEL' | 'SYNC_PROGRESS';
|
|
79
|
+
export type SyncCallBack = (data: SyncCallBackParams) => void;
|
|
80
|
+
export type IOTAType = 'MCU' | 'MODULE';
|
|
81
|
+
export interface ISDKResult<T> {
|
|
82
|
+
data?: T;
|
|
83
|
+
err?: IError;
|
|
84
|
+
message?: string;
|
|
85
|
+
success: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface ISetCommonDeviceOnboardingDeployProps {
|
|
88
|
+
ssid: string;
|
|
89
|
+
bssid?: string;
|
|
90
|
+
password: string;
|
|
91
|
+
timeout: number;
|
|
92
|
+
isBind?: boolean;
|
|
93
|
+
mode?: 0 | 3 | 5;
|
|
94
|
+
softAPSSIDPrefix?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface ISetDeviceOnboardingDeployProps extends ISetCommonDeviceOnboardingDeployProps {
|
|
97
|
+
softAPSSIDPrefix: string;
|
|
98
|
+
eventCallBack: (event: ConfigEventData) => void;
|
|
99
|
+
}
|
|
100
|
+
export interface IRandomCodesResult {
|
|
101
|
+
random_code: string;
|
|
102
|
+
product_key: string;
|
|
103
|
+
mac: string;
|
|
104
|
+
did: string;
|
|
105
|
+
user_id: string;
|
|
106
|
+
timestamp: number;
|
|
107
|
+
type: string;
|
|
108
|
+
wifi_soft_ver: string;
|
|
109
|
+
lan_proto_ver: string;
|
|
110
|
+
}
|
|
111
|
+
export interface IBindRemoteDeviceParams {
|
|
112
|
+
productKey: string;
|
|
113
|
+
mac: string;
|
|
114
|
+
beOwner?: boolean;
|
|
115
|
+
alias?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface IDeviceStatusNoti {
|
|
118
|
+
device: IDevice;
|
|
119
|
+
connectType: TConnectType;
|
|
120
|
+
}
|
|
121
|
+
export interface IDeviceAttrsNoti {
|
|
122
|
+
device: IDevice;
|
|
123
|
+
data: object;
|
|
124
|
+
}
|
|
125
|
+
export interface TListenerType {
|
|
126
|
+
GizDeviceListNotifications: TDeviceListNotifications;
|
|
127
|
+
GizDeviceStatusNotifications: TDeviceStatusNotifications;
|
|
128
|
+
GizDeviceAttrsNotifications: TDeviceAttrsNotifications;
|
|
129
|
+
onScanListChange: OnScanListChange;
|
|
130
|
+
onBleHandleError: OnBleHandleError;
|
|
131
|
+
}
|
|
132
|
+
export type TDeviceListNotifications = (devices: IDevice[]) => void;
|
|
133
|
+
export type TDeviceStatusNotifications = (data: IDeviceStatusNoti) => void;
|
|
134
|
+
export type TDeviceAttrsNotifications = (data: IDeviceAttrsNoti) => void;
|
|
135
|
+
export type OnScanListChange = (devices: IDevice[]) => void;
|
|
136
|
+
export type OnBleHandleError = (error: IError) => void;
|
|
137
|
+
export interface IDeviceSafetyRegisterParams {
|
|
138
|
+
mac: string;
|
|
139
|
+
productKey: string;
|
|
140
|
+
}
|
|
141
|
+
export interface IDeviceSafetyParams extends IDeviceSafetyRegisterParams {
|
|
142
|
+
isReset: boolean;
|
|
143
|
+
}
|
|
144
|
+
export interface IResult<T> {
|
|
145
|
+
success: boolean;
|
|
146
|
+
data?: T;
|
|
147
|
+
err?: IError;
|
|
148
|
+
}
|
|
149
|
+
export interface ICloudServiceInfo {
|
|
150
|
+
openAPIInfo: string;
|
|
151
|
+
}
|
|
152
|
+
export type TimeoutHandle = ReturnType<typeof setTimeout> | null;
|
|
153
|
+
export type IntervalHandle = ReturnType<typeof setInterval> | null;
|
|
154
|
+
export interface IProductInfo {
|
|
155
|
+
productKey: string;
|
|
156
|
+
productSecret: string;
|
|
157
|
+
}
|
|
158
|
+
export interface GizwitsSdkOption {
|
|
159
|
+
appID: string;
|
|
160
|
+
appSecret: string;
|
|
161
|
+
productInfo: IProductInfo[];
|
|
162
|
+
cloudServiceInfo?: ICloudServiceInfo;
|
|
163
|
+
token?: string;
|
|
164
|
+
uid?: string;
|
|
165
|
+
offlineThreshold?: number;
|
|
166
|
+
}
|
|
167
|
+
export interface IRejectCallback {
|
|
168
|
+
(result: IResult<unknown>): void;
|
|
169
|
+
}
|
|
170
|
+
export type TConfigEvent = 'GIZ_CONFIG_START' | 'GIZ_DISCOVER_SUCCESS' | 'GIZ_CONNECT_SUCCESS' | 'GIZ_CONFIG_SEND_SUCCESS' | 'GIZ_CONFIG_RECV_SUCCESS' | 'GIZ_CONFIG_SUCCESS';
|
|
171
|
+
export interface ConfigEventData {
|
|
172
|
+
event: TConfigEvent;
|
|
173
|
+
deviceID?: string;
|
|
174
|
+
}
|
|
175
|
+
export interface IOpenApiDevice {
|
|
176
|
+
product_key: string;
|
|
177
|
+
did: string;
|
|
178
|
+
mac: string;
|
|
179
|
+
passcode: string;
|
|
180
|
+
is_online: boolean;
|
|
181
|
+
host: string;
|
|
182
|
+
port: string;
|
|
183
|
+
port_s: string;
|
|
184
|
+
ws_port: number;
|
|
185
|
+
wss_port: number;
|
|
186
|
+
dev_alias: string;
|
|
187
|
+
remark: string;
|
|
188
|
+
type: 'normal' | 'center_control' | 'sub_dev';
|
|
189
|
+
}
|
|
190
|
+
export interface IDeviceRes {
|
|
191
|
+
devices: IOpenApiDevice[];
|
|
192
|
+
}
|
|
193
|
+
export interface IErrorCode {
|
|
194
|
+
[key: string]: IError;
|
|
195
|
+
}
|
|
196
|
+
export interface IWechatApiResult<T> {
|
|
197
|
+
data: T;
|
|
198
|
+
errMsg: string;
|
|
199
|
+
statusCode: number;
|
|
200
|
+
}
|
|
201
|
+
export interface IServiceResult<T> {
|
|
202
|
+
success: boolean;
|
|
203
|
+
data?: T;
|
|
204
|
+
err?: IError;
|
|
205
|
+
}
|
|
206
|
+
export interface IGetRandomCodes {
|
|
207
|
+
SSID: string;
|
|
208
|
+
password: string;
|
|
209
|
+
pks: string[];
|
|
210
|
+
}
|
|
211
|
+
export interface IGetRandomCode {
|
|
212
|
+
SSID: string;
|
|
213
|
+
password: string;
|
|
214
|
+
pk: string;
|
|
215
|
+
}
|
|
216
|
+
export interface IProductConfigData {
|
|
217
|
+
[key: string]: IDataPointConfig;
|
|
218
|
+
}
|
|
219
|
+
export interface IDataPointConfig {
|
|
220
|
+
name: string;
|
|
221
|
+
protocolType: 'var_len' | 'standard';
|
|
222
|
+
entities: IDataPointEntitie[];
|
|
223
|
+
}
|
|
224
|
+
export interface IDataPointEntitie {
|
|
225
|
+
display_name: string;
|
|
226
|
+
attrs: IDataPointAttr[];
|
|
227
|
+
}
|
|
228
|
+
export interface IDataPointPosition {
|
|
229
|
+
byte_offset: number;
|
|
230
|
+
unit: 'bit' | 'byte';
|
|
231
|
+
len: number;
|
|
232
|
+
bit_offset: number;
|
|
233
|
+
}
|
|
234
|
+
export type TDataType = 'bool' | 'uint8' | 'uint16' | 'uint32' | 'binary' | 'enum' | 'number';
|
|
235
|
+
export interface IUnitSpec {
|
|
236
|
+
addition: number;
|
|
237
|
+
max: number;
|
|
238
|
+
ratio: number;
|
|
239
|
+
min: number;
|
|
240
|
+
}
|
|
241
|
+
export type TDataOptionType = 'status_writable' | 'status_readonly' | 'alert' | 'fault' | 'ALL';
|
|
242
|
+
export interface IDataPointAttr {
|
|
243
|
+
display_name: string;
|
|
244
|
+
uint_spec: IUnitSpec;
|
|
245
|
+
name: string;
|
|
246
|
+
data_type: TDataType;
|
|
247
|
+
position: IDataPointPosition;
|
|
248
|
+
type: TDataOptionType;
|
|
249
|
+
id: number;
|
|
250
|
+
enum: string[];
|
|
251
|
+
desc: string;
|
|
252
|
+
}
|
|
253
|
+
export type GizBleDeviceListotifications = (devices: IDevice[]) => void;
|
|
254
|
+
export type GizBleDeviceDataNotifications = (curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult, hexString: string) => void;
|
|
255
|
+
export type GizBleErrorNotifications = (err: {
|
|
256
|
+
errCode: number;
|
|
257
|
+
errMsg: string;
|
|
258
|
+
}) => void;
|
|
259
|
+
export type TBleDataListener<T> = (_curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult, hexString: string) => T | null | undefined;
|
|
260
|
+
export interface CheckOTAParams {
|
|
261
|
+
device: IDevice;
|
|
262
|
+
type: IOTAType;
|
|
263
|
+
}
|
|
264
|
+
export type OTAEventCode = 'GizOTAEventPretreatment' | 'GizOTAEventDownload' | 'GizOTAEventTransmit' | 'GizOTAEventReboot' | 'GizOTAEventFinish';
|
|
265
|
+
export interface OTAEvent {
|
|
266
|
+
code: OTAEventCode;
|
|
267
|
+
}
|
|
268
|
+
export interface OTAProgressEvent {
|
|
269
|
+
firmwareSize: number;
|
|
270
|
+
packageMaxLen: number;
|
|
271
|
+
currentNumber: number;
|
|
272
|
+
currentProgress: number;
|
|
273
|
+
}
|
|
274
|
+
export type OTAProgressEventCallback = (event: OTAProgressEvent) => void;
|
|
275
|
+
export type OTAEventCallback = (event: OTAEvent) => void;
|
|
276
|
+
export interface StartUpgradeParams extends CheckOTAParams {
|
|
277
|
+
onProgress: OTAProgressEventCallback;
|
|
278
|
+
onEvent: OTAEventCallback;
|
|
279
|
+
productKey: string;
|
|
280
|
+
}
|
|
281
|
+
export interface TBleHandleEvent {
|
|
282
|
+
GizBleDeviceData: GizBleDeviceDataNotifications;
|
|
283
|
+
GizBleDeviceList: GizBleDeviceListotifications;
|
|
284
|
+
GizBleError: GizBleErrorNotifications;
|
|
285
|
+
}
|
|
286
|
+
export interface GizwitsWxBlueToothDevice extends WechatMiniprogram.BlueToothDevice {
|
|
287
|
+
communicationType: 'BLE_BROADCAST' | 'BLE';
|
|
288
|
+
}
|
|
289
|
+
export interface BleHandleParams {
|
|
290
|
+
serviceUUIDSuffix: string;
|
|
291
|
+
characteristicUUIDSuffix: string;
|
|
292
|
+
}
|
|
293
|
+
export interface IStartScanResult {
|
|
294
|
+
scanList: IDevice[];
|
|
295
|
+
err?: ReturnType<typeof wrapErrorInfo>;
|
|
296
|
+
}
|
|
297
|
+
export interface IDeviceReq<T> {
|
|
298
|
+
success: boolean;
|
|
299
|
+
data: T;
|
|
300
|
+
}
|
|
301
|
+
export type OnScanDevice = (scanList: IDevice[]) => void;
|
|
302
|
+
export interface BleConnectDevice {
|
|
303
|
+
deviceId?: string;
|
|
304
|
+
serviceId?: string;
|
|
305
|
+
characteristicId?: string;
|
|
306
|
+
errMsg?: string;
|
|
307
|
+
}
|
|
308
|
+
export interface BleConstructorParams {
|
|
309
|
+
pks: string[];
|
|
310
|
+
bleHandleParams?: BleHandleParams;
|
|
311
|
+
offlineThreshold?: number;
|
|
312
|
+
}
|
|
313
|
+
export interface LanConnectDevice {
|
|
314
|
+
mac: string;
|
|
315
|
+
productKey: string;
|
|
316
|
+
socketHandle: TCPHandler;
|
|
317
|
+
}
|
|
318
|
+
export interface ILanDevice extends IDevice {
|
|
319
|
+
expandData: DiscoverUDP;
|
|
320
|
+
ip: string;
|
|
321
|
+
}
|
|
322
|
+
export type GizLanDeviceListNotifications = (devices: IDevice[]) => void;
|
|
323
|
+
export type GizLanDeviceDataNotifications = (mac: string, data: string) => void;
|
|
324
|
+
export interface TLanHandleEvent {
|
|
325
|
+
GizLanDeviceList: GizLanDeviceListNotifications;
|
|
326
|
+
GizLanDeviceData: GizLanDeviceDataNotifications;
|
|
327
|
+
}
|
|
328
|
+
export interface IBLEService {
|
|
329
|
+
uuid: string;
|
|
330
|
+
isPrimary: boolean;
|
|
331
|
+
}
|
|
332
|
+
export interface IBLECharacteristic {
|
|
333
|
+
uuid: string;
|
|
334
|
+
properties: {
|
|
335
|
+
read: boolean;
|
|
336
|
+
write: boolean;
|
|
337
|
+
notify: boolean;
|
|
338
|
+
indicate: boolean;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
export interface ILoginRes {
|
|
342
|
+
expire_at: number;
|
|
343
|
+
token: string;
|
|
344
|
+
uid: string;
|
|
345
|
+
}
|
|
346
|
+
export interface OTARes {
|
|
347
|
+
download_url: string;
|
|
348
|
+
soft_ver: string;
|
|
349
|
+
}
|
|
350
|
+
export interface configDeviceParams {
|
|
351
|
+
ssid: string;
|
|
352
|
+
password: string;
|
|
353
|
+
softAPSSIDPrefix: string;
|
|
354
|
+
}
|
|
355
|
+
export interface configBLEDeviceParams {
|
|
356
|
+
ssid: string;
|
|
357
|
+
password: string;
|
|
358
|
+
softAPSSIDPrefix?: string;
|
|
359
|
+
timeout: number;
|
|
360
|
+
}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="crypto-js" />
|
|
2
2
|
import { lib } from "crypto-js/core";
|
|
3
|
-
import { IProductInfo } from
|
|
4
|
-
import { GizwitsWxBlueToothDevice } from './handler/ble';
|
|
3
|
+
import { IDevice, IError, IWXDevicesResult, TConnectType, IProductInfo, GizwitsWxBlueToothDevice } from "./types";
|
|
5
4
|
export declare function ab2hex(buffer: ArrayBuffer): any;
|
|
6
5
|
export declare function compareWXSDKVersion(v1: string, v2: string): 0 | 1 | -1;
|
|
7
6
|
export declare const isError: (err: unknown) => err is IError;
|
|
@@ -10,10 +9,6 @@ export declare const wrapErrorInfo: (errorMessage: string) => {
|
|
|
10
9
|
errorMessage: string;
|
|
11
10
|
};
|
|
12
11
|
export declare const unionBy: <T>(array: T[], key: string) => T[];
|
|
13
|
-
interface IWXDevicesResult {
|
|
14
|
-
success: true;
|
|
15
|
-
bleDevices: WechatMiniprogram.BlueToothDevice[];
|
|
16
|
-
}
|
|
17
12
|
export declare function isWXDevicesResult(res: unknown): res is IWXDevicesResult;
|
|
18
13
|
export declare function str2Buf(arr: string): ArrayBuffer;
|
|
19
14
|
export declare const numberArray2Uint8Array: (numArr: number[]) => Uint8Array;
|
package/dist/src/wechatApi.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
discovering: boolean;
|
|
3
|
-
available: boolean;
|
|
4
|
-
}
|
|
5
|
-
export interface IWechatResult {
|
|
6
|
-
errMsg: string;
|
|
7
|
-
errCode: number;
|
|
8
|
-
}
|
|
1
|
+
import { IBluetoothAdapterStateResult, IWechatResult, IBLEService, IBLECharacteristic } from "./types";
|
|
9
2
|
export declare function retryConnect(deviceId: string, timeout?: number): Promise<IWechatResult | {
|
|
10
3
|
success: boolean;
|
|
11
4
|
}>;
|
|
@@ -15,20 +8,7 @@ export declare function getBluetoothAdapterState(): Promise<IBluetoothAdapterSta
|
|
|
15
8
|
export declare function startBluetoothDevicesDiscovery(allowDuplicatesKey?: boolean): Promise<IWechatResult>;
|
|
16
9
|
export declare function getBluetoothDevices(): Promise<WechatMiniprogram.BlueToothDevice[]>;
|
|
17
10
|
export declare function createBLEConnection(deviceId: string, timeout: number): Promise<IWechatResult>;
|
|
18
|
-
interface IBLEService {
|
|
19
|
-
uuid: string;
|
|
20
|
-
isPrimary: boolean;
|
|
21
|
-
}
|
|
22
11
|
export declare function getBLEDeviceServices(deviceId: string): Promise<IBLEService[]>;
|
|
23
|
-
interface IBLECharacteristic {
|
|
24
|
-
uuid: string;
|
|
25
|
-
properties: {
|
|
26
|
-
read: boolean;
|
|
27
|
-
write: boolean;
|
|
28
|
-
notify: boolean;
|
|
29
|
-
indicate: boolean;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
12
|
export declare function getBLEDeviceCharacteristics(deviceId: string, serviceId: string): Promise<IBLECharacteristic[]>;
|
|
33
13
|
export declare function notifyBLECharacteristicValueChange(deviceId: string, serviceId: string, characteristicId: string, state?: boolean): Promise<IWechatResult>;
|
|
34
14
|
export declare function writeBLECharacteristicValue(deviceId: string, serviceId: string, characteristicId: string, value: ArrayBuffer): Promise<IWechatResult>;
|
|
@@ -37,4 +17,3 @@ export declare function downloadFile({ url }: {
|
|
|
37
17
|
url: any;
|
|
38
18
|
}): Promise<unknown>;
|
|
39
19
|
export declare function setMtu(mtu: number, deviceId: string): Promise<unknown>;
|
|
40
|
-
export {};
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult, TimeoutHandle } from "../
|
|
2
|
-
|
|
3
|
-
(result: IResult<unknown>): void;
|
|
4
|
-
}
|
|
5
|
-
export type TConfigEvent = 'GIZ_CONFIG_START' | 'GIZ_DISCOVER_SUCCESS' | 'GIZ_CONNECT_SUCCESS' | 'GIZ_CONFIG_SEND_SUCCESS' | 'GIZ_CONFIG_RECV_SUCCESS' | 'GIZ_CONFIG_SUCCESS';
|
|
6
|
-
export interface ConfigEventData {
|
|
7
|
-
event: TConfigEvent;
|
|
8
|
-
deviceID?: string;
|
|
9
|
-
}
|
|
1
|
+
import { IRandomCodesResult, IRejectCallback, IResult, TimeoutHandle } from "../types";
|
|
2
|
+
import { ConfigEventData, IDevice } from "../types";
|
|
10
3
|
declare class ConfigBase {
|
|
11
4
|
ssid: string;
|
|
12
5
|
bssid: string;
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult } from "../
|
|
1
|
+
import { IDevice, IRandomCodesResult, IResult, configDeviceParams, ISetDeviceOnboardingDeployProps } from "../types";
|
|
2
2
|
import ConfigBase from "./ConfigBase";
|
|
3
|
-
interface configDeviceParams {
|
|
4
|
-
ssid: string;
|
|
5
|
-
password: string;
|
|
6
|
-
softAPSSIDPrefix: string;
|
|
7
|
-
}
|
|
8
|
-
interface ISetDeviceOnboardingDeployProps {
|
|
9
|
-
timeout: number;
|
|
10
|
-
isBind: boolean;
|
|
11
|
-
softAPSSIDPrefix: string;
|
|
12
|
-
}
|
|
13
3
|
declare class ApConfig extends ConfigBase {
|
|
14
4
|
disableSendUDP: boolean;
|
|
15
5
|
private sendMessageInterval;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult } from "../sdk";
|
|
2
1
|
import { BleHandle } from "../handler/ble";
|
|
3
|
-
import ConfigBase
|
|
2
|
+
import ConfigBase from "./ConfigBase";
|
|
3
|
+
import { IDevice, IError, ConfigEventData, IRandomCodesResult, IResult, configBLEDeviceParams } from "../types";
|
|
4
4
|
type EnableAndGetBluetoothDevicesRes = Promise<{
|
|
5
5
|
success: false;
|
|
6
6
|
err: IError;
|
|
@@ -16,12 +16,6 @@ interface IArgs {
|
|
|
16
16
|
bleHandle: BleHandle;
|
|
17
17
|
eventCallBack: (event: ConfigEventData) => void;
|
|
18
18
|
}
|
|
19
|
-
interface configBLEDeviceParams {
|
|
20
|
-
ssid: string;
|
|
21
|
-
password: string;
|
|
22
|
-
softAPSSIDPrefix?: string;
|
|
23
|
-
timeout: number;
|
|
24
|
-
}
|
|
25
19
|
interface ISetDeviceOnboardingDeployProps {
|
|
26
20
|
timeout: number;
|
|
27
21
|
isBind: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult } from "../../sdk";
|
|
2
1
|
import ConfigBase from "../ConfigBase";
|
|
2
|
+
import { IDevice, IResult } from '../../types';
|
|
3
3
|
interface configDeviceParams {
|
|
4
4
|
ssid: string;
|
|
5
5
|
password: string;
|
|
@@ -16,7 +16,7 @@ declare class NFCConfig extends ConfigBase {
|
|
|
16
16
|
address: string;
|
|
17
17
|
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], address: string);
|
|
18
18
|
destroy: () => void;
|
|
19
|
-
configDevice: ({ ssid, password, bssid, address }: configDeviceParams) => Promise<IResult<IRandomCodesResult[]>>;
|
|
19
|
+
configDevice: ({ ssid, password, bssid, address }: configDeviceParams) => Promise<IResult<import("../../types").IRandomCodesResult[]>>;
|
|
20
20
|
setDeviceOnboardingDeploy: ({ timeout, isBind, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
|
|
21
21
|
}
|
|
22
22
|
export default NFCConfig;
|
package/global.d.ts
CHANGED
|
@@ -6,23 +6,7 @@ declare namespace md5 {
|
|
|
6
6
|
|
|
7
7
|
declare function md5(data: any): any;
|
|
8
8
|
|
|
9
|
-
type TUtf8 = {
|
|
10
|
-
toBytes: (data: any) => any
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type TUtils = {
|
|
14
|
-
utf8: TUtf8;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface ecb {
|
|
18
|
-
new(data: any): any;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type TModeOfOperation = {
|
|
22
|
-
ecb: ecb;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
9
|
declare namespace aesjs {
|
|
26
|
-
const utils:
|
|
27
|
-
const ModeOfOperation:
|
|
28
|
-
}
|
|
10
|
+
const utils: any;
|
|
11
|
+
const ModeOfOperation: any;
|
|
12
|
+
}
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mini_program_gizwits_sdk",
|
|
3
|
-
"version": "3.6.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.6.2",
|
|
4
|
+
"description": "更新类型",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s",
|