mini_program_gizwits_sdk 3.6.1 → 3.6.3

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.
Files changed (55) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +3 -3
  3. package/dist/src/GizLog.d.ts +1 -1
  4. package/dist/src/errorCode.d.ts +1 -3
  5. package/dist/src/handler/ble.d.ts +5 -66
  6. package/dist/src/handler/lan.d.ts +3 -18
  7. package/dist/src/handler/socket.d.ts +1 -0
  8. package/dist/src/openApiRequest.d.ts +1 -5
  9. package/dist/src/productConfigFileManage.d.ts +3 -6
  10. package/dist/src/protocol/OTA/CheckCanOTA.d.ts +1 -1
  11. package/dist/src/protocol/{DataPoint.d.ts → dataPoint.d.ts} +0 -34
  12. package/dist/src/randomCode.d.ts +1 -5
  13. package/dist/src/sdk.d.ts +9 -104
  14. package/dist/src/services/devices.d.ts +1 -17
  15. package/dist/src/services/login.d.ts +2 -6
  16. package/dist/src/services/monitor.d.ts +2 -1
  17. package/dist/src/services/ota.d.ts +2 -6
  18. package/dist/src/services/uploadP0.d.ts +2 -1
  19. package/dist/src/types/index.d.ts +360 -0
  20. package/dist/src/utils.d.ts +1 -6
  21. package/dist/src/wechatApi.d.ts +1 -22
  22. package/dist/src/wifiConfig/ConfigBase.d.ts +2 -9
  23. package/dist/src/wifiConfig/ap.d.ts +1 -11
  24. package/dist/src/wifiConfig/ble.d.ts +2 -8
  25. package/dist/src/wifiConfig/nfc/index.d.ts +2 -2
  26. package/global.d.ts +3 -19
  27. package/index.ts +2 -1
  28. package/package.json +2 -2
  29. package/src/errorCode.ts +3 -3
  30. package/src/handler/ble.ts +4 -79
  31. package/src/handler/lan.ts +3 -24
  32. package/src/handler/socket.ts +3 -0
  33. package/src/openApiRequest.ts +2 -14
  34. package/src/productConfigFileManage.ts +3 -5
  35. package/src/protocol/OTA/AwaitNoti.ts +0 -2
  36. package/src/protocol/OTA/CheckCanOTA.ts +1 -2
  37. package/src/protocol/OTA/OTAPackPackage.ts +1 -1
  38. package/src/protocol/OTA/PreOTA.ts +2 -3
  39. package/src/protocol/OTA/ResetPosition.ts +1 -2
  40. package/src/protocol/dataPoint.ts +1 -42
  41. package/src/randomCode.ts +1 -12
  42. package/src/sdk.ts +11 -114
  43. package/src/services/devices.ts +2 -22
  44. package/src/services/login.ts +1 -5
  45. package/src/services/monitor.ts +1 -0
  46. package/src/services/ota.ts +1 -5
  47. package/src/services/uploadP0.ts +1 -0
  48. package/src/types/index.ts +455 -0
  49. package/src/utils.ts +1 -6
  50. package/src/wechatApi.ts +1 -22
  51. package/src/wifiConfig/ConfigBase.ts +2 -10
  52. package/src/wifiConfig/ap.ts +1 -13
  53. package/src/wifiConfig/ble.ts +2 -9
  54. package/src/wifiConfig/nfc/index.ts +1 -4
  55. package/src/global.d.ts +0 -52
@@ -4,35 +4,14 @@ import DiscoverUDP from "../protocol/DiscoverUDP";
4
4
  import Login from "../protocol/Login";
5
5
  import ProtocolBase from "../protocol/ProtocolBase";
6
6
  import { arrayToUint8, hexStrint2byte } from "../protocol/tool";
7
- import { IResult } from "../sdk";
8
7
  import sleep from "../sleep";
8
+ import { IDevice, ILanDevice, IResult, LanConnectDevice, TLanHandleEvent } from "../types";
9
9
  import { ab2hex, ab2numbers } from "../utils";
10
10
  import EventListener from "./EventListener";
11
11
 
