mini_program_gizwits_sdk 3.7.0-kuka → 3.7.0

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 (63) hide show
  1. package/README.md +96 -25
  2. package/{index.ts → dist/index.d.ts} +3 -3
  3. package/dist/index.js +5 -5
  4. package/global.d.ts +3 -19
  5. package/package.json +5 -5
  6. package/yarn-error.log +34 -34
  7. package/src/GizLog.ts +0 -51
  8. package/src/aepApi/aepApiRequest.ts +0 -61
  9. package/src/crc/calculators/crc16modbus.ts +0 -36
  10. package/src/crc/calculators/crc32.ts +0 -47
  11. package/src/crc/crc16modbus.ts +0 -3
  12. package/src/crc/crc32.ts +0 -4
  13. package/src/crc/create_buffer.ts +0 -7
  14. package/src/crc/define_crc.ts +0 -9
  15. package/src/crc/index.ts +0 -10
  16. package/src/crc/package.json +0 -3
  17. package/src/crc/types.ts +0 -10
  18. package/src/errorCode.ts +0 -84
  19. package/src/global.d.ts +0 -53
  20. package/src/globalData.ts +0 -9
  21. package/src/handler/EventListener.ts +0 -44
  22. package/src/handler/ble.ts +0 -1485
  23. package/src/handler/lan.ts +0 -409
  24. package/src/handler/socket.ts +0 -625
  25. package/src/openApiRequest.ts +0 -62
  26. package/src/productConfigFileManage.ts +0 -58
  27. package/src/protocol/Bind.ts +0 -22
  28. package/src/protocol/DeviceInfo.ts +0 -36
  29. package/src/protocol/DiscoverUDP.ts +0 -80
  30. package/src/protocol/GetDeviceStatus.ts +0 -63
  31. package/src/protocol/Login.ts +0 -43
  32. package/src/protocol/Ntp.ts +0 -13
  33. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  34. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  35. package/src/protocol/OTA/OTAPackPackage.ts +0 -36
  36. package/src/protocol/OTA/OtaComplete.ts +0 -17
  37. package/src/protocol/OTA/PreOTA.ts +0 -47
  38. package/src/protocol/OTA/ResetPosition.ts +0 -14
  39. package/src/protocol/OffLineData.ts +0 -81
  40. package/src/protocol/ProtocolBase.ts +0 -54
  41. package/src/protocol/Reset.ts +0 -15
  42. package/src/protocol/SetReset.ts +0 -11
  43. package/src/protocol/WifiConfig.ts +0 -42
  44. package/src/protocol/dataPoint.ts +0 -769
  45. package/src/protocol/thirdProtocol/YunZhiMianBleProtocolBase.ts +0 -39
  46. package/src/protocol/tool.ts +0 -147
  47. package/src/randomCode.ts +0 -36
  48. package/src/request.ts +0 -22
  49. package/src/sdk.ts +0 -1472
  50. package/src/sentry.ts +0 -55
  51. package/src/services/devices.ts +0 -309
  52. package/src/services/login.ts +0 -15
  53. package/src/services/ota.ts +0 -30
  54. package/src/services/tool.ts +0 -10
  55. package/src/services/uploadP0.ts +0 -56
  56. package/src/sleep.ts +0 -2
  57. package/src/types/index.ts +0 -48
  58. package/src/utils.ts +0 -419
  59. package/src/wechatApi.ts +0 -210
  60. package/src/wifiConfig/ConfigBase.ts +0 -185
  61. package/src/wifiConfig/ap.ts +0 -192
  62. package/src/wifiConfig/ble.ts +0 -436
  63. package/src/wifiConfig/ble_ailCloud.ts +0 -554
