components:
  schemas:
    LoggerConfig:
      properties:
        ADC_RESOLUTION:
          description: Resolution of ADC measurements. Can be either 12 bits or 16 bits.
          enum:
            - 12
            - 16
          example: 12
          type: integer
        AIN_ENABLED:
          description: >-
            Enables or disables an analog channel AINx. True = enabled, false =
            disabled.
          properties:
            AIN1_ENABLE:
              example: true
              type: boolean
            AIN2_ENABLE:
              example: true
              type: boolean
            AIN3_ENABLE:
              example: true
              type: boolean
            AIN4_ENABLE:
              example: true
              type: boolean
            AIN5_ENABLE:
              example: true
              type: boolean
            AIN6_ENABLE:
              example: true
              type: boolean
            AIN7_ENABLE:
              example: true
              type: boolean
            AIN8_ENABLE:
              example: true
              type: boolean
          type: object
        AIN_RANGE_SELECT:
          description: >-
            Select the range of an analog channel. False = +/- 10V, true = +/-
            60V
          properties:
            AIN1_RANGE:
              example: false
              type: boolean
            AIN2_RANGE:
              example: false
              type: boolean
            AIN3_RANGE:
              example: true
              type: boolean
            AIN4_RANGE:
              example: true
              type: boolean
            AIN5_RANGE:
              example: false
              type: boolean
            AIN6_RANGE:
              example: false
              type: boolean
            AIN7_RANGE:
              example: false
              type: boolean
            AIN8_RANGE:
              example: false
              type: boolean
          type: object
        DIN_ENABLED:
          description: >-
            Enables or disables a digital input. True = enabled, false =
            disabled.
          properties:
            DIN1_ENABLE:
              example: true
              type: boolean
            DIN2_ENABLE:
              example: true
              type: boolean
            DIN3_ENABLE:
              example: true
              type: boolean
            DIN4_ENABLE:
              example: true
              type: boolean
            DIN5_ENABLE:
              example: true
              type: boolean
            DIN6_ENABLE:
              example: true
              type: boolean
          type: object
        EXT_TRIGGER_MODE:
          description: >-
            Sets the external trigger mode of the logger. - `0` - Continuous
            measurement (default) - `1` - External trigger - after starting the
            logger and arming it by activating "Start logger", the Uberlogger
            will acquire data when a digital pin is set to HIGH. The trigger pin
            can be set using the EXT_TRIGGER_PIN setting. - `2` - External
            control - the Uberlogger will start logging and acquiring data after
            the digital pin with value EXT_TRIGGER_PIN will be put HIGH. When
            this pin is LOW, the logger will stop logging. The physical
            start/stop button and the start/stop buttons in the web UI cannot be
            used when setting measurement mode is used.
          enum:
            - 0
            - 1
            - 2
          example: 0
          type: integer
        EXT_TRIGGER_PIN:
          description: Sets the pin for the external trigger input.
          enum:
            - 1
            - 2
            - 3
            - 4
            - 5
            - 6
          example: 1
          type: integer
        EXT_TRIGGER_DEBOUNCE_TIME:
          description: Debounce time for the external trigger in milliseconds.
          minimum: 0
          maximum: 60000
          example: 100
          type: integer
        FILE_DECIMAL_CHAR:
          description: >-
            Character used for decimal notation in files. - `0` - DOT: Decimal
            point. - `1` - COMMA: Decimal comma.
          enum:
            - 0
            - 1
          example: 0
          type: integer
        FILE_NAME_MODE:
          description: >-
            File naming convention used by the logger. - `0` - SEQ_NUM:
            Sequential numbering. - `1` - TIMESTAMP: Based on the timestamp.
          enum:
            - 0
            - 1
          example: 1
          type: integer
        FILE_NAME_PREFIX:
          description: Log file prefix. Cannot contain special characters or spaces.
          example: logfilename
          maxLength: 70
          type: string
        FILE_SEPARATOR_CHAR:
          description: >-
            Character used as a separator in files. - `0` - COMMA: Comma is used
            as a separator. - `1` - SEMICOLON: Semicolon is used as a separator.
          enum:
            - 0
            - 1
          example: 0
          type: integer
        LOG_MODE:
          description: >-
            Logging mode of the device. - `0` - RAW: Stores raw binary data. -
            `1` - CSV: Stores data in CSV format.
          enum:
            - 0
            - 1
          example: 0
          type: integer
        LOG_SAMPLE_RATE:
          description: >-
            Frequency at which the logger samples data. - `0` - Once per hour -
            `1` - Once per 10 minutes - `2` - Once per 5 minutes - `3` - Once
            per minute - `4` - Once per 10 seconds - `5` - 1 Hz - `6` - 2 Hz -
            `7` - 5 Hz - `8` - 10 Hz - `9` - 25 Hz - `10` - 50 Hz - `11` - 100
            Hz - `12` - 250 Hz
          enum:
            - 0
            - 1
            - 2
            - 3
            - 4
            - 5
            - 6
            - 7
            - 8
            - 9
            - 10
            - 11
            - 12
          example: 1
          type: integer
        NTC_SELECT:
          description: Sets the analog input AINx as analog (=false) or NTC input (=true).
          properties:
            NTC1:
              example: true
              type: boolean
            NTC2:
              example: true
              type: boolean
            NTC3:
              example: true
              type: boolean
            NTC4:
              example: false
              type: boolean
            NTC5:
              example: false
              type: boolean
            NTC6:
              example: false
              type: boolean
            NTC7:
              example: false
              type: boolean
            NTC8:
              example: false
              type: boolean
          type: object
        AVERAGE_SAMPLES:
          description: >-
            Sets the sampling mode. - `0` - Normal sampling (default) - `1` -
            Average samples over time (use an IIR filter to average samples over
            time for sample rates below 1 Hz).
          enum:
            - 0
            - 1
          example: 0
          type: integer
        WIFI_CHANNEL:
          description: WiFi channel used by the device. Range is from 1 to 13.
          example: 1
          maximum: 13
          minimum: 1
          type: integer
        WIFI_PASSWORD:
          description: WiFi password of access point the Uberlogger needs to connect to.
          example: your_secret_password
          maxLength: 20
          type: string
        WIFI_SSID:
          description: WiFi SSID of access point the Uberlogger needs to connect to.
          example: My Router SSID
          maxLength: 32
          type: string
      type: object
    LoggerValues:
      properties:
        ERRORCODE:
          description: >-
            Current error code if any. Check manual for the meaning of the error
            codes. Codes can be bitwise OR-ed in this integer.
          type: integer
        FW_VERSION:
          description: Firmware version
          example: 1.3.0_2026.05.22.12.00
          type: string
        LOGGER_STATE:
          description: >
            The current state of the logger. The following values correspond to
            specific states:

            - `1` - IDLE: The logger is idle.

            - `2` - LOGGING: The logger is actively logging data.

            - `3` - PERSISTING: The logger is persisting settings

            - `4` - SYNC: syncing settings with external STM32 chip

            - `5` - SYNC_TIME: syncing the time with STM32

            - `6` - ERROR: error state

            - `7` - REBOOT: system about to reboot 

            - `8` - FIRMWARE_UPDATE: firmware update mode

            - `9` - SINGLE_SHOT: retrieve a single ADC conversion

            - `10` - CALIBRATE: calibration mode enabled

            - `11` - FORMAT_SD_CARD: formatting SD card

            - `14` - WAITING_FOR_TRIGGER: Waiting for external trigger to turn
            high
          enum:
            - 1
            - 2
            - 3
            - 4
            - 5
            - 6
            - 7
            - 8
            - 9
            - 10
            - 11
            - 14
          type: integer
        READINGS:
          properties:
            ANALOG:
              properties:
                UNITS:
                  example: Volt
                  type: string
                VALUES:
                  additionalProperties:
                    type: number
                  description: >-
                    Analog values for sensors. Can include any from AIN1 to
                    AIN8.
                  example:
                    AIN1: 14.225257
                    AIN3: 14.2266462
                    AIN8: 14.2266462
                  type: object
              type: object
            DIGITAL:
              properties:
                UNITS:
                  example: Level
                  type: string
                VALUES:
                  properties:
                    DI1:
                      enum:
                        - 0
                        - 1
                      example: 0
                      type: integer
                    DI2:
                      enum:
                        - 0
                        - 1
                      example: 0
                      type: integer
                    DI3:
                      enum:
                        - 0
                        - 1
                      example: 0
                      type: integer
                    DI4:
                      enum:
                        - 0
                        - 1
                      example: 0
                      type: integer
                    DI5:
                      enum:
                        - 0
                        - 1
                      example: 0
                      type: integer
                    DI6:
                      enum:
                        - 0
                        - 1
                      example: 0
                      type: integer
                  type: object
              type: object
            TEMPERATURE:
              properties:
                UNITS:
                  example: DEG C
                  type: string
                VALUES:
                  additionalProperties:
                    type: number
                  description: >-
                    Temperature values for NTC sensors. Can include any from
                    NTC1 to NTC8.
                  example:
                    NTC2: 25.5
                    NTC4: 26.5
                    NTC5: 27
                    NTC6: 27.5
                    NTC7: 28
                  type: object
              type: object
          type: object
        SD_CARD_FREE_SPACE:
          description: Available space in SD card in KB
          example: 15097344
          type: integer
        SD_CARD_STATUS:
          description: |
            Status of the SD card
            - `0` - EJECTED: SD card is ejected.
            - `1` - UNMOUNTED: SD card is unmounted or not available.
            - `2` - MOUNTED: SD card is mounted
            - `3` - MOUNT_ERROR: Error mounting the SD card
          enum:
            - 0
            - 1
            - 2
            - 3
          example: 2
          type: integer
        TIMESTAMP:
          description: Unix timestamp set on the Uberlogger in ms
          example: 1711207016573
          format: int64
          type: integer
        WIFI_TEST_IP:
          description: WiFi module IP address from access point
          example: 192.168.6.3
          format: ipv4
          type: string
        WIFI_TEST_RSSI:
          description: WiFi signal strength in RSSI
          example: -54
          type: integer
        WIFI_TEST_STATUS:
          description: >
            WiFi connection status

            - `0` - IDLE: Wi-Fi connection idle

            - `1` - DISCONNECTED: The logger is not connected to an access point

            - `2` - CONNECTION_AP_FAILED: Connection to access point failed.

            - `3` - CONNECTION_AP_SUCCESS: The logger succesfully connected to
            the provided access point
          enum:
            - 0
            - 1
            - 2
            - 3
          example: 0
          type: integer
      type: object
