TuyaLinkWizard
A wrapper that combines @tuya/tuya-connector-nodejs and
(@tuyapi/link).manual (included in this package)
to make registration Just Work™️. Exported as
(@tuyapi/link).wizard.
new TuyaLinkWizard(options: Object)
Parameters
options
(Object
= {})
construction options
| Name | Description |
|---|---|
options.email String
|
user email |
options.password String
|
user password |
options.region String
(default 'us')
|
region (us=Americas, cn=Asia, eu=Europe) |
options.timezone String
(default 'America/Chicago')
|
timezone of device in tz format |
options.apiKey String
|
API key |
options.apiSecret String
|
API secret |
options.schema String
|
app schema to register the device under |
Example
// Note: user account does not need to already exist
const register = new TuyaLink.wizard({key: 'your-api-key',
secret: 'your-api-secret',
email: 'example@example.com',
password: 'example-password'});
Instance Members
▸
init()
▸
linkDevice(options)
Links device to WiFi and cloud
Parameters
options
(Object
= {})
options
| Name | Description |
|---|---|
options.timeout Number
(default 100)
|
how long we should wait for devices to connect before throwing an error, in seconds |
options.ssid String
|
the SSID to send to the device |
options.wifiPassword String
(default '')
|
password for the SSID |
options.devices Number
(default 1)
|
if linking more than 1 device at a time, set to number of devices being linked |
Returns
Promise<Object>:
A Promise that contains data on device(s)
Example
register.linkDevice({ssid: 'example-ssid',
wifiPassword: 'example-password'}).then(device => {
console.log(device);
});
TuyaLink
A lower level option for linking
devices. Use only if you're not generating
a token through @tuyapi/cloud. Exported
as (@tuyapi/link).manual.
new TuyaLink()
Example
const register = new TuyaLink.manual();
Instance Members
▸
registerSmartLink(options)
Thin wrapper for this.sendSmartLinkStart() and this.sendSmartLinkData(). Unless you have a special use case, prefer this method over calling this.sendSmartLinkStart() and this.sendSmartLinkData() directly.
Parameters
Returns
Promise<Undefined>:
A Promise that resolves when all data has been transmitted
Example
device.registerSmartLink({region: 'AZ',
token: '00000000',
secret: '0101',
ssid: 'Example SSID',
wifiPassword: 'example-password'}).then(() => {
console.log('Done!');
});
▸
sendSmartLinkStart()
▸
sendSmartLinkData(data)
▸
abortBroadcastingData()
Aborts broadcasting UDP packets.
abortBroadcastingData()
▸
smartLinkEncode(options)
Encodes data as UDP packet lengths.
Parameters
Returns
Array:
array of packet lengths
▸
cleanup()
Un-references UDP instance so that a script can cleanly exit.
cleanup()
