ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
handle-updatefw.cpp
Go to the documentation of this file.
1 /*
2  handle-updatefw.cpp - ESP3D http handle
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include "../../../include/esp3d_config.h"
21 #if defined (HTTP_FEATURE) && defined(WEB_UPDATE_FEATURE)
22 #include "../http_server.h"
23 #if defined (ARDUINO_ARCH_ESP32)
24 #include <WebServer.h>
25 #endif //ARDUINO_ARCH_ESP32
26 #if defined (ARDUINO_ARCH_ESP8266)
27 #include <ESP8266WebServer.h>
28 #endif //ARDUINO_ARCH_ESP8266
29 #include "../../../core/esp3d.h"
30 #include "../../authentication/authentication_service.h"
31 //Web Update handler
32 void HTTP_Server::handleUpdate ()
33 {
35  if (auth_level != LEVEL_ADMIN) {
36  _upload_status = UPLOAD_STATUS_NONE;
37  _webserver->send (401, "text/plain", "Wrong authentication!");
38  return;
39  }
40  String jsonfile = "{\"status\":\"" ;
41  jsonfile += String(_upload_status);
42  jsonfile += "\"}";
43  _webserver->sendHeader("Cache-Control", "no-cache");
44  _webserver->send(200, "application/json", jsonfile);
45  //if success restart
46  if (_upload_status == UPLOAD_STATUS_SUCCESSFUL) {
47  Hal::wait(1000);
49  } else {
50  _upload_status = UPLOAD_STATUS_NONE;
51  }
52 }
53 
54 #endif //HTTP_FEATURE && WEB_UPDATE_FEATURE
Hal::wait
static void wait(uint32_t milliseconds)
Definition: hal.cpp:226
AuthenticationService::authenticated_level
static level_authenticate_type authenticated_level(const char *pwd=nullptr)
Definition: authentication_service.cpp:61
Esp3D::restart_esp
static void restart_esp(bool need_restart=true)
Definition: esp3d.cpp:169
UPLOAD_STATUS_NONE
@ UPLOAD_STATUS_NONE
Definition: http_server.h:38
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
UPLOAD_STATUS_SUCCESSFUL
@ UPLOAD_STATUS_SUCCESSFUL
Definition: http_server.h:41