瀏覽代碼

add system endpoint, allowing forced restart

Chris Mullins 8 年之前
父節點
當前提交
b0d07465d1
共有 2 個文件被更改,包括 14 次插入0 次删除
  1. 13 0
      lib/WebServer/MiLightHttpServer.cpp
  2. 1 0
      lib/WebServer/MiLightHttpServer.h

+ 13 - 0
lib/WebServer/MiLightHttpServer.cpp

@@ -20,6 +20,7 @@ void MiLightHttpServer::begin() {
   server.onPattern("/download_update/:component", HTTP_GET, [this](const UrlTokenBindings* b) { handleDownloadUpdate(b); });
   server.on("/web", HTTP_POST, [this]() { server.send(200, "text/plain", "success"); }, handleUpdateFile(WEB_INDEX_FILENAME));
   server.on("/about", HTTP_GET, [this]() { handleAbout(); });
+  server.on("/system", HTTP_POST, [this]() { handleSystemPost(); });
   server.on("/firmware", HTTP_POST, 
     [this](){
       server.sendHeader("Connection", "close");
@@ -56,6 +57,18 @@ void MiLightHttpServer::handleClient() {
   server.handleClient();
 }
 
+void MiLightHttpServer::handleSystemPost() {
+  DynamicJsonBuffer buffer;
+  JsonObject& request = buffer.parse(server.arg("plain"));
+  
+  if (request.containsKey("command")) {
+    if (request["command"] == "restart") {
+      Serial.println("Restarting...");
+      ESP.restart();
+    }
+  }
+}
+
 void MiLightHttpServer::handleDownloadUpdate(const UrlTokenBindings* bindings) {
   GithubDownloader* downloader = new GithubDownloader();
   const String& component = bindings->get("component");

+ 1 - 0
lib/WebServer/MiLightHttpServer.h

@@ -39,6 +39,7 @@ protected:
   void handleUpdateSettings();
   void handleGetRadioConfigs();
   void handleAbout();
+  void handleSystemPost();
   void handleListenGateway(const UrlTokenBindings* urlBindings);
   void handleSendRaw(const UrlTokenBindings* urlBindings);
   void handleUpdateGroup(const UrlTokenBindings* urlBindings);