Skip to main content

Service Control

Each ESPRMService instance under ESPRMNode instance will have a set of ESPRMServiceParam that can be updated using the setValue API. This method requires the value to be set and returns a response indicating the success or failure of the operation.

To control a service, you need to navigate through the node hierarchy:

  1. Get the node - Retrieve the node using getUserNodes() or getNodeDetails()
  2. Access node configuration - Get the nodeConfig from the node
  3. Find the service - Access the services array from nodeConfig
  4. Get service parameters - Access the params array from the service
  5. Update parameter value - Call setValue() on the specific parameter

Example: Complete Flow for Service Parameter Control

try {
// Step 1: Get user nodes
const response = await userInstance.getUserNodes();

// Step 2: Find the specific node
const targetNode = response.nodes.find(node => node.id === "your_node_id");

if (!targetNode) {
console.error("Node not found");
return;
}

// Step 3: Get node configuration
const nodeConfig = targetNode.nodeConfig || await targetNode.getNodeConfig();

// Step 4: Find the specific service (e.g., Time service)
const timeService = nodeConfig.services.find(
service => service.type === "esp.service.time"
);

if (!timeService) {
console.error("Service not found");
return;
}

// Step 5: Find the specific parameter (e.g., TZ parameter)
const tzParam = timeService.params.find(
param => param.name === "TZ"
);

if (!tzParam) {
console.error("Parameter not found");
return;
}

// Step 6: Update the parameter value
const timezone = "America/Los_Angeles";
const updateResponse = await tzParam.setValue(timezone);

console.log("Service parameter updated successfully:", updateResponse);
} catch (error) {
console.error("Error updating service parameter:", error);
}

Example: Using getServices Method

You can also use the getServices() method on the node instance to retrieve services:

try {
const response = await userInstance.getUserNodes();
const node = response.nodes[0];

// Get services directly from node
const services = await node.getServices();

// Find Time service
const timeService = services.find(
service => service.type === "esp.service.time"
);

if (timeService) {
// Find and update TZ parameter
const tzParam = timeService.params.find(param => param.name === "TZ");
if (tzParam) {
await tzParam.setValue("Asia/Kolkata");
console.log("Timezone updated");
}
}
} catch (error) {
console.error("Error updating service parameter:", error);
}

Example: Finding Service Parameters by Type

You can find service parameters by their type:

try {
const response = await userInstance.getUserNodes();
const node = response.nodes[0];
const nodeConfig = node.nodeConfig || await node.getNodeConfig();
const service = nodeConfig.services[0];

// Find parameter by type (e.g., esp.param.tz)
const tzParam = service.params.find(
param => param.type === "esp.param.tz"
);

if (tzParam) {
await tzParam.setValue("Europe/London");
console.log("Timezone parameter updated");
}
} catch (error) {
console.error("Error updating parameter:", error);
}

Service Parameter setValue API

ParameterTypeDescription
value*anyThe value of parameter to update.
note

The setValue method returns a response indicating the success or failure of the operation. The response structure depends on the SDK implementation and may include status information, updated parameter values, or error details.

On this page