Skip to content

Installation Guide

This guide covers the installation process for the Energy Manager IoT library and all required dependencies.

Library Installation

Install the library using npm:

npm install energy-manager-iot

Or using yarn:

yarn add energy-manager-iot

Dependencies

Energy Manager IoT has the following direct dependencies:

  • mqtt: For MQTT communication
  • winston: For advanced logging capabilities

These will be installed automatically when you install the library.

MQTT Broker Setup

The Energy Manager IoT library requires an MQTT broker to function. Here are instructions for setting up the most common brokers:

Mosquitto is a lightweight MQTT broker that works well for both development and production.

  1. Download the installer from https://mosquitto.org/download/
  2. Follow the installer instructions
  3. Add Mosquitto to your system PATH if the installer doesn't do it automatically
  4. Start the broker by opening a command prompt and running:
    mosquitto -v
    
# Install Mosquitto
sudo apt update
sudo apt install mosquitto mosquitto-clients

# Start the service
sudo systemctl start mosquitto

# Make it start on boot
sudo systemctl enable mosquitto

# Check status
sudo systemctl status mosquitto

Using Homebrew:

# Install Mosquitto
brew install mosquitto

# Start the broker
brew services start mosquitto

Basic Mosquitto Configuration

The default configuration works for testing, but for production, you should secure your MQTT broker.

Create or edit the mosquitto.conf file (location depends on your OS):

# Basic listener configuration
listener 1883
protocol mqtt

# Enable persistent sessions
persistence true
persistence_location /var/lib/mosquitto/

# Logging
log_dest file /var/log/mosquitto/mosquitto.log
log_type all

TypeScript Configuration

If you're using TypeScript, the library includes type definitions. Ensure your tsconfig.json includes:

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "CommonJS",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

Verification

To verify your installation, create a simple test file:

// test.ts
import { EnergyManager } from 'energy-manager-iot';

async function test() {
  const manager = new EnergyManager();
  console.log('Energy Manager IoT library installed successfully!');
  console.log('Version:', manager.VERSION);
}

test();

Run it using:

ts-node test.ts

If you see the success message, your installation is complete!

Next Steps

Now that you've installed Energy Manager IoT, proceed to the Quick Start Guide to learn how to use the library.