@improv-wifi/serial-sdk 0.0.0-stage → 2.10.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.
- package/LICENSE +201 -0
- package/README.md +114 -2
- package/dist/const.d.ts +56 -0
- package/dist/const.js +37 -0
- package/dist/provision.d.ts +2 -0
- package/dist/provision.js +26 -0
- package/dist/serial-launch-button.d.ts +7 -0
- package/dist/serial-launch-button.js +79 -0
- package/dist/serial-provision-dialog.d.ts +53 -0
- package/dist/serial-provision-dialog.js +691 -0
- package/dist/serial.d.ts +143 -0
- package/dist/serial.js +626 -0
- package/dist/util/fire-event.d.ts +5 -0
- package/dist/util/fire-event.js +12 -0
- package/dist/util/hex-formatter.d.ts +1 -0
- package/dist/util/hex-formatter.js +2 -0
- package/dist/util/to-hex.d.ts +1 -0
- package/dist/util/to-hex.js +9 -0
- package/dist/web/serial-launch-button.js +1 -0
- package/dist/web/serial-provision-dialog-DR-raZEr.js +803 -0
- package/package.json +36 -4
package/dist/serial.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { ImprovSerialCurrentState, ImprovSerialErrorState, Logger } from "./const.js";
|
|
2
|
+
export interface Ssid {
|
|
3
|
+
name: string;
|
|
4
|
+
rssi: number;
|
|
5
|
+
secured: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface NetworkState {
|
|
8
|
+
online: boolean;
|
|
9
|
+
supportsWifi: boolean;
|
|
10
|
+
supportsEthernet: boolean;
|
|
11
|
+
supportsThread: boolean;
|
|
12
|
+
supportsModem: boolean;
|
|
13
|
+
urls: string[];
|
|
14
|
+
}
|
|
15
|
+
export declare class ImprovSerial extends EventTarget {
|
|
16
|
+
port: SerialPort;
|
|
17
|
+
logger: Logger;
|
|
18
|
+
info?: {
|
|
19
|
+
name: string;
|
|
20
|
+
firmware: string;
|
|
21
|
+
version: string;
|
|
22
|
+
chipFamily: string;
|
|
23
|
+
osName: string | null;
|
|
24
|
+
osVersion: string | null;
|
|
25
|
+
};
|
|
26
|
+
improvVersion: number | undefined;
|
|
27
|
+
nextUrl: string | undefined;
|
|
28
|
+
state?: ImprovSerialCurrentState | undefined;
|
|
29
|
+
private _error;
|
|
30
|
+
/** Last device error (or local timeout). Assigning dispatches `error-changed`. */
|
|
31
|
+
get error(): ImprovSerialErrorState;
|
|
32
|
+
set error(error: ImprovSerialErrorState);
|
|
33
|
+
private _networkState;
|
|
34
|
+
/**
|
|
35
|
+
* Last known network state: `undefined` until a request succeeds, `null` once
|
|
36
|
+
* the device reports the command unsupported. Changes dispatch `network-state-changed`.
|
|
37
|
+
*/
|
|
38
|
+
get networkState(): NetworkState | null | undefined;
|
|
39
|
+
private _stopNetworkStatePolling?;
|
|
40
|
+
private _reader?;
|
|
41
|
+
private _rpcFeedback?;
|
|
42
|
+
private _rpcLock;
|
|
43
|
+
constructor(port: SerialPort, logger: Logger);
|
|
44
|
+
/**
|
|
45
|
+
* Detect Improv Serial, fetch the state and return the next URL if provisioned.
|
|
46
|
+
* @param timeout Timeout in ms to wait for the device to respond. Default to 1000ms.
|
|
47
|
+
*/
|
|
48
|
+
initialize(timeout?: number): Promise<this["info"]>;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* This command will trigger at least one packet,
|
|
52
|
+
* the Current State and if already provisioned,
|
|
53
|
+
* the same response you would get if device provisioning
|
|
54
|
+
* was successful (see below).
|
|
55
|
+
*
|
|
56
|
+
* A caller polling an intermittently-unresponsive device (e.g. one rebooting
|
|
57
|
+
* to switch network interfaces) can pass a timeout shorter than the default
|
|
58
|
+
* so each poll settles quickly.
|
|
59
|
+
*/
|
|
60
|
+
requestCurrentState(timeout?: number): Promise<void>;
|
|
61
|
+
requestInfo(timeout?: number): Promise<void>;
|
|
62
|
+
provision(ssid: string, password: string, timeout?: number): Promise<void>;
|
|
63
|
+
scan(timeout?: number): Promise<Ssid[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Continuously scan for Wi-Fi networks, calling `onChange` whenever the list
|
|
66
|
+
* of networks changes.
|
|
67
|
+
*
|
|
68
|
+
* Results are merged with previous scans (networks are keyed by name and kept
|
|
69
|
+
* sorted alphabetically), so a network missing from a single scan won't
|
|
70
|
+
* immediately disappear. `onChange` is only called when a value in the list
|
|
71
|
+
* actually changes.
|
|
72
|
+
*
|
|
73
|
+
* Scanning stops on the first error or when the returned function is called.
|
|
74
|
+
* If the first scan fails (e.g. the device doesn't support scanning, or stops
|
|
75
|
+
* responding), `onChange` is called once with `null` to signal that networks
|
|
76
|
+
* are unavailable.
|
|
77
|
+
*
|
|
78
|
+
* The returned function resolves once the in-flight scan has settled, so it
|
|
79
|
+
* can be awaited before sending another RPC command (such as provisioning).
|
|
80
|
+
*/
|
|
81
|
+
subscribeSSIDs(onChange: (ssids: Ssid[] | null) => void): () => Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Get the current hostname of the device.
|
|
84
|
+
*/
|
|
85
|
+
getHostname(timeout?: number): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Set the hostname of the device. Returns the hostname as set by the device.
|
|
88
|
+
*
|
|
89
|
+
* Hostnames need to conform to RFC 1123: letters, numbers and hyphens, up to
|
|
90
|
+
* 255 characters. The device rejects other hostnames with a BAD_HOSTNAME error.
|
|
91
|
+
*/
|
|
92
|
+
setHostname(hostname: string, timeout?: number): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Get the current device name. This is the same value as `info.name`.
|
|
95
|
+
*/
|
|
96
|
+
getDeviceName(timeout?: number): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Set the device name. Returns the device name as set by the device.
|
|
99
|
+
*
|
|
100
|
+
* When setting both the device name and the hostname, set the device name
|
|
101
|
+
* first, as it can change the default hostname.
|
|
102
|
+
*/
|
|
103
|
+
setDeviceName(deviceName: string, timeout?: number): Promise<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Request the device's network connectivity and supported interfaces.
|
|
106
|
+
*
|
|
107
|
+
* This is independent of the Wi-Fi provisioning state: a device already
|
|
108
|
+
* online over Ethernet reports that here without Wi-Fi provisioning. The
|
|
109
|
+
* first response string is the network flags as a decimal-encoded byte, and
|
|
110
|
+
* when online the reachable device URL(s) follow.
|
|
111
|
+
*
|
|
112
|
+
* This command is optional. Devices that do not implement it respond with
|
|
113
|
+
* UNKNOWN_RPC_COMMAND, so this rejects with that error for such devices.
|
|
114
|
+
*/
|
|
115
|
+
requestNetworkState(timeout?: number): Promise<NetworkState>;
|
|
116
|
+
/**
|
|
117
|
+
* Poll the device's network state, keeping `networkState` fresh. Idempotent;
|
|
118
|
+
* stopped by `stopNetworkStatePolling()`, `close()`, a disconnect, or the
|
|
119
|
+
* device reporting the command unsupported. A failed poll keeps the last
|
|
120
|
+
* known state, leaves `error` untouched and retries on the next tick.
|
|
121
|
+
*/
|
|
122
|
+
startNetworkStatePolling(interval?: number, timeout?: number): void;
|
|
123
|
+
stopNetworkStatePolling(): void;
|
|
124
|
+
private _requestNetworkState;
|
|
125
|
+
private _setNetworkState;
|
|
126
|
+
private _sendRPC;
|
|
127
|
+
/**
|
|
128
|
+
* Run an RPC command once the previous one has settled, so devices that
|
|
129
|
+
* handle a single command at a time never see two at once. The chain is kept
|
|
130
|
+
* alive regardless of each command's outcome.
|
|
131
|
+
*/
|
|
132
|
+
private _enqueueRPC;
|
|
133
|
+
private _sendRPCWithResponse;
|
|
134
|
+
private _sendRPCWithMultipleResponses;
|
|
135
|
+
private _awaitRPCResultWithTimeout;
|
|
136
|
+
private _processInput;
|
|
137
|
+
private _handleIncomingPacket;
|
|
138
|
+
/**
|
|
139
|
+
* Add header + checksum and write packet to stream
|
|
140
|
+
*/
|
|
141
|
+
writePacketToStream(type: number, data: number[]): Promise<void>;
|
|
142
|
+
private _setError;
|
|
143
|
+
}
|