Skip to content

Using Energy Manager IoT

This section provides detailed information on how to use the Energy Manager IoT library effectively.

Overview

Energy Manager IoT is designed to provide a comprehensive solution for managing IoT devices with a focus on energy efficiency. The library offers:

  • Device Management - Register, update, and remove IoT devices
  • Group Organization - Create groups to organize devices by location or function
  • Power Management - Send sleep/wake commands to optimize energy usage
  • Status Monitoring - Receive and process device status updates
  • Analytics - Calculate statistics across device groups

Core Components

The library is built around three main classes:

  1. EnergyManager - The main entry point for the library
  2. DeviceRegistry - Handles device registration and grouping
  3. MqttHandler - Manages MQTT communication

Basic Workflow

The typical workflow for using the Energy Manager IoT library follows these steps:

  1. Create an instance of the EnergyManager class
  2. Connect to your MQTT broker
  3. Register devices that you want to manage
  4. Organize devices into groups for easier management
  5. Send commands to control device behavior
  6. Process status updates from devices
  7. Use analytics to monitor energy usage and performance

Guides in This Section

Quick Start

For those eager to get started, here's a minimal example:

import { EnergyManager, DeviceType } from 'energy-manager-iot';

async function quickStart() {
  // Create a manager instance
  const manager = new EnergyManager();

  try {
    // Connect to MQTT broker
    await manager.connect('mqtt://localhost:1883');

    // Register a device
    manager.registerDevice('sensor1', 'Temperature Sensor', DeviceType.SENSOR);

    // Listen for status updates
    manager.on('statusUpdate', (deviceId, status) => {
      console.log(`Status update from ${deviceId}:`, status);
    });

    console.log('Energy Manager initialized and listening for updates');
  } catch (error) {
    console.error('Failed to initialize:', error);
  }
}

quickStart();

For more detailed usage examples, please explore the guides in this section.