API Reference - jjaroztegi/BuildingSignalSimulator GitHub Wiki

API Reference

🇪🇸 Ver en español

Overview

The Building Signal Simulator provides a RESTful API for interacting with the system. All endpoints return JSON responses and accept JSON payloads where applicable.

Base URL

  • Development: http://localhost:8082/BuildingSignalSimulator
  • Production: http://your-server/BuildingSignalSimulator

Authentication

Currently, the API does not require authentication. This may change in future versions.

Endpoints

Signal Types

Get Signal Types

Retrieves all available signal types and their quality margins.

GET /signal-types

Response

[
  {
    "type": "Signal Type Name",
    "min": minimum_level_value,
    "max": maximum_level_value
  }
]

Components

List Components by Type

Get a list of component models for a specific type.

GET /components?type={type}

Parameters

  • type (required): One of coaxial, derivador, distribuidor, or toma

Response

["model1", "model2", "model3"]

Get Component Details

Get detailed information about a specific component.

GET /components?type={type}&model={model}

Parameters

  • type (required): One of coaxial, derivador, distribuidor, or toma
  • model (required): The model name of the component

Response Examples

Coaxial Cable

{
    "costo": 0.0,
    "atenuacion_470mhz": 0.0,
    "atenuacion_694mhz": 0.0
}

Derivador (Tap)

{
    "costo": 0.0,
    "atenuacion_derivacion": 0.0,
    "atenuacion_paso": 0.0,
    "directividad": 0.0,
    "desacoplo": 0.0,
    "perdidas_retorno": 0.0
}

Distribuidor (Splitter)

{
    "costo": 0.0,
    "numero_salidas": 0,
    "atenuacion_distribucion": 0.0,
    "desacoplo": 0.0,
    "perdidas_retorno": 0.0
}

Toma (Outlet)

{
    "costo": 0.0,
    "atenuacion": 0.0,
    "desacoplo": 0.0
}

Add New Component

Add a new component to the system.

POST /components

Request Body

{
    "type": "component_type",
    "modelo": "model_name",
    "costo": 0.0,
    "properties": {
        // Component-specific properties
    }
}

Response

{
    "success": "Component added successfully"
}

Configurations

List Configurations

Get all available configurations.

GET /configurations

Response

[
    {
        "id_configuraciones": "config_id",
        "nombre": "Configuration Name",
        "nivel_cabecera": 95.0,
        "num_pisos": 5,
        "costo_total": 0.0,
        "fecha_creacion": "2024-03-20 12:00:00",
        "usuario_creacion": "admin",
        "fecha_modificacion": "2024-03-20 12:00:00",
        "usuario_modificacion": "admin"
    }
]

Add New Configuration

Create a new configuration.

POST /configurations

Request Body

{
    "nombre": "Configuration Name",
    "nivel_cabecera": 95.0,
    "num_pisos": 5
}

Response

{
    "success": "Configuration added successfully",
    "id": "configuration_id"
}

Update Configuration

Update an existing configuration.

PUT /configurations

Request Body

{
    "id_configuraciones": "config_id",
    "nombre": "New Name",
    "nivel_cabecera": 95.0,
    "num_pisos": 5
}

Response

{
    "success": "Configuration updated successfully"
}

Delete Configuration

Delete an existing configuration.

DELETE /configurations

Request Body

{
    "id_configuraciones": "config_id"
}

Response

{
    "success": "Configuration deleted successfully"
}

Signal Calculation

Calculate Signal Levels

Calculate and validate signal levels for each floor.

POST /calculate

Request Body

{
    "num_pisos": 5,
    "nivel_cabecera": 95.0,
    "tipo_senal": "signal_type",
    "components": [
        {
            "type": "derivador",
            "model": "DER-2",
            "floor": 1
        },
        {
            "type": "coaxial",
            "model": "RG-6",
            "floor": 1
        },
        {
            "type": "toma",
            "model": "TOMA-1",
            "floor": 1
        }
    ]
}

Response

{
    "levels": [
        {
            "floor": 1,
            "level": 85.5,
            "status": "OK"
        }
    ],
    "total_cost": 150.75,
    "is_valid": true
}

Error Handling

All endpoints follow a consistent error response format:

{
    "error": true,
    "message": "Error description",
    "code": "ERROR_CODE"
}

Common error codes:

  • INVALID_PARAMETER: Invalid request parameter
  • COMPONENT_NOT_FOUND: Requested component not found
  • CONFIGURATION_NOT_FOUND: Configuration not found
  • DATABASE_ERROR: Database operation failed
  • VALIDATION_ERROR: Input validation failed

Rate Limiting

Currently, there are no rate limits implemented. This may change in future versions.

Versioning

The API is currently at v1. The version is not included in the URL path but may be in future releases.

Best Practices

  1. Always specify the content type in requests:

    Content-Type: application/json
    
  2. Handle errors appropriately by checking the response status code and error message.

  3. Use appropriate HTTP methods for different operations:

    • GET for retrieving data
    • POST for creating new resources
    • PUT for updating existing resources
    • DELETE for removing resources
  4. Include all required parameters in requests to avoid validation errors.

Examples

Complete Configuration Flow

  1. Create a new configuration:
curl -X POST http://localhost:8082/BuildingSignalSimulator/configurations \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "Edificio A",
    "nivel_cabecera": 95.0,
    "num_pisos": 5
  }'
  1. Add components to floors:
curl -X POST http://localhost:8082/BuildingSignalSimulator/calculate \
  -H "Content-Type: application/json" \
  -d '{
    "num_pisos": 5,
    "nivel_cabecera": 95.0,
    "tipo_senal": "TDT",
    "components": [
      {
        "type": "derivador",
        "model": "DER-2",
        "floor": 1
      }
    ]
  }'