ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP102.cpp
Go to the documentation of this file.
1 /*
2  ESP102.cpp - ESP3D command class
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 (WIFI_FEATURE) || defined (ETH_FEATURE)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/network/netconfig.h"
26 #if defined (WIFI_FEATURE)
27 #include "../../modules/wifi/wificonfig.h"
28 #endif //WIFI_FEATURE
29 #if defined (ETH_FEATURE)
30 #include "../../modules/ethernet/ethconfig.h"
31 #endif //ETH_FEATURE
32 #include "../../modules/authentication/authentication_service.h"
33 //Change STA IP mode (DHCP/STATIC)
34 //[ESP102]<mode>pwd=<admin password>
35 bool Commands::ESP102(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
36 {
37  bool response = true;
38  String parameter;
39 #ifdef AUTHENTICATION_FEATURE
40  if (auth_type == LEVEL_GUEST) {
41  output->printERROR("Wrong authentication!", 401);
42  return false;
43  }
44 #else
45  (void)auth_type;
46 #endif //AUTHENTICATION_FEATURE
47  parameter = get_param (cmd_params, "");
48  //get
49  if (parameter.length() == 0) {
51  if (resp == DHCP_MODE) {
52  output->printMSG("DHCP");
53  } else if (resp == STATIC_IP_MODE) {
54  output->printMSG("STATIC");
55  } else {
56  output->printMSG("???");
57  }
58  } else { //set
59 #ifdef AUTHENTICATION_FEATURE
60  if (auth_type != LEVEL_ADMIN) {
61  output->printERROR("Wrong authentication!", 401);
62  return false;
63  }
64 #endif //AUTHENTICATION_FEATURE
65  parameter.toUpperCase();
66  if (!((parameter == "STATIC") || (parameter == "DHCP"))) {
67  output->printERROR ("only STATIC or DHCP mode supported!");
68  return false;
69  } else {
70  uint8_t bbuf = (parameter == "DHCP")?DHCP_MODE:STATIC_IP_MODE;
72  output->printERROR ("Set failed!");
73  response = false;
74  } else {
75  output->printMSG ("ok");
76  }
77  }
78  }
79  return response;
80 }
81 
82 #endif //WIFI_FEATURE || ETH_FEATURE
Settings_ESP3D::write_byte
static bool write_byte(int pos, const uint8_t value)
Definition: settings_esp3d.cpp:749
DHCP_MODE
#define DHCP_MODE
Definition: netconfig.h:36
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
STATIC_IP_MODE
#define STATIC_IP_MODE
Definition: netconfig.h:37
ESP_STA_IP_MODE
#define ESP_STA_IP_MODE
Definition: settings_esp3d.h:42
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
Commands::ESP102
bool ESP102(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP102.cpp:35
ESP3DOutput::printMSG
size_t printMSG(const char *s, bool withNL=true)
Definition: esp3doutput.cpp:190
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
Settings_ESP3D::read_byte
static uint8_t read_byte(int pos, bool *haserror=NULL)
Definition: settings_esp3d.cpp:715
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition: authentication_service.h:28
ESP3DOutput
Definition: esp3doutput.h:48