info:
  description: >
    The Uberlogger API provides functionalities for managing logger operations. 

    It encompasses endpoints for triggering calibration, formatting the SD
    card, 

    retrieving file lists, obtaining current measurment values, and controlling
    the logger. 

    Each endpoint is thoroughly described, including their operations, expected
    responses, 

    and code samples, facilitating seamless integration and utilization for
    developers.


    **Limitation**: **don't call the endpoints more than twice per second**.
    There is no throttling implemented, so calling them too often may overload
    the Uberlogger and could lead to unstable behaviour.
  title: Uberlogger API
  version: 1.3.0
openapi: 3.0.3
paths:
  /ajax/calibrate:
    post:
      responses:
        '200':
          description: Calibration started successfully
        '403':
          description: Calibration cannot be started (e.g., logger is currently logging)
        '500':
          description: Internal server error
      summary: Trigger calibration process
      tags:
        - Calibration
  /ajax/formatSdcard:
    get:
      responses:
        '200':
          description: Formatting started successfully
        '403':
          description: >-
            Cannot start format (e.g., SD card not inserted or logging is
            active)
        '500':
          description: Internal server error
      summary: Format the SD card
      tags:
        - SD Card Management
  /ajax/getConfig:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoggerConfig'
          description: Successfully retrieved the logger configuration
        '500':
          description: Internal server error
      summary: Get current logger configuration
      tags:
        - Configuration
  /ajax/getFileList/{file_path}:
    get:
      parameters:
        - description: >-
            The path to the file or directory on the SD card. Supports wildcard
            (*) to match multiple files.
          example: 2024_05_05_13_30.csv
          in: path
          name: file_path
          required: true
          schema:
            type: string
      responses:
        '200':
          content:
            application/octet-stream:
              example: Binary data representing the file contents
              schema:
                format: binary
                type: string
          description: File successfully retrieved.
        '400':
          content:
            application/json:
              example:
                error: Filename too long.
          description: Filename too long.
        '404':
          content:
            application/json:
              example:
                error: File does not exist.
          description: File not found.
        '500':
          content:
            application/json:
              examples:
                logging_error:
                  summary: Logging in progress
                  value:
                    error: Cannot request files while logging
                sd_card_error:
                  summary: SD card mount failure
                  value:
                    error: Failed to mount SD card
          description: Internal server error.
      summary: Retrieve a list of files or download a file from the SD card
      tags:
        - File Management
  /ajax/getValues:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoggerValues'
          description: Successfully retrieved the logger values
        '500':
          description: Internal server error
      summary: Get current logger values
      tags:
        - Data
  /ajax/loggerStart:
    post:
      responses:
        '200':
          description: Logging started successfully
        '403':
          description: Logging could not be started (e.g., already logging)
        '500':
          description: Internal server error
      summary: Start the logging process
      tags:
        - Logger Control
  /ajax/loggerStop:
    post:
      responses:
        '200':
          description: Logging stopped successfully
        '403':
          description: Logging could not be stopped (e.g., not currently logging)
        '500':
          description: Internal server error
      summary: Stop the logging process
      tags:
        - Logger Control
  /ajax/reboot:
    post:
      responses:
        '200':
          description: When reponded, system will reboot after 3 seconds.
        '500':
          description: Internal server error
      summary: Reboot the Uberlogger
      tags:
        - Logger Control
  /ajax/sdcardUnmount:
    post:
      responses:
        '200':
          description: SD card unmounted successfully
        '403':
          description: >-
            SD card could not be unmounted (e.g., logging in process or SD card
            not inserted)
        '500':
          description: Internal server error
      summary: Unmount the SD card safely
      tags:
        - SD Card Management
  /ajax/setConfig:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoggerConfig'
        required: true
      responses:
        '200':
          description: Configuration updated successfully
        '400':
          description: Invalid configuration data
        '403':
          description: Cannot set configuration while logging
        '500':
          description: Internal server error
      summary: Set logger configuration
      tags:
        - Configuration
  /ajax/setTime:
    post:
      requestBody:
        content:
          application/json:
            schema:
              properties:
                TIMESTAMP:
                  description: Unix timestamp to set the logger's current time in ms.
                  example: 1711368350281
                  type: integer
              type: object
        required: true
      responses:
        '200':
          description: Successfully set the time
        '400':
          description: Invalid time data provided
        '403':
          description: Cannot set time while logging
        '500':
          description: Internal server error
      summary: Set the current time of the logger
      tags:
        - Configuration
servers:
  - url: http://{host}:{port}
    variables:
      host:
        default: 192.168.4.1
      port:
        default: '80'
