2025.2.21-0 • Published 4 months ago

milesight-load-controller-api v2025.2.21-0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 months ago

Milesight Load Controller API

Description

The Milesight Load Controller API is a microservice built using the NestJS framework. It serves as a command hub for managing Milesight WS558 load controllers through lorawan downlink commands. This service is responsible for:

  • Managing load controller pin states
  • Configuring device reporting intervals
  • Handling device discovery and listing
  • Coordinating with AWS IoT and Wireless IoT services
  • Managing downlink message delivery through RabbitMQ

Core Features

Device Management

  • Device Discovery: List and manage Milesight load controller devices
  • Pin Control: Granular control over individual device pins
  • Reporting Configuration: Customizable device reporting intervals
  • Multi-vendor Support: Native support for Milesight WS558 load controllers

Command Processing

  • Downlink Management: Robust downlink command processing
  • State Control: Comprehensive pin state management
  • Message Queue Integration: RabbitMQ-based command distribution

Architecture

Core Components

  1. API Layer:

    • RESTful endpoints for device control
    • Validation pipeline
    • Error handling
  2. Service Layer:

    • Load Controller Service: Handles device-specific command logic
    • Downlink Service: Manages message queue operations
    • AWS Integration Service: Handles AWS IoT operations
  3. Integration Points:

    • AWS IoT Core
    • AWS IoT Wireless
    • RabbitMQ message queue

Requirements

  • Node 20.15.0
  • RabbitMQ 3.9.11
  • AWS Account with IoT Core access

Additional Requirements for Docker

  • Docker 20.10^
  • Docker Compose 1.27^

Configuration

Environment Variables

Variable NameDescriptionDefault ValueRequired
NODE_ENVApplication environmentdevelopmentYes
STAGEDeployment stagedevelopmentYes
MILESIGHT_LOAD_CONTROLLER_API_PORTAPI port9061Yes
MILESIGHT_LOAD_CONTROLLER_DOWNLINK_FPORTDownlink port85Yes
AMQP_HOSTRabbitMQ hostlocalhostYes
AMQP_USERNAMERabbitMQ usernameguestYes
AMQP_PASSWORDRabbitMQ passwordguestYes
AMQP_PORTRabbitMQ port5672Yes
AMQP_VHOSTRabbitMQ virtual host/Yes
AMQP_PREFETCHRabbitMQ prefetch count200Yes
AMQP_DOWNLINK_EXCHANGERabbitMQ exchangehardware.downlinkexchangeYes
AWS_REGIONAWS regionus-east-1Yes
AWS_ACCESS_KEY_IDAWS access key-Yes
AWS_SECRET_ACCESS_KEYAWS secret key-Yes
ELASTIC_APM_ENABLEDEnable/disable Elastic APMfalseNo
ELASTIC_APM_SERVER_URLElastic APM server URLhttp://localhost:8200No
TRANSACTION_SAMPLE_RATEAPM transaction sample rate1.0No
ELASTIC_APM_SECRET_TOKENElastic APM secret token-No

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Service Dependencies

The Load Controller API provides the following core functionalities:

Device Management

  • List available load controllers
  • Control device pin states
  • Configure reporting intervals
  • Endpoints:

    • GET /load-controller

      // Query Parameters
      {
        maxResult?: number; // 1-250, default 25
        nextToken?: string;
      }
      
      // Response
      {
        "message": "Retrieved device list details",
        "result": {
          "things": [...],
          "nextToken": "..."
        }
      }
    • POST /load-controller/pin-status

      // Request Body
      {
        "deviceEui": "string",
        "serialNumber": "string", // optional
        "pinStatus": {
          "key": boolean // e.g., {"0": true, "1": false}
        }
      }
      
      // Response
      {
        "message": "Successfully sent set pin status command",
        "result": true
      }
    • POST /load-controller/reporting-interval

      // Request Body
      {
        "deviceEui": "string",
        "serialNumber": "string", // optional
        "seconds": number // 60-1800 seconds
      }
      
      // Response
      {
        "message": "Successfully sent set reporting interval command",
        "result": true
      }

External Service Dependencies

The service integrates with the following external services:

ServicePurpose
AWS IoT CoreDevice management and discovery
AWS IoT WirelessLoRaWAN communication
RabbitMQMessage queue for downlink commands

Monitoring and Logging

  • Standardized logging through NestJS Logger
  • Error tracking and debugging support
  • APM integration for performance monitoring
  • RabbitMQ message tracking

License

This project is proprietary software. All rights reserved. This source code is protected under international copyright law. No part of this source code may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of GlacierGrid.

Version: 2024.11.14
Author: Jeff Robert Dagala
Copyright: © 2024 GlacierGrid. All rights reserved.