ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP800.cpp
Go to the documentation of this file.
1 /*
2  ESP800.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 #include "../commands.h"
22 #include "../esp3doutput.h"
23 #include "../settings_esp3d.h"
24 #include "../../modules/network/netconfig.h"
25 #include "../../modules/authentication/authentication_service.h"
26 #ifdef FILESYSTEM_FEATURE
27 #include "../../modules/filesystem/esp_filesystem.h"
28 #endif //FILESYSTEM_FEATURE
29 #if defined (WIFI_FEATURE) || defined(ETH_FEATURE) ||defined(BLUETOOTH_FEATURE)
30 #include "../../modules/network/netconfig.h"
31 #if defined (WIFI_FEATURE)
32 #include "../../modules/wifi/wificonfig.h"
33 #endif //WIFI_FEATURE
34 #endif //WIFI_FEATURE || ETH_FEATURE || BLUETOOTH_FEATURE
35 #ifdef HTTP_FEATURE
36 #include "../../modules/http/http_server.h"
37 #endif //HTTP_FEATURE
38 #ifdef TIMESTAMP_FEATURE
39 #include "../../modules/time/time_server.h"
40 #endif //TIMESTAMP_FEATURE
41 #ifdef CAMERA_DEVICE
42 #include "../../modules/camera/camera.h"
43 #endif //CAMERA_DEVICE
44 //get fw version firmare target and fw version
45 //eventually set time with pc time
46 //output is JSON or plain text according parameter
47 //[ESP800]<plain><time=YYYY-MM-DD-HH-MM-SS>
48 bool Commands::ESP800(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
49 {
50  bool response = true;
51  String parameter;
52 #ifdef AUTHENTICATION_FEATURE
53  if (auth_type == LEVEL_GUEST) {
54  output->printERROR("Wrong authentication!", 401);
55  return false;
56  }
57 #else
58  (void)auth_type;
59 #endif //AUTHENTICATION_FEATURE
60  bool plain = hastag(cmd_params,"plain");
61 #ifdef TIMESTAMP_FEATURE
62  String newtime = get_param (cmd_params, "time=");
63  String tparm = (timeserver.is_internet_time())?"Auto":"Manual";
64  if (!timeserver.is_internet_time() && (newtime.length() > 0)) {
65  if (!timeserver.setTime(newtime.c_str())) {
66  tparm="Failed to set";
67  }
68  } else {
69  if (!timeserver.is_internet_time() && (newtime.length() == 0)) {
70  tparm="Not set";
71  }
72  }
73 #endif //TIMESTAMP_FEATURE
74  //FW version
75  if (plain) {
76  output->print("FW version:");
77  } else {
78  output->print("{\"FWVersion\":\"");
79  }
80  output->print(FW_VERSION);
81  if(plain) {
82  output->printLN("");
83  } else {
84  output->print("\"");
85  }
86 
87  //FW target
88  if (plain) {
89  output->print("FW target:");
90  } else {
91  output->print(",\"FWTarget\":\"");
92  }
94  if(plain) {
95  output->printLN("");
96  } else {
97  output->print("\"");
98  }
99  //SD connection
100  if (plain) {
101  output->print("SD connection:");
102  } else {
103  output->print(",\"SDConnection\":\"");
104  }
106  output->print("direct");
107  } else if (Settings_ESP3D::GetSDDevice() == ESP_SHARED_SD) {
108  output->print("shared");
109  } else {
110  output->print("None");
111  }
112  if(plain) {
113  output->printLN("");
114  } else {
115  output->print("\"");
116  }
117  //Authentication
118  if (plain) {
119  output->print("Authentication:");
120  } else {
121  output->print(",\"Authentication\":\"");
122  }
123 #ifdef AUTHENTICATION_FEATURE
124  output->print("Enabled");
125 #else
126  output->print("Disabled");
127 #endif //AUTHENTICATION_FEATURE
128  if(plain) {
129  output->printLN("");
130  } else {
131  output->print("\"");
132  }
133 #if (defined(WIFI_FEATURE) || defined(ETH_FEATURE)) && defined(HTTP_FEATURE)
134  //Web Communication
135  if (plain) {
136  output->print("Web Communication:");
137  } else {
138  output->print(",\"WebCommunication\":\"");
139  }
140 #if defined (ASYNCWEBSERVER_FEATURE)
141  output->print("Asynchronous");
142 #else
143  output->print("Synchronous");
144 #endif //ASYNCWEBSERVER_FEATURE
145  if(plain) {
146  output->printLN("");
147  } else {
148  output->print("\"");
149  }
150  //WebSocket IP
151  if (plain) {
152  output->print("Web Socket IP:");
153  } else {
154  output->print(",\"WebSocketIP\":\"");
155  }
156  output->print(NetConfig::localIP().c_str());
157  if(plain) {
158  output->printLN("");
159  } else {
160  output->print("\"");
161  }
162  //WebSocket Port
163  if (plain) {
164  output->print("Web Socket port:");
165  } else {
166  output->print(",\"WebSocketport\":\"");
167  }
168 #if defined (ASYNCWEBSERVER_FEATURE)
169  output->print(HTTP_Server::port());
170 #else
171  output->print(HTTP_Server::port() +1);
172 #endif
173  if(plain) {
174  output->printLN("");
175  } else {
176  output->print("\"");
177  }
178 
179 #endif // (WIFI_FEATURE) || ETH_FEATURE) && HTTP_FEATURE)
180 #if defined(WIFI_FEATURE) || defined(ETH_FEATURE) || defined(BT_FEATURE)
181  //Hostname
182  if (plain) {
183  output->print("Hostname:");
184  } else {
185  output->print(",\"Hostname\":\"");
186  }
187  output->print(NetConfig::hostname());
188  if(plain) {
189  output->printLN("");
190  } else {
191  output->print("\"");
192  }
193 #endif //WIFI_FEATURE|| ETH_FEATURE || BT_FEATURE
194 #if defined(WIFI_FEATURE)
195  if (WiFiConfig::started()) {
196  //WiFi mode
197  if (plain) {
198  output->print("WiFi mode:");
199  } else {
200  output->print(",\"WiFiMode\":\"");
201  }
202  output->print((WiFi.getMode() == WIFI_AP)?"AP":"STA");
203  if(plain) {
204  output->printLN("");
205  } else {
206  output->print("\"");
207  }
208  }
209 #endif //WIFI_FEATURE
210 #if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
211  //Update
212  if (plain) {
213  output->print("Web Update:");
214  } else {
215  output->print(",\"WebUpdate\":\"");
216  }
217 #ifdef WEB_UPDATE_FEATURE
218  output->print("Enabled");
219 #else
220  output->print("Disabled");
221 #endif //WEB_UPDATE_FEATURE
222  if(plain) {
223  output->printLN("");
224  } else {
225  output->print("\"");
226  }
227 #endif //WIFI_FEATURE|| ETH_FEATURE
228 
229 //Hostname
230  if (plain) {
231  output->print("Filesystem:");
232  } else {
233  output->print(",\"Filesystem\":\"");
234  }
235 #if defined(FILESYSTEM_FEATURE)
236  output->print(ESP_FileSystem::FilesystemName());
237 #else
238  output->print("None");
239 #endif //FILESYSTEM_FEATURE
240  if(plain) {
241  output->printLN("");
242  } else {
243  output->print("\"");
244  }
245 //time server
246  if (plain) {
247  output->print("Time:");
248  } else {
249  output->print(",\"Time\":\"");
250  }
251 #ifdef TIMESTAMP_FEATURE
252  output->print(tparm.c_str());
253 #else
254  output->print("None");
255 #endif //TIMESTAMP_FEATURE
256  if(plain) {
257  output->printLN("");
258  } else {
259  output->print("\"");
260  }
261 #ifdef CAMERA_DEVICE
262  //camera port
263  if (plain) {
264  output->print("Camera port:");
265  } else {
266  output->print(",\"Cam_port\":\"");
267  }
268  output->print(esp3d_camera.port());
269  if(plain) {
270  output->printLN("");
271  } else {
272  output->print("\"");
273  }
274  //camera ID
275  if (plain) {
276  output->print("Camera ID:");
277  } else {
278  output->print(",\"Cam_ID\":\"");
279  }
280  output->print(esp3d_camera.GetModel());
281  if(plain) {
282  output->printLN("");
283  } else {
284  output->print("\"");
285  }
286  //camera Name
287  if (plain) {
288  output->print("Camera Name:");
289  } else {
290  output->print(",\"Cam_name\":\"");
291  }
292  output->print(esp3d_camera.GetModelString());
293  if(plain) {
294  output->printLN("");
295  } else {
296  output->print("\"");
297  }
298 #endif //CAMERA_DEVICE
299  //final
300  if(!plain) {
301  output->printLN("}");
302  }
303  return response;
304 }
305 
ESP_FileSystem::FilesystemName
static const char * FilesystemName()
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
ESP_SHARED_SD
#define ESP_SHARED_SD
Definition: defines.h:56
ESP3DOutput::printLN
size_t printLN(const char *s)
Definition: esp3doutput.cpp:165
Camera::GetModel
uint8_t GetModel()
Commands::ESP800
bool ESP800(const char *cmd_params, level_authenticate_type auth_level, ESP3DOutput *output)
Definition: ESP800.cpp:48
Settings_ESP3D::GetSDDevice
static uint8_t GetSDDevice(bool fromsettings=false)
Definition: settings_esp3d.cpp:191
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
NetConfig::hostname
static const char * hostname(bool fromsettings=false)
Definition: netconfig.cpp:331
timeserver
TimeServer timeserver
TimeServer::setTime
bool setTime(const char *stime)
FW_VERSION
#define FW_VERSION
Definition: version.h:25
Camera::GetModelString
const char * GetModelString()
Settings_ESP3D::GetFirmwareTargetShortName
static const char * GetFirmwareTargetShortName()
Definition: settings_esp3d.cpp:203
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP_DIRECT_SD
#define ESP_DIRECT_SD
Definition: defines.h:55
Commands::hastag
bool hastag(const char *cmd_params, const char *tag)
Definition: commands.cpp:221
TimeServer::is_internet_time
bool is_internet_time(bool readfromsettings=false)
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
Camera::port
uint16_t port()
Definition: camera.h:55
HTTP_Server::port
static uint16_t port()
Definition: http_server.h:57
esp3d_camera
Camera esp3d_camera
WiFiConfig::started
static bool started()
Definition: wificonfig.cpp:270
NetConfig::localIP
static String localIP()
Definition: netconfig.cpp:119
ESP3DOutput
Definition: esp3doutput.h:48