12
- // 局域网连接设备结构
13
- interface ConnectDevice {
14
- mac: string
15
- productKey: string
16
- socketHandle: TCPHandler
17
- }
18
-
19
- // 局域网设备
20
- interface ILanDevice extends IDevice {
21
- expandData: DiscoverUDP
22
- ip: string
23
- }
24
-
25
- type GizLanDeviceListNotifications = (devices: IDevice[]) => void;
26
- type GizLanDeviceDataNotifications = (mac: string, data: string) => void;
27
- export interface TLanHandleEvent {
28
- GizLanDeviceList: GizLanDeviceListNotifications;
29
- GizLanDeviceData: GizLanDeviceDataNotifications
30
- }
31
-
32
-
33
12
  export class LanHandle extends EventListener<TLanHandleEvent> {
34
13
  // private characteristicUUIDSuffix: string;
35
- public connectedList: ConnectDevice[] = [];
14
+ public connectedList: LanConnectDevice[] = [];
36
15
  public pks: string[] = [];
37
16
  // private globalListenerMap = {};
38
17
  public scanList: ILanDevice[] = [];
@@ -273,7 +252,7 @@ interface ITCPHandlerProps {
273
252
  onClose: (ip) => void
274
253
  onData: (mac: string, data: string) => void
275
254
  }
276
- class TCPHandler {
255
+ export class TCPHandler {
277
256
  private deviceTCPPort = 12416
278
257
  private ip = ""
279
258
  private productKey = ""
@@ -1,6 +1,9 @@
1
1
  import errorCode from "../errorCode";
2
2
  import GizLog from "../GizLog";
3
3
  import request from "../openApiRequest";
4
+ import { IDevice, IError, IOnDeviceStatusChanged,
5
+ IDeviceStatusChangedProps, IDeviceRawStatusChangedProps,
6
+ IOnSocketStatusChanged, IEmptyFn, ICommonObj } from "../types";
4
7
  import { compareWXSDKVersion, isError } from '../utils';
5
8
 
6
9
  // commType = 'custom' | 'attrs_v4'
@@ -1,19 +1,7 @@
1
1
  import errorCode from './errorCode';
2
2
  import { getGlobalData } from "./globalData";
3
3
  import request from './request';
4
-
5
- interface IResult<T> {
6
- data: T;
7
- errMsg: string;
8
- statusCode: number;
9
- }
10
-
11
- export interface IServiceResult<T> {
12
- success: boolean;
13
- data?: T;
14
- err?: IError;
15
- }
16
-
4
+ import { IError, IServiceResult, IWechatApiResult } from './types';
17
5
 
18
6
  const openApiRequest = async <T>(url: string, options: any, needToken: boolean = true): Promise<IServiceResult<T>> => {
19
7
  const requestOptions = { ...options };
@@ -29,7 +17,7 @@ const openApiRequest = async <T>(url: string, options: any, needToken: boolean =
29
17
  requestOptions.header = { ...headers, ...options.headers };
30
18
  delete requestOptions.headers;
31
19
  const openApiUrl = getGlobalData('cloudServiceInfo').openAPIInfo;
32
- const res = await request<IResult<T>>('https://' + openApiUrl + url, requestOptions);
20
+ const res = await request<IWechatApiResult<T>>('https://' + openApiUrl + url, requestOptions);
33
21
  // 统一封装OPEN API的错误码
34
22
  if (res.statusCode >= 200 && res.statusCode < 300) {
35
23
  return {
@@ -1,12 +1,10 @@
1
1
  import openApiRequest from './openApiRequest';
2
- import { IDataPointConfig } from './protocol/DataPoint';
2
+ import { IProductConfigData, IDataPointConfig } from './types';
3
3
  // 管理配置文件
4
4
 
5
- interface IData {
6
- [key: string]: IDataPointConfig;
7
- }
5
+
8
6
  class ProductConfigFileManage {
9
- data: IData = {};
7
+ data: IProductConfigData = {};
10
8
  key = 'dataPointConfig';
11
9
 
12
10
  init = async () => {
@@ -1,6 +1,4 @@
1
- import { IOTAType } from "../../sdk";
2
1
  import ProtocolBase from "../ProtocolBase";
3
- import { arrayToString, fillString, hexStrint2byte } from "../tool";
4
2
 
5
3
  class AwaitNoti extends ProtocolBase {
6
4
  state = 0; // 0继续 1失败
@@ -1,6 +1,5 @@
1
- import { IOTAType } from "../../sdk";
1
+ import { IOTAType } from "../../types";
2
2
  import ProtocolBase from "../ProtocolBase";
3
- import { arrayToString } from "../tool";
4
3
 
5
4
  class CheckCanOTA extends ProtocolBase {
6
5
  type: IOTAType = 'MCU';
@@ -1,5 +1,5 @@
1
1
  import { crc16modbus } from '../../crc'
2
- import { getVariableLength } from "../DataPoint";
2
+ import { getVariableLength } from "../dataPoint";
3
3
  import ProtocolBase from "../ProtocolBase";
4
4
  import { bytesToInt, fillString, hexStrint2byte } from "../tool";
5
5
 
@@ -1,7 +1,6 @@
1
- import { IOTAType } from "../../sdk";
2
- import { getVariableLength } from "../DataPoint";
1
+ import { getVariableLength } from "../dataPoint";
3
2
  import ProtocolBase from "../ProtocolBase";
4
- import { arrayToString, bytesToHexString, bytesToInt, fillString, hexStrint2byte, string2Bytes } from "../tool";
3
+ import { bytesToHexString, bytesToInt, fillString, hexStrint2byte, string2Bytes } from "../tool";
5
4
 
6
5
  type TState = 0 | 1 | 2 | 3 // 0x00 正常升级 0x01 pk不一致 0x02 版本低于当前 0x03 大小超过范围
7
6
  class PreOTA extends ProtocolBase {
@@ -1,6 +1,5 @@
1
- import { IOTAType } from "../../sdk";
2
1
  import ProtocolBase from "../ProtocolBase";
3
- import { arrayToString, fillString, hexStrint2byte } from "../tool";
2
+ import { fillString, hexStrint2byte } from "../tool";
4
3
 
5
4
  class ResetPosition extends ProtocolBase {
6
5
  constructor(data: number[]) {
@@ -1,48 +1,7 @@
1
1
  import productConfigFileManage from "../productConfigFileManage";
2
+ import { IDataPointAttr, TDataOptionType, TDataType } from "../types";
2
3
  import { arrayToString, checkHeader, fillString, getProtocolLen, hexStrint2byte, completeBlock} from "./tool";
3
4
 
4
- export interface IDataPointConfig {
5
- name: string;
6
- protocolType: 'var_len' | 'standard';
7
- entities: IDataPointEntitie[];
8
- }
9
-
10
-
11
-
12
- interface IDataPointEntitie {
13
- display_name: string;
14
- attrs: IDataPointAttr[];
15
- }
16
-
17
- interface IDataPointPosition {
18
- byte_offset: number;
19
- unit: 'bit' | 'byte';
20
- len: number;
21
- bit_offset: number;
22
- }
23
-
24
- type TDataType = 'bool' | 'uint8' | 'uint16' | 'uint32' | 'binary' | 'enum' | 'number';
25
-
26
-
27
- interface IUnitSpec {
28
- addition: number;
29
- max: number;
30
- ratio: number;
31
- min: number;
32
- }
33
-
34
- type TDataOptionType = 'status_writable' | 'status_readonly' | 'alert' | 'fault' | 'ALL';
35
- export interface IDataPointAttr {
36
- display_name: string;
37
- uint_spec: IUnitSpec;
38
- name:string;
39
- data_type: TDataType;
40
- position: IDataPointPosition;
41
- type: TDataOptionType;
42
- id: number;
43
- enum: string[];
44
- desc: string;
45
- }
46
5
 
47
6
  const fixType = (type: TDataType) => {
48
7
  return type.indexOf('uint') !== -1 ? 'number' : type;
package/src/randomCode.ts CHANGED
@@ -1,16 +1,5 @@
1
1
  import {MD5, AES, enc, pad, mode} from 'crypto-js';
2
-
3
- interface IGetRandomCodes {
4
- SSID: string;
5
- password: string;
6
- pks: string[];
7
- }
8
-
9
- interface IGetRandomCode {
10
- SSID: string;
11
- password: string;
12
- pk: string;
13
- }
2
+ import { IGetRandomCode, IGetRandomCodes } from './types';
14
3
 
15
4
  const getRandomCodes = ({ SSID, password, pks }: IGetRandomCodes): string[] => {
16
5
  const randomCodes: string[] = [];
package/src/sdk.ts CHANGED
@@ -3,12 +3,12 @@ import { getGlobalData, setGlobalData } from './globalData';
3
3
  import sdkConfig from '../package.json';
4
4
  import { LanHandle } from './handler/lan';
5
5
  import productConfigFileManage from './productConfigFileManage';
6
- import { formatEnum, IDataPointConfig, pack, unpack } from './protocol/DataPoint';
6
+ import { formatEnum, pack, unpack } from './protocol/dataPoint';
7
7
  import Ntp from './protocol/Ntp';
8
8
  import { CancelSync, DeletePackage, RequestSync, SyncPackage } from './protocol/OffLineData';
9
9
  import ProtocolBase from './protocol/ProtocolBase';
10
10
  import { arrayToString, hexStrint2byte } from './protocol/tool';
11
- import { BleHandle, OTAEventCallback, OTAProgressEventCallback } from './handler/ble';
11
+ import { BleHandle } from './handler/ble';
12
12
  import GizwitsWS from './handler/socket';
13
13
  import Reset from './protocol/Reset';
14
14
  import SetReset from './protocol/SetReset';
@@ -20,13 +20,12 @@ import {
20
20
  bindMac,
21
21
  editBindInfo,
22
22
  getBindingList,
23
- IOpenApiDevice,
24
23
  ISafeRegisterReturn,
25
24
  IUnbindReturn,
26
25
  safeRegister,
27
26
  unbindDevice
28
27
  } from './services/devices';
29
- import { AnonymousLogin, ILoginRes } from './services/login';
28
+ import { AnonymousLogin } from './services/login';
30
29
  import { uploadP0 } from './services/uploadP0';
31
30
  import sleep from './sleep';
32
31
  import {
@@ -41,118 +40,16 @@ import {
41
40
  import ApConfig from './wifiConfig/ap';
42
41
  import BLEConfig from './wifiConfig/ble';
43
42
  import NFCConfig from './wifiConfig/nfc';
44
- import { ConfigEventData } from './wifiConfig/ConfigBase';
43
+ import { IDevice, TConnectType, IOnDeviceStatusChanged,
44
+ IOpenApiDevice,
45
+ IDeviceStatusChangedProps, IOnSocketStatusChanged,
46
+ IProductInfo, GizwitsSdkOption, SyncCallBack, ISDKResult,
47
+ IResult, IOTAType, IBindRemoteDeviceParams, ICloudServiceInfo,
48
+ TListenerType, IDeviceSafetyParams, ISetDeviceOnboardingDeployProps,
49
+ IDataPointConfig, OTAEventCallback, OTAProgressEventCallback, ILoginRes,
50
+ IDeviceSafetyRegisterParams } from './types';
45
51
 
46
52
  const version = sdkConfig.version;
47
- interface SyncCallBackParams {
48
- event: TSyncEvnet;
49
- currentNum?: number;
50
- totalNum?: number;
51
- message?: string;
52
- }
53
- type TSyncEvnet = 'SYNC_START' | 'SYNC_END' | 'SYNC_FAIL' | 'SYNC_CANCEL' | 'SYNC_PROGRESS';
54
- export type SyncCallBack = (data: SyncCallBackParams) => void
55
- export type IOTAType = 'MCU' | 'MODULE'
56
-
57
- // 接口返回格式
58
- export interface ISDKResult<T> {
59
- data?: T;
60
- err?: IError;
61
- message?: string;
62
- success: boolean;
63
- }
64
- export interface ISetCommonDeviceOnboardingDeployProps {
65
- ssid: string;
66
- bssid?: string;
67
- password: string;
68
- timeout: number;
69
- isBind?: boolean;
70
- mode?: 0 | 3 | 5; // 0 AP 3 BLE 5 NFC
71
- softAPSSIDPrefix?: string;
72
- }
73
-
74
- export interface ISetDeviceOnboardingDeployProps
75
- extends ISetCommonDeviceOnboardingDeployProps {
76
- softAPSSIDPrefix: string;
77
- eventCallBack: (event: ConfigEventData) => void, // 配网回调
78
- }
79
-
80
- export interface IRandomCodesResult {
81
- random_code: string;
82
- product_key: string;
83
- mac: string;
84
- did: string;
85
- user_id: string;
86
- timestamp: number;
87
- type: string;
88
- wifi_soft_ver: string;
89
- lan_proto_ver: string;
90
- }
91
-
92
- interface IBindRemoteDeviceParams {
93
- productKey: string;
94
- mac: string;
95
- beOwner?: boolean;
96
- alias?: string;
97
- }
98
-
99
- interface IDeviceStatusNoti {
100
- device: IDevice;
101
- connectType: TConnectType;
102
- }
103
- interface IDeviceAttrsNoti {
104
- device: IDevice;
105
- data: object;
106
- }
107
-
108
- export interface TListenerType {
109
- GizDeviceListNotifications: TDeviceListNotifications;
110
- GizDeviceStatusNotifications: TDeviceStatusNotifications;
111
- GizDeviceAttrsNotifications: TDeviceAttrsNotifications;
112
- onScanListChange: OnScanListChange;
113
- onBleHandleError: OnBleHandleError;
114
- }
115
-
116
- type TDeviceListNotifications = (devices: IDevice[]) => void;
117
- type TDeviceStatusNotifications = (data: IDeviceStatusNoti) => void;
118
- type TDeviceAttrsNotifications = (data: IDeviceAttrsNoti) => void;
119
- type OnScanListChange = (devices: IDevice[]) => void;
120
- type OnBleHandleError = (error: IError) => void;
121
-
122
- interface IDeviceSafetyRegisterParams {
123
- mac: string;
124
- productKey: string;
125
- }
126
-
127
- interface IDeviceSafetyParams extends IDeviceSafetyRegisterParams {
128
- isReset: boolean;
129
- }
130
- export interface IResult<T> {
131
- success: boolean;
132
- data?: T;
133
- err?: IError;
134
- }
135
-
136
- interface ICloudServiceInfo {
137
- openAPIInfo: string;
138
- }
139
-
140
- export type TimeoutHandle = ReturnType<typeof setTimeout> | null;
141
- export type IntervalHandle = ReturnType<typeof setInterval> | null;
142
- export interface IProductInfo {
143
- productKey: string;
144
- productSecret: string;
145
- }
146
- interface GizwitsSdkOption {
147
- appID: string;
148
- appSecret: string;
149
- productInfo: IProductInfo[];
150
- cloudServiceInfo?: ICloudServiceInfo;
151
- token?: string;
152
- uid?: string;
153
- offlineThreshold?: number;
154
- }
155
-
156
53
  class GizwitsMiniSDK {
157
54
  private listenerMap: any = {};
158
55
  private keepScanTimer: any = null;
@@ -1,31 +1,11 @@
1
1
  import { enc, AES, mode, pad } from 'crypto-js';
2
- import openApiRequest, { IServiceResult } from '../openApiRequest';
2
+ import openApiRequest from '../openApiRequest';
3
3
  import getRandomCodes from '../randomCode';
4
- import { IRandomCodesResult } from '../sdk';
5
4
  import { psKeySign } from './tool';
5
+ import { IDevice, IDeviceRes, IOpenApiDevice, IRandomCodesResult, IServiceResult } from '../types';
6
6
  // eslint-disable-next-line import/no-commonjs
7
7
  // const CryptoJS = require('crypto-js');
8
8
 
9
- export interface IOpenApiDevice {
10
- product_key: string;
11
- did: string;
12
- mac: string;
13
- passcode: string;
14
- is_online: boolean;
15
- host: string;
16
- port: string;
17
- port_s: string;
18
- ws_port: number;
19
- wss_port: number;
20
- dev_alias: string;
21
- remark: string;
22
- type: 'normal' | 'center_control' | 'sub_dev';
23
- }
24
-
25
- interface IDeviceRes {
26
- devices: IOpenApiDevice[];
27
- }
28
-
29
9
  // 云端aes 特殊解码
30
10
  class Padding {
31
11
  /**
@@ -1,10 +1,6 @@
1
1
  import openApiRequest from "../openApiRequest";
2
+ import { ILoginRes } from "../types";
2
3
 
3
- export interface ILoginRes {
4
- expire_at: number;
5
- token: string;
6
- uid: string;
7
- }
8
4
  export async function AnonymousLogin ({uid}: {uid: string}) {
9
5
  return openApiRequest<ILoginRes>('/app/users', {
10
6
  data: {
@@ -1,6 +1,7 @@
1
1
  import { version } from '../../package.json';
2
2
  import { getGlobalData } from "../globalData";
3
3
  import openApiRequest from '../openApiRequest';
4
+ import { IDevice } from '../types';
4
5
 
5
6
  interface MobileInfo {
6
7
  brand: string;
@@ -1,10 +1,6 @@
1
1
  import openApiRequest from "../openApiRequest";
2
- import { IOTAType } from "../sdk";
2
+ import { IOTAType, OTARes } from "../types";
3
3
 
4
- export interface OTARes {
5
- download_url: string;
6
- soft_ver: string; // 新的版本号
7
- }
8
4
 
9
5
  //type 指定固件类型,1代表WiFi模组,2代表MCU
10
6
  export async function checkUpdate ({did, type, hardVersion, softVersion}: {did: string, type: IOTAType, hardVersion: string, softVersion: string}) {
@@ -1,5 +1,6 @@
1
1
  import openApiRequest from "../openApiRequest";
2
2
  import { enc, AES, mode, pad } from 'crypto-js';
3
+ import { IDevice } from "../types";
3
4
 
4
5
  export interface IUploadRes {
5
6
  }