{
  "openapi": "3.0.3",
  "info": {
    "title": "BME280 Sensor API",
    "version": "1.1.0",
    "description": "Current temperature, relative humidity and barometric pressure from a Bosch BME280 sensor attached to a Raspberry Pi.\n\nReadings are cached for a short time (default 2 s), so polling faster than that returns the same reading. Every response allows cross-origin requests (`Access-Control-Allow-Origin: *`)."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "security": [],
  "tags": [
    {
      "name": "Sensor",
      "description": "Sensor readings"
    },
    {
      "name": "Service",
      "description": "Service status"
    }
  ],
  "paths": {
    "/api/reading": {
      "get": {
        "tags": [
          "Sensor"
        ],
        "operationId": "getReading",
        "summary": "Get the current sensor values",
        "description": "Returns the current temperature (°C and °F), relative humidity and pressure.",
        "responses": {
          "200": {
            "description": "Current reading",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Reading"
                }
              }
            }
          },
          "503": {
            "description": "The sensor could not be read (e.g. disconnected). Retry later.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "Sensor unavailable: Remote I/O error"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "Service"
        ],
        "operationId": "getHealth",
        "summary": "Check service and sensor health",
        "responses": {
          "200": {
            "description": "Service is running and the sensor responds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "ok",
                  "sensor": "ok"
                }
              }
            }
          },
          "503": {
            "description": "Service is running but the sensor does not respond",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "degraded",
                  "sensor": "Remote I/O error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Reading": {
        "type": "object",
        "required": [
          "time",
          "temperatureC",
          "temperatureF",
          "humidityPct",
          "pressureHPa"
        ],
        "properties": {
          "time": {
            "type": "string",
            "format": "date-time",
            "description": "When the measurement was taken (UTC, ISO 8601)",
            "example": "2026-11-11T15:58:22.734Z"
          },
          "temperatureC": {
            "type": "number",
            "format": "double",
            "description": "Temperature in degrees Celsius (2 decimals)",
            "example": 26.18
          },
          "temperatureF": {
            "type": "number",
            "format": "double",
            "description": "Temperature in degrees Fahrenheit (2 decimals)",
            "example": 79.12
          },
          "humidityPct": {
            "type": "number",
            "format": "double",
            "minimum": 0,
            "maximum": 100,
            "description": "Relative humidity in percent (1 decimal)",
            "example": 47.3
          },
          "pressureHPa": {
            "type": "number",
            "format": "double",
            "description": "Barometric pressure at the sensor in hectopascal (2 decimals), not adjusted to sea level",
            "example": 1016.5
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "status",
          "sensor"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded"
            ]
          },
          "sensor": {
            "type": "string",
            "description": "\"ok\", or the error from the last sensor access"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable error message"
          }
        }
      }
    }
  }
}