{
  "openapi": "3.0.0",
  "info": {
    "title": "WEM Local HTTP API",
    "version": "1.1.0",
    "description": "Interactive test specification for current WEM local HTTP APIs. Public endpoints are listed first. Use Authorize for endpoints protected by the optional Admin Security module."
  },
  "servers": [
    {
      "url": "http://11.11.11.1",
      "description": "Default AP mode address"
    }
  ],
  "tags": [
    {
      "name": "Public",
      "description": "Endpoints that remain accessible without HTTP Basic Authentication."
    },
    {
      "name": "Admin-Security-Public",
      "description": "Public status and signed recovery endpoints. Recovery still requires a valid Ed25519 signature."
    },
    {
      "name": "Admin-Security-Authenticated",
      "description": "Administrator validation and credential configuration. Use Authorize when Admin Security is enabled."
    },
    {
      "name": "WEM-Configuration-Authenticated",
      "description": "WEM network, advanced configuration, and history endpoints. Basic Auth is required when Admin Security is enabled."
    },
    {
      "name": "WEM-Legacy-Authenticated",
      "description": "Legacy WEM single-setting APIs. Basic Auth is required when Admin Security is enabled."
    },
    {
      "name": "TLS-CA-Authenticated",
      "description": "Outbound MQTTS/HTTPS certificate verification. Admin Security and valid Basic Auth are required."
    },
    {
      "name": "Maintenance-Authenticated",
      "description": "Restart and reset operations. Basic Auth is required when Admin Security is enabled."
    }
  ],
  "paths": {
    "/api/monitor": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Get current WEM status and real-time meter data",
        "description": "Returns Wi-Fi status, device identity, model, and meter data. WEM Datas rows normally use [voltage, current, activePower, importEnergy, exportEnergy, frequency, powerFactor].",
        "responses": {
          "200": {
            "description": "Current WEM monitor data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WemMonitor"
                },
                "example": {
                  "ssid": "wifi-name",
                  "sig": 100,
                  "mac": "B0F893000001",
                  "version": "i.91.xxx",
                  "server": "em",
                  "SN": "12345678",
                  "model": "WEM3080T",
                  "Datas": [
                    [
                      220,
                      9.99,
                      2198,
                      11.337,
                      11.201,
                      49.99,
                      1
                    ]
                  ]
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/monitorjson": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Get legacy meter data through the /api compatibility path",
        "description": "Alias of GET /monitorjson. New integrations should prefer GET /api/monitor.",
        "security": [],
        "responses": {
          "200": {
            "description": "Legacy monitor JSON response.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/monitorjson": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Get legacy real-time meter data",
        "description": "Legacy compatibility response. New integrations should prefer GET /api/monitor.",
        "security": [],
        "responses": {
          "200": {
            "description": "Legacy monitor JSON response.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/api/getbrand": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Get local Web UI branding",
        "responses": {
          "200": {
            "description": "Branding configuration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BrandSettings"
                },
                "example": {
                  "showIammeter": 1,
                  "brandText": "IAMMETER",
                  "apSsid": "FactoryAP",
                  "hasLogo": false
                }
              }
            }
          }
        },
        "security": [],
        "description": "Returns the current brand settings. Firmware i.91.065.23 and later reports hasLogo. When true, open /brand-logo on the same device to view the saved image."
      }
    },
    "/api/sntpstatus": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Get SNTP synchronization status",
        "responses": {
          "200": {
            "description": "SNTP status. Exact fields depend on firmware.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/info.xml": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Get UPnP-style XML device information",
        "responses": {
          "200": {
            "description": "XML device information",
            "content": {
              "application/xml": {
                "schema": {
                  "type": "string"
                }
              },
              "text/xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/admin/status": {
      "get": {
        "tags": [
          "Admin-Security-Public"
        ],
        "summary": "Get Admin Security and local-service status",
        "description": "Returns Admin Security, signed recovery, Modbus/TCP, and SSDP states.",
        "security": [],
        "responses": {
          "200": {
            "description": "Admin Security status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AdminStatus"
                },
                "example": {
                  "enabled": 1,
                  "hasPassword": 1,
                  "recoverySupported": 1,
                  "modbusTcpEnabled": 0,
                  "ssdpEnabled": 1
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/recovery_challenge": {
      "get": {
        "tags": [
          "Admin-Security-Public"
        ],
        "summary": "Generate a one-time administrator recovery payload",
        "description": "Every call generates a new RAM-only nonce and invalidates the previous payload. Device reboot also invalidates it.",
        "security": [],
        "responses": {
          "200": {
            "description": "One-time Ed25519 recovery challenge.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecoveryChallenge"
                },
                "example": {
                  "successful": 1,
                  "alg": "ed25519",
                  "payload": "reset_admin|DEVICE_SN|DEVICE_MAC|ONE_TIME_NONCE"
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/recovery": {
      "post": {
        "tags": [
          "Admin-Security-Public"
        ],
        "summary": "Disable Admin Security using a signed recovery payload",
        "description": "No Basic Auth is required, but the payload must match the current nonce and have a valid Ed25519 signature.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecoveryRequest"
              },
              "example": {
                "payload": "reset_admin|DEVICE_SN|DEVICE_MAC|ONE_TIME_NONCE",
                "signature": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          }
        }
      }
    },
    "/api/admin/check": {
      "get": {
        "tags": [
          "Admin-Security-Authenticated"
        ],
        "summary": "Validate administrator credentials",
        "description": "Returns successful=1 when the Basic Auth credentials are valid.",
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/admin/enable": {
      "post": {
        "tags": [
          "Admin-Security-Authenticated"
        ],
        "summary": "Enable or disable Admin Security and configure local services",
        "description": "Initial enablement works without credentials and requires username, password, and confirmPassword. Once enabled, valid Basic Auth is required. Service changes may reboot the device.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AdminEnableRequest"
              },
              "example": {
                "enable": 1,
                "username": "admin",
                "password": "ExamplePassword1",
                "confirmPassword": "ExamplePassword1",
                "modbusTcpEnabled": 0,
                "ssdpEnabled": 1
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/admin/password": {
      "post": {
        "tags": [
          "Admin-Security-Authenticated"
        ],
        "summary": "Change administrator credentials",
        "description": "Requires valid Basic Auth and current credentials in the JSON body. New passwords require 8-32 visible ASCII characters, including a letter and a digit.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AdminPasswordRequest"
              },
              "example": {
                "oldUsername": "admin",
                "oldPassword": "ExamplePassword1",
                "username": "admin",
                "password": "NewPassword2",
                "confirmPassword": "NewPassword2"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/wifidata": {
      "get": {
        "tags": [
          "WEM-Configuration-Authenticated"
        ],
        "summary": "Get Wi-Fi and network settings",
        "responses": {
          "200": {
            "description": "Wi-Fi and upload settings",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WifiData"
                },
                "example": {
                  "version": "i.91.xxx",
                  "SN": "12345678",
                  "mac": "B0F893000001",
                  "type": "PM",
                  "ssid": "wifi-name",
                  "ip": "192.168.1.100",
                  "netmask": "255.255.255.0",
                  "gw": "192.168.1.1",
                  "dns": "192.168.1.1",
                  "dhcp": 1,
                  "runMode": "mqtt",
                  "uploadAddress": "mqtt://example.com:1883",
                  "netmeter": 0,
                  "uploadinterval": 60
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/wifiaplist": {
      "get": {
        "tags": [
          "WEM-Configuration-Authenticated"
        ],
        "summary": "Scan nearby Wi-Fi networks",
        "responses": {
          "200": {
            "description": "Nearby Wi-Fi networks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WifiAp"
                  }
                },
                "example": [
                  {
                    "ssid": "example-wifi",
                    "signal": 88
                  }
                ]
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/getadv": {
      "get": {
        "tags": [
          "WEM-Configuration-Authenticated"
        ],
        "summary": "Get WEM advanced settings",
        "responses": {
          "200": {
            "description": "WEM advanced settings",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WemAdvancedSettings"
                },
                "example": {
                  "runMode": 3,
                  "runModeList": "IAMMETER-cloud,tcp,http,mqtt,stand alone",
                  "uploadAddress": "mqtts://mqtt.iammeter.com:8883",
                  "mqttUsername": "user",
                  "mqttPassword": "password",
                  "ntpServer": "pool.ntp.org",
                  "haDiscovery": 0,
                  "uploadInterval": 60,
                  "netmetering": 0,
                  "ctcRatio": 1,
                  "reactive": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/energyhistory": {
      "get": {
        "tags": [
          "WEM-Configuration-Authenticated"
        ],
        "summary": "Get local energy history",
        "responses": {
          "200": {
            "description": "Energy history. Exact structure depends on firmware.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/setbrand": {
      "post": {
        "tags": [
          "WEM-Configuration-Authenticated"
        ],
        "summary": "Set local Web UI branding",
        "description": "Set one or more brand fields. In firmware i.91.065.23 and later, logoBase64 installs a custom PNG, JPEG, or static WebP image. Use plain Base64 with no data URI prefix or line breaks. The maximum is 2048 Base64 characters (1536 decoded bytes), 2304 bytes for the entire JSON body, and 256 pixels per side. Omit logoBase64 to keep the saved logo. Set showIammeter to 0 to display the custom logo. Older firmware does not support logoBase64. Basic Auth is required when Admin Security is enabled.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BrandUpdate"
              },
              "examples": {
                "full": {
                  "summary": "Full update",
                  "description": "Updates all branding fields and replaces the saved image with a sample PNG. Replace logoBase64 with your own image before executing.",
                  "value": {
                    "showIammeter": 0,
                    "brandText": "Factory",
                    "apSsid": "FactoryAP",
                    "logoBase64": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAd0lEQVR42mNgoBAwInPEylb9J0bTq64wuD4mUjWjq2UiVTO6IUyUhgFJBrzsDCXegJedoXCMrBndECZibYIB8fLV+A1A1gxTjM9AJkKakW1Etx3DAGya8NmO1QvotmAzlORoxKUZbgBy2iYWwPQwYcsgpGQmigEAuEg1HAbQv7wAAAAASUVORK5CYII="
                  }
                },
                "brandingOnly": {
                  "summary": "Update text and AP prefix only",
                  "description": "Keeps the existing custom logo.",
                  "value": {
                    "showIammeter": 0,
                    "brandText": "Factory",
                    "apSsid": "FactoryAP"
                  }
                },
                "showIammeter": {
                  "summary": "Show IAMMETER branding",
                  "value": {
                    "showIammeter": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Brand update succeeded, or a legacy field was invalid. Check successful.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OkMessage"
                },
                "examples": {
                  "saved": {
                    "value": {
                      "successful": 1,
                      "message": "ok"
                    }
                  },
                  "invalidParameter": {
                    "value": {
                      "successful": 0,
                      "message": "invalid parameter"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or incomplete body.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BrandUpdateError"
                },
                "examples": {
                  "invalid_base64": {
                    "value": {
                      "successful": 0,
                      "message": "Logo Base64 is invalid.",
                      "code": "invalid_base64"
                    }
                  },
                  "invalid_logo_format": {
                    "value": {
                      "successful": 0,
                      "message": "Logo must be a valid PNG, JPEG, or static WebP image.",
                      "code": "invalid_logo_format"
                    }
                  },
                  "invalid_logo_dimensions": {
                    "value": {
                      "successful": 0,
                      "message": "Logo dimensions must be between 1 and 256 pixels per side.",
                      "code": "invalid_logo_dimensions"
                    }
                  },
                  "invalid_request": {
                    "value": {
                      "successful": 0,
                      "message": "One or more brand settings are invalid.",
                      "code": "invalid_request"
                    }
                  },
                  "incomplete_request": {
                    "value": {
                      "successful": 0,
                      "message": "The request body is incomplete.",
                      "code": "incomplete_request"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "413": {
            "description": "The request or Base64 field exceeds its limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BrandUpdateError"
                },
                "examples": {
                  "request_too_large": {
                    "value": {
                      "successful": 0,
                      "message": "Request body exceeds 2304 bytes.",
                      "code": "request_too_large"
                    }
                  },
                  "logo_too_large": {
                    "value": {
                      "successful": 0,
                      "message": "Logo Base64 exceeds 2048 characters.",
                      "code": "logo_too_large"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "description": "The logo could not be saved or failed readback verification.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BrandUpdateError"
                },
                "examples": {
                  "logo_write_failed": {
                    "value": {
                      "successful": 0,
                      "message": "Failed to save the logo.",
                      "code": "logo_write_failed"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "The device did not have enough memory.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BrandUpdateError"
                },
                "examples": {
                  "out_of_memory": {
                    "value": {
                      "successful": 0,
                      "message": "Insufficient memory to decode the logo.",
                      "code": "out_of_memory"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/setadv": {
      "post": {
        "tags": [
          "WEM-Configuration-Authenticated"
        ],
        "summary": "Set WEM advanced settings",
        "description": "Saves WEM advanced settings. Some changes require reboot; the firmware sends the JSON response first, saves configuration, waits briefly, and then reboots if needed.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WemAdvancedSettings"
              },
              "example": {
                "runMode": 3,
                "uploadAddress": "mqtts://mqtt.iammeter.com:8883",
                "uploadInterval": 60,
                "mqttUsername": "user",
                "mqttPassword": "pass",
                "haDiscovery": 0
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/setwifiadv": {
      "post": {
        "tags": [
          "WEM-Configuration-Authenticated"
        ],
        "summary": "Set Wi-Fi and IP settings",
        "description": "Saves Wi-Fi and IP settings. This endpoint saves configuration and reboots after responding.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WifiAdvancedSettings"
              },
              "examples": {
                "dhcp": {
                  "summary": "DHCP",
                  "value": {
                    "ssid": "my-wifi",
                    "pwd": "password",
                    "dhcp": true
                  }
                },
                "staticIp": {
                  "summary": "Static IP",
                  "value": {
                    "ssid": "my-wifi",
                    "pwd": "password",
                    "dhcp": false,
                    "ip": "192.168.1.80",
                    "netmask": "255.255.255.0",
                    "gw": "192.168.1.1",
                    "dns": "192.168.1.1"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/reactive": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set reactive-energy flag",
        "parameters": [
          {
            "name": "x",
            "in": "query",
            "required": false,
            "description": "0 disables reactive-energy mode, 1 enables it.",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current or updated reactive flag",
            "content": {
              "application/json": {
                "example": {
                  "reactive": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/mqttha": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set MQTT Home Assistant discovery flag",
        "parameters": [
          {
            "name": "x",
            "in": "query",
            "required": false,
            "description": "0 disables Home Assistant discovery, 1 enables it.",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current or updated MQTT Home Assistant flag",
            "content": {
              "application/json": {
                "example": {
                  "mqttHA": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/ratio": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set CT ratio",
        "description": "Used by WEM3046T-style models.",
        "parameters": [
          {
            "name": "x",
            "in": "query",
            "required": false,
            "description": "CT ratio value.",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 1000
          }
        ],
        "responses": {
          "200": {
            "description": "Current or updated CT ratio",
            "content": {
              "application/json": {
                "example": {
                  "CTratio": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/netmetering": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set net metering mode",
        "description": "Current firmware implements netmetering. Older external documentation may spell it as netmetring.",
        "parameters": [
          {
            "name": "nem",
            "in": "query",
            "required": false,
            "description": "0 disables net metering, 1 enables it.",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Current or updated net metering mode",
            "content": {
              "application/json": {
                "example": {
                  "NEM": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/ctcratio": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set CT-C ratio",
        "parameters": [
          {
            "name": "ctc",
            "in": "query",
            "required": false,
            "description": "CT-C ratio value.",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 1
          }
        ],
        "responses": {
          "200": {
            "description": "Current or updated CT-C ratio",
            "content": {
              "application/json": {
                "example": {
                  "ctcratio": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/uploadinterval": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set upload interval",
        "parameters": [
          {
            "name": "x",
            "in": "query",
            "required": false,
            "description": "Upload interval in seconds.",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 60
          }
        ],
        "responses": {
          "200": {
            "description": "Current or updated upload interval",
            "content": {
              "application/json": {
                "example": {
                  "uploadinterval": 60
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/mqtt": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set MQTT username and password",
        "description": "Without query parameters, returns MQTT username and password length. With user and pwd, sets MQTT credentials. Prefer POST /api/setadv for new integrations.",
        "parameters": [
          {
            "name": "user",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "user"
          },
          {
            "name": "pwd",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "password"
          }
        ],
        "responses": {
          "200": {
            "description": "MQTT credential status",
            "content": {
              "application/json": {
                "example": {
                  "username": "user",
                  "pwdlength": 6
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/basicauth": {
      "get": {
        "tags": [
          "WEM-Legacy-Authenticated"
        ],
        "summary": "Get or set Basic Auth string",
        "parameters": [
          {
            "name": "authstring",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "xxxx"
          }
        ],
        "responses": {
          "200": {
            "description": "Basic Auth status",
            "content": {
              "application/json": {
                "example": {
                  "authstring": "xxxx",
                  "pwdlength": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/tls/ca/status": {
      "get": {
        "tags": [
          "TLS-CA-Authenticated"
        ],
        "summary": "Get outbound TLS certificate-verification status",
        "description": "Returns the shared MQTTS/HTTPS verification mode and custom Root CA metadata. Admin Security must be enabled.",
        "responses": {
          "200": {
            "description": "TLS CA status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TlsCaStatus"
                },
                "example": {
                  "successful": 1,
                  "mode": "builtin",
                  "customCaValid": 0,
                  "customCaLength": 0,
                  "customCaSha256": "",
                  "restartRequiredAfterChange": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/tls/ca/upload": {
      "post": {
        "tags": [
          "TLS-CA-Authenticated"
        ],
        "summary": "Upload a custom PEM Root CA",
        "description": "Uploads a raw PEM certificate for outbound MQTTS/HTTPS verification. Maximum size is 3072 bytes. Uploading does not select custom mode.",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-pem-file": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/tls/ca/select": {
      "post": {
        "tags": [
          "TLS-CA-Authenticated"
        ],
        "summary": "Select outbound TLS verification mode",
        "description": "Selects builtin, custom, or none. Custom requires an uploaded valid CA. None disables certificate and hostname verification.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TlsModeRequest"
              },
              "example": {
                "mode": "builtin"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/tls/ca/delete": {
      "post": {
        "tags": [
          "TLS-CA-Authenticated"
        ],
        "summary": "Delete the custom Root CA",
        "description": "Deletes the custom CA and restores builtin verification mode.",
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/restart": {
      "get": {
        "tags": [
          "Maintenance-Authenticated"
        ],
        "summary": "Restart device or reset Wi-Fi/settings",
        "description": "Without query parameters, reboots the device. With reset=true, factory-resets user Wi-Fi/settings except the serial number, then persists the change.",
        "parameters": [
          {
            "name": "reset",
            "in": "query",
            "required": false,
            "description": "Set to true to factory-reset user Wi-Fi/settings except the serial number.",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Restart or reset response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/ssid": {
      "get": {
        "tags": [
          "Maintenance-Authenticated"
        ],
        "summary": "Legacy AP SSID setter",
        "description": "Stores the factory AP SSID and reboots. Prefer POST /api/setbrand with apSsid for new integrations.",
        "parameters": [
          {
            "name": "value",
            "in": "query",
            "required": true,
            "description": "Factory AP SSID.",
            "schema": {
              "type": "string",
              "maxLength": 18
            },
            "example": "FactoryAP"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/OkMessage"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "OkMessage": {
        "description": "Successful setter response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OkMessage"
            },
            "example": {
              "successful": 1,
              "message": "ok"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Administrator authentication is required or the supplied credentials are invalid.",
        "headers": {
          "WWW-Authenticate": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OkMessage"
            },
            "example": {
              "successful": 0,
              "message": "Unauthorized"
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Too many failed authentication attempts. Wait for Retry-After.",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OkMessage"
            },
            "example": {
              "successful": 0,
              "message": "Too many authentication failures. Try again later."
            }
          }
        }
      }
    },
    "schemas": {
      "OkMessage": {
        "type": "object",
        "properties": {
          "successful": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "WemMonitor": {
        "type": "object",
        "properties": {
          "ssid": {
            "type": "string"
          },
          "sig": {
            "type": "integer"
          },
          "mac": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "server": {
            "type": "string"
          },
          "SN": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "Datas": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "number",
                "nullable": true
              }
            }
          }
        },
        "additionalProperties": true
      },
      "WifiData": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string"
          },
          "SN": {
            "type": "string"
          },
          "mac": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "ssid": {
            "type": "string"
          },
          "ip": {
            "type": "string"
          },
          "netmask": {
            "type": "string"
          },
          "gw": {
            "type": "string"
          },
          "dns": {
            "type": "string"
          },
          "dhcp": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "runMode": {
            "type": "string"
          },
          "uploadAddress": {
            "type": "string"
          },
          "netmeter": {
            "type": "integer"
          },
          "uploadinterval": {
            "type": "integer"
          }
        },
        "additionalProperties": true
      },
      "WifiAp": {
        "type": "object",
        "properties": {
          "ssid": {
            "type": "string"
          },
          "signal": {
            "type": "integer"
          }
        }
      },
      "BrandSettings": {
        "type": "object",
        "properties": {
          "showIammeter": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "1 shows IAMMETER branding, 0 hides it."
          },
          "brandText": {
            "type": "string",
            "maxLength": 20
          },
          "apSsid": {
            "type": "string",
            "maxLength": 19
          },
          "hasLogo": {
            "type": "boolean",
            "description": "True when a valid custom logo is stored. This field is present on firmware i.91.065.23 and later."
          }
        },
        "additionalProperties": false
      },
      "WifiAdvancedSettings": {
        "type": "object",
        "properties": {
          "ssid": {
            "type": "string"
          },
          "pwd": {
            "type": "string"
          },
          "dhcp": {
            "type": "boolean"
          },
          "ip": {
            "type": "string"
          },
          "netmask": {
            "type": "string"
          },
          "gw": {
            "type": "string"
          },
          "dns": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "WemAdvancedSettings": {
        "type": "object",
        "properties": {
          "runMode": {
            "type": "integer",
            "description": "0 cloud, 1 TCP, 2 HTTP, 3 MQTT, 4 standalone.",
            "enum": [
              0,
              1,
              2,
              3,
              4
            ]
          },
          "runModeList": {
            "type": "string",
            "readOnly": true
          },
          "uploadAddress": {
            "type": "string"
          },
          "mqttUsername": {
            "type": "string"
          },
          "mqttPassword": {
            "type": "string"
          },
          "ntpServer": {
            "type": "string"
          },
          "haDiscovery": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "uploadInterval": {
            "type": "integer",
            "minimum": 1
          },
          "netmetering": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "ctcRatio": {
            "type": "integer",
            "minimum": 1
          },
          "reactive": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          }
        },
        "additionalProperties": false
      },
      "AdminStatus": {
        "type": "object",
        "properties": {
          "enabled": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "hasPassword": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "recoverySupported": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "modbusTcpEnabled": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "ssdpEnabled": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          }
        },
        "additionalProperties": false
      },
      "RecoveryChallenge": {
        "type": "object",
        "properties": {
          "successful": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "alg": {
            "type": "string",
            "enum": [
              "ed25519"
            ]
          },
          "payload": {
            "type": "string",
            "example": "reset_admin|DEVICE_SN|DEVICE_MAC|ONE_TIME_NONCE"
          },
          "message": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "RecoveryRequest": {
        "type": "object",
        "required": [
          "payload",
          "signature"
        ],
        "properties": {
          "payload": {
            "type": "string",
            "example": "reset_admin|DEVICE_SN|DEVICE_MAC|ONE_TIME_NONCE"
          },
          "signature": {
            "type": "string",
            "minLength": 128,
            "maxLength": 128,
            "pattern": "^[0-9a-fA-F]{128}$"
          }
        },
        "additionalProperties": false
      },
      "AdminEnableRequest": {
        "type": "object",
        "required": [
          "enable"
        ],
        "properties": {
          "enable": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "username": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "password": {
            "type": "string",
            "format": "password",
            "minLength": 8,
            "maxLength": 32
          },
          "confirmPassword": {
            "type": "string",
            "format": "password",
            "minLength": 8,
            "maxLength": 32
          },
          "modbusTcpEnabled": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "ssdpEnabled": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          }
        },
        "additionalProperties": false
      },
      "AdminPasswordRequest": {
        "type": "object",
        "required": [
          "oldUsername",
          "oldPassword",
          "username",
          "password",
          "confirmPassword"
        ],
        "properties": {
          "oldUsername": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "oldPassword": {
            "type": "string",
            "format": "password",
            "minLength": 1,
            "maxLength": 32
          },
          "username": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "password": {
            "type": "string",
            "format": "password",
            "minLength": 8,
            "maxLength": 32
          },
          "confirmPassword": {
            "type": "string",
            "format": "password",
            "minLength": 8,
            "maxLength": 32
          }
        },
        "additionalProperties": false
      },
      "TlsCaStatus": {
        "type": "object",
        "properties": {
          "successful": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "mode": {
            "type": "string",
            "enum": [
              "builtin",
              "custom",
              "none"
            ]
          },
          "customCaValid": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "customCaLength": {
            "type": "integer"
          },
          "customCaSha256": {
            "type": "string"
          },
          "restartRequiredAfterChange": {
            "type": "integer",
            "enum": [
              0,
              1
            ]
          },
          "message": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "TlsModeRequest": {
        "type": "object",
        "required": [
          "mode"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "builtin",
              "custom",
              "none"
            ]
          }
        },
        "additionalProperties": false
      },
      "BrandUpdate": {
        "type": "object",
        "minProperties": 1,
        "properties": {
          "showIammeter": {
            "type": "integer",
            "enum": [
              0,
              1
            ],
            "description": "1 shows IAMMETER branding, 0 hides it."
          },
          "brandText": {
            "type": "string",
            "maxLength": 20,
            "minLength": 1,
            "description": "Printable ASCII. Double quotes and backslashes are not allowed."
          },
          "apSsid": {
            "type": "string",
            "maxLength": 19,
            "minLength": 1,
            "description": "Printable ASCII. Double quotes and backslashes are not allowed."
          },
          "logoBase64": {
            "type": "string",
            "format": "byte",
            "minLength": 4,
            "maxLength": 2048,
            "description": "Optional Base64 for a static PNG, JPEG, or WebP image without a data URI prefix. Omit to keep the saved logo."
          }
        },
        "additionalProperties": false
      },
      "BrandUpdateError": {
        "type": "object",
        "required": [
          "successful",
          "code",
          "message"
        ],
        "properties": {
          "successful": {
            "type": "integer",
            "enum": [
              0
            ]
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "securitySchemes": {
      "basicAuth": {
        "type": "http",
        "scheme": "basic",
        "description": "Administrator username and password configured in the device Security tab."
      }
    }
  },
  "security": [
    {
      "basicAuth": []
    }
  ]
}
