ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP410.cpp
Go to the documentation of this file.
1 /*
2  ESP410.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)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/wifi/wificonfig.h"
26 #include "../../modules/authentication/authentication_service.h"
27 //Get available AP list (limited to 30)
28 //output is JSON or plain text according parameter
29 //[ESP410]<plain>
30 bool Commands::ESP410(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
31 {
32  bool response = true;
33  String parameter;
34 #ifdef AUTHENTICATION_FEATURE
35  if (auth_type == LEVEL_GUEST) {
36  output->printERROR("Wrong authentication!", 401);
37  return false;
38  }
39 #else
40  (void)auth_type;
41 #endif //AUTHENTICATION_FEATURE
42  //Backup current mode
43  uint8_t currentmode = WiFi.getMode();
44  bool plain = hastag(cmd_params,"plain");
45  int n = 0;
46  if (plain) {
47  output->printLN ("Start Scan");
48  output->flush();
49  }
50  n = WiFi.scanNetworks ();
51  if (!plain) {
52  output->print ("{\"AP_LIST\":[");
53  }
54  for (int i = 0; i < n; ++i) {
55  if (i > 0) {
56  if (!plain) {
57  output->print (",");
58  } else {
59  output->printLN ("");
60  }
61  }
62  if (!plain) {
63  output->print ("{\"SSID\":\"");
64  }
65  output->print (WiFi.SSID (i).c_str());
66  if (!plain) {
67  output->print ("\",\"SIGNAL\":\"");
68  } else {
69  output->print ("\t");
70  }
71  output->print (String(WiFiConfig::getSignal (WiFi.RSSI (i) )));
72  if (plain) {
73  output->print("%");
74  }
75  if (!plain) {
76  output->print ("\",\"IS_PROTECTED\":\"");
77  }
78  if (WiFi.encryptionType (i) == ENC_TYPE_NONE) {
79  if (!plain) {
80  output->print ("0");
81  } else {
82  output->print ("\tOpen");
83  }
84  } else {
85  if (!plain) {
86  output->print ("1");
87  } else {
88  output->print ("\tSecure");
89  }
90  }
91  if (!plain) {
92  output->print ("\"}");
93  }
94  }
95  WiFi.scanDelete();
96  if (!plain) {
97  output->printLN ("]}");
98  } else {
99  output->printLN ("");
100  output->printLN ("End Scan");
101  }
102  WiFi.mode((WiFiMode_t)currentmode);
103  return response;
104 }
105 
106 #endif //WIFI_FEATURE
ESP3DOutput::printLN
size_t printLN(const char *s)
Definition: esp3doutput.cpp:165
Commands::ESP410
bool ESP410(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP410.cpp:30
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
WiFiConfig::getSignal
static int32_t getSignal(int32_t RSSI)
Definition: wificonfig.cpp:107
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
Commands::hastag
bool hastag(const char *cmd_params, const char *tag)
Definition: commands.cpp:221
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
ESP3DOutput::flush
void flush()
Definition: esp3doutput.cpp:128
ESP3DOutput
Definition: esp3doutput.h:48