function execute
execute(
baseUrl: string,
actions: Action[],
): Promise<ExecuteResult>

Executes one or more actions on the router.

Handles the full request/response cycle:

  1. Splits the actions into as many round trips as the dialect needs
  2. Encrypts and sends each request
  3. Decrypts and decodes each response
  4. Maps responses back onto the original requests by position

The returned actions array always has one entry per input action, in input order; actions the router returned nothing for carry res: null. A transport failure (any non-200 response) short-circuits to { error: -1, actions: [] }.

Examples

Get LTE band information

import { ACT, authenticate, execute } from "@hertzg/tplink-api";

const auth = await authenticate("http://192.168.1.1", { password: "admin" });
if (auth) {
  const result = await execute(
    "http://192.168.1.1",
    [[ACT.GET, "LTE_BANDINFO"]],
    auth,
  );
  // result.actions[0].res contains the band info
}

Execute multiple actions

import { ACT, authenticate, execute } from "@hertzg/tplink-api";

const auth = await authenticate("http://192.168.1.1", { password: "admin" });
if (auth) {
  const result = await execute(
    "http://192.168.1.1",
    [
      [ACT.SET, "LTE_SMS_UNREADMSGBOX", { pageNumber: "1" }],
      [ACT.GS, "LTE_SMS_UNREADMSGENTRY", ["index", "from", "content"]],
    ],
    auth,
  );
}

Parameters

baseUrl: string

Base URL of the router

actions: Action[]

Array of actions to execute

Execution options from authentication result

Return Type

Promise<ExecuteResult>

Execution result with error status and action responses