package/src/sentry.ts DELETED
@@ -1,55 +0,0 @@
1
- import { MD5 } from "crypto-js";
2
- import request from "./request";
3
-
4
- export default (err) => {
5
- const platformInfo = wx.getSystemInfoSync();
6
- const baseData = {
7
- "exception": {
8
- "values": [{
9
- "type": "Error",
10
- "value": err.stack,
11
- "stacktrace": {
12
- },
13
- "mechanism": {
14
- "type": "generic",
15
- "handled": true
16
- }
17
- }]
18
- },
19
- "level": "error",
20
- "event_id": MD5(`${new Date().getTime()}`).toString(),
21
- "platform": "javascript",
22
- "sdk": {
23
- },
24
- "timestamp": new Date().getTime() / 1000,
25
- "environment": "production",
26
- "contexts": {
27
- "device": {
28
- },
29
- "os": {
30
- "name": platformInfo.platform,
31
- "version": platformInfo.version
32
- },
33
- "extra": {}
34
- },
35
- "extra": {
36
- "message": err.message
37
- }
38
- }
39
- var options = {
40
- 'method': 'POST',
41
- 'headers': {
42
- 'Connection': 'keep-alive',
43
- 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/',
44
- 'content-type': 'application/json',
45
- 'Accept': '*/*',
46
- 'Sec-Fetch-Site': 'cross-site',
47
- 'Sec-Fetch-Mode': 'cors',
48
- 'Sec-Fetch-Dest': 'empty',
49
- 'Referer': 'https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html',
50
- 'Cookie': '__org='
51
- },
52
- data: JSON.stringify(baseData)
53
- };
54
- request('https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7', options)
55
- }
@@ -1,309 +0,0 @@
1
- import openApiRequest, { IServiceResult } from '../openApiRequest';
2
- import getRandomCodes from '../randomCode';
3
- import { IRandomCodesResult } from '../sdk';
4
- import { psKeySign } from './tool';
5
- // eslint-disable-next-line import/no-commonjs
6
- // const CryptoJS = require('crypto-js');
7
- import { enc, AES, mode, pad } from 'crypto-js';
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
- // 云端aes 特殊解码
26
- class Padding {
27
- /**
28
- * Pads data using the algorithm defined in PKCS #5/7.
29
- *
30
- * @param data The data to pad.
31
- * @param blockSize The multiple that the data should be padded to.
32
- *
33
- * @example
34
- *
35
- * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
36
- */
37
- pad = (data, blockSize) => {};
38
-
39
- /**
40
- * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
41
- *
42
- * @param data The data to unpad.
43
- *
44
- * @example
45
- *
46
- * CryptoJS.pad.Pkcs7.unpad(wordArray);
47
- */
48
- unpad = data => {
49
- const AES_BLOCK_LEN = 16;
50
- const len = data.sigBytes;
51
- let readed = 0;
52
- let repeat = 1;
53
- const stringData = data.toString(enc.Utf8);
54
- while (readed + AES_BLOCK_LEN <= len) {
55
- readed += AES_BLOCK_LEN;
56
- }
57
- for (let i = 0; i < (AES_BLOCK_LEN - 2) / 2; i++) {
58
- const start = readed - i * 2;
59
- if (stringData.substring(start, start - 2) == stringData.substring(start - 2, start - 4)) {
60
- repeat++;
61
- } else {
62
- readed -= repeat * 2;
63
-
64
- break;
65
- }
66
- }
67
- data.sigBytes = readed;
68
- };
69
- }
70
-
71
- interface IDeviceRes {
72
- devices: IOpenApiDevice[];
73
- }
74
-
75
- export const getBindingList = async (): Promise<IServiceResult<IDevice[]>> => {
76
- const data = await openApiRequest<IDeviceRes>('/app/bindings?show_disabled=0&limit=1000&skip=0', {
77
- method: 'GET',
78
- });
79
-
80
- if (data.success) {
81
- const newDevices: IDevice[] = data.data!.devices.map(item => {
82
- return {
83
- productKey: item.product_key,
84
- mac: item.mac,
85
- did: item.did,
86
- host: item.host,
87
- port_s: item.port_s,
88
- port: item.port,
89
- ws_port: item.ws_port,
90
- wss_port: item.wss_port,
91
- passcode: item.passcode,
92
- isBleOnline: false,
93
- isLanOnline: false,
94
- connectType: 'NONE',
95
- name: item.dev_alias,
96
- isBind: true,
97
- isOnline: item.is_online,
98
- };
99
- });
100
- return {
101
- success: true,
102
- data: newDevices,
103
- };
104
- }
105
- return {
106
- success: false,
107
- err: data.err,
108
- };
109
- };
110
-
111
- export interface IBindMacParams {
112
- mac: string;
113
- productKey: string;
114
- productSecret: string;
115
- alias?: string;
116
- beOwner?: boolean;
117
- }
118
- export async function bindMac({
119
- mac,
120
- productKey,
121
- productSecret,
122
- alias,
123
- beOwner,
124
- }: IBindMacParams): Promise<IServiceResult<IOpenApiDevice>> {
125
- const dataJson = {
126
- mac,
127
- product_key: productKey,
128
- dev_alias: alias,
129
- set_owner: beOwner,
130
- };
131
-
132
- const { Signature, timestamp } = psKeySign(productSecret);
133
-
134
- const data = await openApiRequest<IOpenApiDevice>('/app/bind_mac', {
135
- method: 'POST',
136
- data: dataJson,
137
- headers: {
138
- 'X-Gizwits-Signature': Signature,
139
- 'X-Gizwits-Timestamp': timestamp,
140
- },
141
- });
142
- return data;
143
- }
144
-
145
- export interface IUnbindReturn {
146
- failed: string[];
147
- success: string[];
148
- }
149
- export async function unbindDevice({ devices }: { devices: IDevice[] }): Promise<IServiceResult<IUnbindReturn>> {
150
- const data = await openApiRequest<IUnbindReturn>('/app/bindings', {
151
- method: 'DELETE',
152
- data: {
153
- devices: devices.map(device => {
154
- return { did: device.did };
155
- }),
156
- },
157
- });
158
- return data;
159
- }
160
-
161
- interface ICheckDeviceRegisterParams {
162
- SSID: string;
163
- password: string;
164
- productKeys: string[];
165
- }
166
- export async function checkDeviceRegister({
167
- SSID,
168
- password,
169
- productKeys,
170
- }: ICheckDeviceRegisterParams): Promise<IServiceResult<IRandomCodesResult[]>> {
171
- const codes = getRandomCodes({
172
- SSID,
173
- password,
174
- pks: productKeys,
175
- });
176
- let codeStr = '';
177
- codes.map(item => {
178
- codeStr += `${item},`;
179
- });
180
- codeStr = codeStr.substring(0, codeStr.length - 1);
181
- const data = await openApiRequest<IRandomCodesResult[]>(`/app/device_register?random_codes=${codeStr}`, {
182
- method: 'get',
183
- });
184
- return data;
185
- }
186
-
187
- interface ISafeRegisterParams {
188
- productKey: string;
189
- productSecret: string;
190
- mac: string;
191
- passcode: string;
192
- gwDid?: string;
193
- isReset: boolean;
194
- }
195
-
196
- export interface ISafeRegisterReturn {
197
- successDevices: IDevice[];
198
- failedDevices: IDevice[];
199
- }
200
- export async function safeRegister({
201
- productKey,
202
- productSecret,
203
- mac,
204
- passcode,
205
- gwDid,
206
- isReset,
207
- }: ISafeRegisterParams): Promise<IServiceResult<ISafeRegisterReturn>> {
208
- let dataStr = `is_reset=${isReset ? 1 : 0}&mac=${mac}&passcode=${passcode}`;
209
- if (gwDid) {
210
- dataStr += `&gw_did=${gwDid}`;
211
- }
212
-
213
- const key = enc.Hex.parse(productSecret);
214
- const iv = enc.Hex.parse('');
215
- const srcs = enc.Utf8.parse(dataStr);
216
- const encrypted = AES.encrypt(srcs, key, {
217
- iv: iv,
218
- mode: mode.ECB,
219
- padding: pad.Pkcs7,
220
- });
221
- const hexStr = encrypted.ciphertext.toString().toUpperCase();
222
- const data = await openApiRequest<string>(
223
- `/dev/${productKey}/device`,
224
- {
225
- method: 'POST',
226
- data: {
227
- data: hexStr,
228
- },
229
- headers: {
230
- 'content-type': 'application/x-www-form-urlencoded',
231
- },
232
- },
233
- false
234
- );
235
- if (data.success) {
236
- const successDevices = unPackSafeRegisterRes({ productSecret, iv, data: data.data });
237
- const failedDevices = [];
238
- const targetDevice = successDevices.find(item => item.mac === mac);
239
- if (!targetDevice) {
240
- // 不存在
241
- failedDevices.push({
242
- mac,
243
- });
244
- }
245
-
246
- // TODO 解码
247
- return {
248
- success: true,
249
- data: {
250
- successDevices,
251
- failedDevices,
252
- },
253
- };
254
- }
255
- return {
256
- success: false,
257
- err: data.err,
258
- };
259
- }
260
-
261
- const unPackSafeRegisterRes = ({ productSecret, data, iv }: { productSecret: string; data: string; iv: any }) => {
262
- const aesKey = enc.Hex.parse(productSecret);
263
- const bodyHex = enc.Hex.parse(data);
264
- let resEncrypted = AES.decrypt(enc.Base64.stringify(bodyHex), aesKey, {
265
- iv: iv,
266
- mode: mode.ECB,
267
- padding: new Padding(),
268
- });
269
- const resString = resEncrypted.toString(enc.Utf8);
270
- const newData = [];
271
- resString.split(',').map(item => {
272
- const tmp = item.split('&');
273
- const mac = tmp[0].replace('mac=', '');
274
- const did = tmp[1].replace('did=', '');
275
- newData.push({
276
- mac,
277
- did,
278
- });
279
- });
280
- return newData;
281
- };
282
-
283
- interface IRenameProps {
284
- name?: string;
285
- did: string;
286
- remark?: string;
287
- }
288
- export interface IRenamePropsReturn {
289
- remark: string;
290
- dev_alias: string;
291
- }
292
- export async function editBindInfo({ name, remark, did }: IRenameProps): Promise<IServiceResult<IRenamePropsReturn>> {
293
- const body: any = {};
294
- if (name) {
295
- body.dev_alias = name;
296
- }
297
- if (remark) {
298
- body.remark = remark;
299
- }
300
- const data = await openApiRequest<IRenamePropsReturn>(
301
- `/app/bindings/${did}`,
302
- {
303
- method: 'PUT',
304
- data: body,
305
- },
306
- true
307
- );
308
- return data;
309
- }
@@ -1,15 +0,0 @@
1
- import openApiRequest from "../openApiRequest";
2
-
3
- export interface ILoginRes {
4
- expire_at: number;
5
- token: string;
6
- uid: string;
7
- }
8
- export async function AnonymousLogin ({uid}: {uid: string}) {
9
- return openApiRequest<ILoginRes>('/app/users', {
10
- data: {
11
- phone_id: uid,
12
- },
13
- method: 'POST',
14
- }, false)
15
- }
@@ -1,30 +0,0 @@
1
- import openApiRequest from '../openApiRequest';
2
- import { IOTAType, OTARes } from '../types';
3
-
4
- //type 指定固件类型,1代表WiFi模组,2代表MCU
5
- export async function checkUpdate({
6
- did,
7
- type,
8
- hardVersion,
9
- softVersion,
10
- }: {
11
- did: string;
12
- type: IOTAType;
13
- hardVersion: string;
14
- softVersion: string;
15
- }) {
16
- const realType = type == 'MCU' ? '2' : '1';
17
- return openApiRequest<OTARes>(
18
- `/app/ota/v4.1/update_and_check/${did}`,
19
- {
20
- data: {
21
- type: realType,
22
- hard_version: hardVersion,
23
- soft_version: softVersion,
24
- https: '1',
25
- },
26
- method: 'POST',
27
- },
28
- true
29
- );
30
- }
@@ -1,10 +0,0 @@
1
- // eslint-disable-next-line import/no-commonjs
2
- import { MD5 } from "crypto-js";
3
-
4
- export const psKeySign = (productSecret: string) => {
5
- const timestamp = Math.round(new Date().getTime()/1000);
6
-
7
- const str = productSecret + timestamp;
8
- const Signature = MD5(str).toString();
9
- return {Signature, timestamp};
10
- }
@@ -1,56 +0,0 @@
1
- import openApiRequest from "../openApiRequest";
2
- import { enc, AES, mode, pad } from 'crypto-js';
3
-
4
- export interface IUploadRes {
5
- }
6
-
7
- interface IData {
8
- raw: string;
9
- created_at: number;
10
- }
11
-
12
- interface IProps {
13
- device: IDevice;
14
- data: IData[];
15
- productSecret: string;
16
- }
17
- export async function uploadP0 ({device, data, productSecret}: IProps) {
18
- const path = `/v2/products/${device.productKey}/devices/offline-data`;
19
-
20
- let passCode = device.passcode
21
-
22
- const key = enc.Hex.parse(productSecret);
23
- const iv = enc.Hex.parse('');
24
- const srcs = enc.Utf8.parse(passCode);
25
- const encrypted = AES.encrypt(srcs, key, { iv: iv, mode: mode.ECB, padding: pad.Pkcs7 });
26
- passCode = encrypted.ciphertext.toString().toUpperCase();
27
-
28
- return openApiRequest<IUploadRes>(path, {
29
- data: {
30
- data,
31
- encoding: 'hex',
32
- },
33
- method: 'POST',
34
- headers: {
35
- 'X-Gizwits-Device-Id': device.did,
36
- 'X-Gizwits-Device-passcode': passCode,
37
- },
38
- }, false)
39
- }
40
-
41
- // setTimeout(() => {
42
- // uploadP0({
43
- // device: {
44
- // productKey: "8da73e49a9c74d6e9321b4383b44e4e9",
45
- // did: "SlJJzMGa0MDOmhUTt0PIul",
46
- // passcode: "1234567890",
47
- // },
48
- // data: [
49
- // {
50
- // raw: "00000003",
51
- // created_at: parseInt(`${Date.now() / 1000}`, 10)
52
- // }
53
- // ],
54
- // productSecret: "bf5df28e904b455f85fa5be1805945ad"
55
- // })
56
- // }, 3000)
package/src/sleep.ts DELETED
@@ -1,2 +0,0 @@
1
- const sleep = (time: number) => new Promise<void>(resolve => setTimeout(() => resolve(), time));
2
- export default sleep;
@@ -1,48 +0,0 @@
1
- export type IOTAType = 'MCU' | 'MODULE';
2
-
3
- export interface IResult<T> {
4
- success: boolean;
5
- data?: T;
6
- err?: IError;
7
- }
8
-
9
- export type TBleDataListener<T> = (
10
- _curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult,
11
- hexString: string
12
- ) => T | null | undefined;
13
-
14
- export interface CheckOTAParams {
15
- device: IDevice;
16
- type: IOTAType;
17
- }
18
-
19
- export interface OTARes {
20
- download_url: string;
21
- soft_ver: string; // 新的版本号
22
- }
23
-
24
- export interface OTAProgressEvent {
25
- firmwareSize: number;
26
- packageMaxLen: number;
27
- currentNumber: number;
28
- currentProgress: number; // 0 ~ 100
29
- }
30
-
31
- export type OTAEventCode =
32
- | 'GizOTAEventPretreatment'
33
- | 'GizOTAEventDownload'
34
- | 'GizOTAEventTransmit'
35
- | 'GizOTAEventReboot'
36
- | 'GizOTAEventFinish';
37
- export interface OTAEvent {
38
- code: OTAEventCode;
39
- }
40
-
41
- export type OTAProgressEventCallback = (event: OTAProgressEvent) => void;
42
- export type OTAEventCallback = (event: OTAEvent) => void;
43
-
44
- export interface StartUpgradeParams extends CheckOTAParams {
45
- onProgress: OTAProgressEventCallback;
46
- onEvent: OTAEventCallback;
47
- productKey: string;
48
- }