{
  "openapi": "3.0.4",
  "info": {
    "title": "OpenSonde.API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.opensonde.com"
    }
  ],
  "paths": {
    "/api/Readings": {
      "post": {
        "tags": [
          "Readings"
        ],
        "summary": "Report device readings and status",
        "description": "Accepts one or more sensor samples for the authenticated device.\n            \nThis endpoint may also be called with only device metadata\n(such as battery level or latitude/longitude), or with an empty\nrequest body, to act as a keep-alive/heartbeat signal.\n            \nEach call updates the device’s “last seen” timestamp, even when\nno samples are included.\n            \nThe current server time (Epoch 2025 seconds) is returned in the\nX-Server-Time response header.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReadingRequest"
              },
              "example": {
                "samples": {
                  "13046400": {
                    "values": {
                      "t0": "21.4",
                      "t1": "18.2"
                    },
                    "latitude": 51.5072,
                    "longitude": -0.1276
                  },
                  "13047300": {
                    "values": {
                      "t0": "21.6",
                      "t1": "18.3"
                    }
                  }
                },
                "latitude": 51.5072,
                "longitude": -0.1276,
                "batt_p": 87,
                "rssi": -85,
                "next": 13048200,
                "fw": "1.0.3",
                "updates": {
                  "eps": [
                    "t1"
                  ],
                  "dps": [ ]
                }
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/ReadingRequest"
              },
              "example": {
                "samples": {
                  "13046400": {
                    "values": {
                      "t0": "21.4",
                      "t1": "18.2"
                    },
                    "latitude": 51.5072,
                    "longitude": -0.1276
                  },
                  "13047300": {
                    "values": {
                      "t0": "21.6",
                      "t1": "18.3"
                    }
                  }
                },
                "latitude": 51.5072,
                "longitude": -0.1276,
                "batt_p": 87,
                "rssi": -85,
                "next": 13048200,
                "fw": "1.0.3",
                "updates": {
                  "eps": [
                    "t1"
                  ],
                  "dps": [ ]
                }
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/ReadingRequest"
              },
              "example": {
                "samples": {
                  "13046400": {
                    "values": {
                      "t0": "21.4",
                      "t1": "18.2"
                    },
                    "latitude": 51.5072,
                    "longitude": -0.1276
                  },
                  "13047300": {
                    "values": {
                      "t0": "21.6",
                      "t1": "18.3"
                    }
                  }
                },
                "latitude": 51.5072,
                "longitude": -0.1276,
                "batt_p": 87,
                "rssi": -85,
                "next": 13048200,
                "fw": "1.0.3",
                "updates": {
                  "eps": [
                    "t1"
                  ],
                  "dps": [ ]
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Request accepted. Device status updated and any provided samples stored."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ReadingRequest": {
        "type": "object",
        "properties": {
          "samples": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Sample"
            },
            "description": "Dictionary/map of samples keyed by Epoch 2025 seconds. Each entry becomes one reading.",
            "nullable": true
          },
          "latitude": {
            "type": "number",
            "description": "The latitude value at the time of request.",
            "format": "double",
            "nullable": true
          },
          "longitude": {
            "type": "number",
            "description": "The longitude value at the time of request.",
            "format": "double",
            "nullable": true
          },
          "batt_p": {
            "maximum": 100,
            "minimum": 0,
            "type": "number",
            "description": "Battery level as a percentage (0-100) at time of request.",
            "format": "double",
            "nullable": true
          },
          "rssi": {
            "maximum": 0,
            "minimum": -140,
            "type": "integer",
            "description": "Received signal strength in dBm (e.g. -113 weakest to -51 strongest for cellular).",
            "format": "int32",
            "nullable": true
          },
          "next": {
            "type": "integer",
            "description": "When the device is expected to next check in, as Epoch 2025 seconds.",
            "format": "int64",
            "nullable": true
          },
          "fw": {
            "type": "string",
            "description": "The firmware version the device is running. Ignored if empty.",
            "nullable": true
          },
          "updates": {
            "$ref": "#/components/schemas/Updates"
          }
        },
        "additionalProperties": false,
        "description": "The request body shape sent to the readings endpoint."
      },
      "Sample": {
        "type": "object",
        "properties": {
          "values": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "The parameter values for this sample.",
            "nullable": true
          },
          "latitude": {
            "type": "number",
            "description": "The latitude value of the device when the reading was taken.",
            "format": "double",
            "nullable": true
          },
          "longitude": {
            "type": "number",
            "description": "The longitude value of the device when the reading was taken.",
            "format": "double",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "Updates": {
        "type": "object",
        "properties": {
          "eps": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Keys of the parameters to enable.",
            "nullable": true
          },
          "dps": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Keys of the parameters to disable.",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Parameter enable/disable changes reported by the device."
      }
    }
  },
  "tags": [
    {
      "name": "Readings"
    }
  ]
}