Closed antonioGabrielGomes closed 1 year ago
About this selfApiKey, where can it be generated? Could you make a complete example?
`// eWeLink Lan Control import eWeLink from "ewelink-api-next";
const lanClient = new eWeLink.Lan({ selfApikey: "xxx", logObj: eWeLink.createLogger("lan") });
lanClient.discovery((server) => { console.log("server:", server); }); // Start Discovery Service
// Save device information to local cache
// When controlling, it is necessary to pass in deviceId, secretKey, encryption, iv try { const res = await lanClient.zeroconf.switch({ ip: "xxx", port: 80, data: { switch: "on" }, deviceId: "xxx", secretKey: "xxx", encrypt: true, iv: "xxx" }); console.info("Request result::", res); const res2 = await lanClient.zeroconf.switches({ ip: "xxx", port: 80, data: { switches: [ { switch: "on", outlet: 0 }, { switch: "on", outlet: 1 }, { switch: "on", outlet: 2 }, { switch: "on", outlet: 3 } ] }, deviceId: "xxx", secretKey: "xxx", encrypt: true, iv: "xxx" }); console.info("Request result::", res2); } catch (error: any) { console.info(error.message); }`
selfApiKey='user.apikey' obtained after login
You can indirectly obtain your apikey by accessing your device information, home, and other related interfaces
About this selfApiKey, where can it be generated? Could you make a complete example?
`// eWeLink Lan Control import eWeLink from "ewelink-api-next";
const lanClient = new eWeLink.Lan({ selfApikey: "xxx", logObj: eWeLink.createLogger("lan") });
lanClient.discovery((server) => { console.log("server:", server); }); // Start Discovery Service
// Save device information to local cache
// When controlling, it is necessary to pass in deviceId, secretKey, encryption, iv try { const res = await lanClient.zeroconf.switch({ ip: "xxx", port: 80, data: { switch: "on" }, deviceId: "xxx", secretKey: "xxx", encrypt: true, iv: "xxx" }); console.info("Request result::", res); const res2 = await lanClient.zeroconf.switches({ ip: "xxx", port: 80, data: { switches: [ { switch: "on", outlet: 0 }, { switch: "on", outlet: 1 }, { switch: "on", outlet: 2 }, { switch: "on", outlet: 3 } ] }, deviceId: "xxx", secretKey: "xxx", encrypt: true, iv: "xxx" }); console.info("Request result::", res2); } catch (error: any) { console.info(error.message); }`