-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifiDevice.ts
98 lines (94 loc) · 3.02 KB
/
wifiDevice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { TuyaSdkBridge } from './common';
/**
* Register wifi device by EZ Mode <br/>
* In case success registration, Thing name is made by combination(building/dong/ho/user (zGuard meta info.)
*
* @param ssid - The name of the Wi-Fi network to which a paired device is connected
* @param password - The password of the Wi-Fi network to which a paired device is connected
* @param timeout - maximum timeout for wifi devices registration, unit is seconds
*
* @returns Success and failure details as a result
* - in case OK: [ref](https://github.com/iot-device-sdk/blob/main/packages/iot-device-sdk/sample-gw.md)
* - in case Processing: registerWifiEzDevice is started
* - in case Occur Timeout: Timeout
* @example
* ```ts
* iot-device-sdk.registerWifiEzDevice(
* "ssid",
* "password",
* 90
* ).then(
* (okRes: any) => {
* debugText("Ok Res")
* assignedGwId = okRes.devId
* console.log(assignedGwId)
* console.log(okRes)
* },
* (errRes) => {
* debugText("Ng Res")
* console.log(errRes)
* }
* )
* ```
*/
export async function registerWifiEzDevice(ssid: string, password: string, timeout: number): Promise<any> {
return TuyaSdkBridge.registerWifiEzDevice(ssid, password, timeout);
}
/**
* Register wifi device by AP Mode <br/>
* In case success registration, Thing name is made by combination(building/dong/ho/user (zGuard meta info.)
*
* @param ssid - The name of the Wi-Fi network to which a paired device is connected
* @param password - The password of the Wi-Fi network to which a paired device is connected
* @param timeout - maximum timeout for wifi devices registration, unit is seconds
* @param token - token value from {@link reqTokenForWifiAp}
*
* @returns Success and failure details as a result
* - in case OK: [ref](https://github.com/iot-device-sdk/blob/main/packages/iot-device-sdk/sample-gw.md)
* - in case Processing: registerWifiEzDevice is started
* - in case Occur Timeout: Timeout
* @example
* ```ts
* iot-device-sdk.registerWifiApDevice(
* "ssid",
* "password",
* 90,
* "token"
* ).then(
* (okRes: any) => {
* debugText("Ok Res")
* assignedWifiDevId = okRes.devId
* console.log("DevID: " + assignedWifiDevId)
* },
* (errRes) => {
* debugText("Ng Res")
* console.log(errRes)
* }
* )
* ```
*/
export async function registerWifiApDevice(ssid: string, password: string, timeout: number, token:string): Promise<any> {
return TuyaSdkBridge.registerWifiApDevice(ssid, password, timeout, token);
}
/**
* Request token to device register <br/>
* This api is used for {@link registerWifiApDevice}
*
* @returns Success and failure details as a result
* - in case OK: token string
* - in case NG: error message
* @example
* ```ts
* iot-device-sdk.reqTokenForWifiAp().then(
* (okRes: any) => {
* console.log("Token: " + okRes)
* },
* (errRes) => {
* console.log(errRes)
* }
* )
* ```
*/
export async function reqTokenForWifiAp(): Promise<string> {
return TuyaSdkBridge.reqTokenForWifiAp();
}