ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP110.cpp
Go to the documentation of this file.
1 /*
2  ESP110.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( BLUETOOTH_FEATURE) || defined (ETH_FEATURE)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/network/netconfig.h"
26 #include "../../modules/authentication/authentication_service.h"
27 //Set radio state at boot which can be BT, WIFI-STA, WIFI-AP, ETH-STA, OFF
28 //[ESP110]<state>pwd=<admin password>
29 bool Commands::ESP110(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
30 {
31  bool response = true;
32  String parameter;
33 #ifdef AUTHENTICATION_FEATURE
34  if (auth_type == LEVEL_GUEST) {
35  output->printERROR("Wrong authentication!", 401);
36  return false;
37  }
38 #else
39  (void)auth_type;
40 #endif //AUTHENTICATION_FEATURE
41  parameter = get_param (cmd_params, "");
42  //get
43  if (parameter.length() == 0) {
44  int8_t wifiMode = Settings_ESP3D::read_byte(ESP_RADIO_MODE);
45  if (wifiMode == ESP_RADIO_OFF) {
46  output->printMSG("OFF");
47  } else if (wifiMode == ESP_BT) {
48  output->printMSG("BT");
49  } else if (wifiMode == ESP_WIFI_AP) {
50  output->printMSG("WIFI-AP");
51  } else if (wifiMode == ESP_WIFI_STA) {
52  output->printMSG("WIFI-STA");
53 // } else if (wifiMode == ESP_ETH_SRV) {
54 // output->printMSG("ETH-SRV");
55  } else if (wifiMode == ESP_ETH_STA) {
56  output->printMSG("WIFI-STA");
57  } else {
58  output->printMSG("??");
59  }
60  } else { //set
61 #ifdef AUTHENTICATION_FEATURE
62  if (auth_type != LEVEL_ADMIN) {
63  output->printERROR("Wrong authentication!", 401);
64  return false;
65  }
66 #endif //AUTHENTICATION_FEATURE
67  parameter.toUpperCase();
68  if (!(
69 #if defined( BLUETOOTH_FEATURE)
70  (parameter == "BT") ||
71 #endif //BLUETOOTH_FEATURE
72 #if defined( WIFI_FEATURE)
73  (parameter == "WIFI-STA") || (parameter == "WIFI-AP") ||
74 #endif //WIFI_FEATURE
75 #if defined( ETH_FEATURE)
76  (parameter == "ETH-STA") || //(parameter == "ETH-SRV") ||
77 #endif //ETH_FEATURE
78  (parameter == "OFF"))) {
79 
80  output->printERROR ("Only "
81 #ifdef BLUETOOTH_FEATURE
82  "BT or "
83 #endif //BLUETOOTH_FEATURE
84 #ifdef WIFI_FEATURE
85  "WIFI-STA or WIFI-AP or "
86 #endif //WIFI_FEATURE
87 #ifdef ETH_FEATURE
88  "ETH-STA or ETH-SRV or "
89 #endif //ETH_FEATURE
90  "OFF mode supported!");
91  return false;
92  }
93 
94  int8_t bbuf = ESP_RADIO_OFF;
95 #ifdef WIFI_FEATURE
96  if(parameter == "WIFI-STA") {
97  bbuf = ESP_WIFI_STA;
98  }
99  if(parameter == "WIFI-AP") {
100  bbuf = ESP_WIFI_AP;
101  }
102 #endif //WIFI_FEATURE
103 #ifdef ETH_FEATURE
104  if(parameter == "ETH-STA") {
105  bbuf = ESP_ETH_STA;
106  }
107 // if(parameter == "ETH-SRV") {
108 // bbuf = ESP_ETH_SRV;
109 // }
110 #endif //ETH_FEATURE
111 #ifdef BLUETOOTH_FEATURE
112  if(parameter == "BT") {
113  bbuf = ESP_BT;
114  }
115 #endif //BLUETOOTH_FEATURE
117  output->printERROR ("Set failed!");
118  response = false;
119  } else {
120  if (!NetConfig::begin()) {
121  output->printERROR ("Cannot setup network");
122  response = false;
123  }
124  }
125  }
126  return response;
127 }
128 
129 #endif //WIFI_FEATURE
Settings_ESP3D::write_byte
static bool write_byte(int pos, const uint8_t value)
Definition: settings_esp3d.cpp:749
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
ESP_WIFI_STA
#define ESP_WIFI_STA
Definition: netconfig.h:41
WIFI_FEATURE
#define WIFI_FEATURE
Definition: configuration.h:31
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
NetConfig::begin
static bool begin()
Definition: netconfig.cpp:215
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP3DOutput::printMSG
size_t printMSG(const char *s, bool withNL=true)
Definition: esp3doutput.cpp:190
Commands::ESP110
bool ESP110(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP110.cpp:29
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
ESP_BT
#define ESP_BT
Definition: netconfig.h:43
ESP_RADIO_OFF
#define ESP_RADIO_OFF
Definition: netconfig.h:40
ESP_ETH_STA
#define ESP_ETH_STA
Definition: netconfig.h:44
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
ESP_WIFI_AP
#define ESP_WIFI_AP
Definition: netconfig.h:42
ESP3DOutput
Definition: esp3doutput.h:48
ESP_RADIO_MODE
#define ESP_RADIO_MODE
Definition: settings_esp3d.h:39