21 #include "../../include/esp3d_config.h"
25 #include "../../core/settings_esp3d.h"
26 #include "../../core/esp3doutput.h"
27 #if defined( ARDUINO_ARCH_ESP8266)
29 #include <ESP8266mDNS.h>
32 #include <ESP8266SSDP.h>
34 #endif //ARDUINO_ARCH_ESP8266
35 #if defined( ARDUINO_ARCH_ESP32)
40 #include <ESP32SSDP.h>
42 #endif //ARDUINO_ARCH_ESP32
44 #include <ArduinoOTA.h>
46 #if defined(FILESYSTEM_FEATURE)
47 #include "../filesystem/esp_filesystem.h"
48 #endif //FILESYSTEM_FEATURE
50 #include "../telnet/telnet_server.h"
51 #endif //TELNET_FEATURE
53 #include "../ftp/FtpServer.h"
56 #include "../http/http_server.h"
58 #if defined(HTTP_FEATURE) || defined(WS_DATA_FEATURE)
59 #include "../websocket/websocket_server.h"
60 #endif //HTTP_FEATURE || WS_DATA_FEATURE
61 #ifdef CAPTIVE_PORTAL_FEATURE
62 #include <DNSServer.h>
65 #endif //CAPTIVE_PORTAL_FEATURE
66 #ifdef TIMESTAMP_FEATURE
67 #include "../time/time_server.h"
68 #endif //TIMESTAMP_FEATURE
69 #ifdef NOTIFICATION_FEATURE
70 #include "../notifications/notifications_service.h"
71 #endif //NOTIFICATION_FEATURE
73 #include "../camera/camera.h"
74 #endif //CAMERA_DEVICE
75 bool NetServices::_started =
false;
76 bool NetServices::_restart =
false;
92 #ifdef TIMESTAMP_FEATURE
93 if (WiFi.getMode() != WIFI_AP) {
96 output.
printERROR(
"Failed contact time servers!");
99 String tmp =
"Time set :";
104 #endif //TIMESTAMP_FEATURE
105 #if defined(MDNS_FEATURE) && defined(ARDUINO_ARCH_ESP8266)
106 if(WiFi.getMode() != WIFI_AP) {
107 String lhostname =hostname;
108 lhostname.toLowerCase();
109 if (!MDNS.begin(hostname.c_str())) {
113 String stmp =
"mDNS started with '" + lhostname +
".local'";
117 #endif //MDNS_FEATURE && ARDUINO_ARCH_ESP8266
120 if(WiFi.getMode() != WIFI_AP) {
121 ArduinoOTA.onStart([]() {
123 String type =
"Start OTA updating ";
124 if (ArduinoOTA.getCommand() == U_FLASH) {
128 type +=
"filesystem";
129 #if defined(FILESYSTEM_FEATURE)
131 #endif //FILESYSTEM_FEATURE
136 ArduinoOTA.onEnd([]() {
140 ArduinoOTA.onProgress([](
unsigned int progress,
unsigned int total) {
141 String prg =
"OTA Progress ";
143 prg += String(progress / (total / 100)) +
"%";
146 ArduinoOTA.onError([](ota_error_t error) {
147 String stmp =
"OTA Error: " + String(error);
150 if (error == OTA_AUTH_ERROR) {
152 }
else if (error == OTA_BEGIN_ERROR) {
154 }
else if (error == OTA_CONNECT_ERROR) {
156 }
else if (error == OTA_RECEIVE_ERROR) {
158 }
else if (error == OTA_END_ERROR) {
162 output.
printMSG(
"OTA service started");
167 #if defined(MDNS_FEATURE) && defined(ARDUINO_ARCH_ESP32)
168 if(WiFi.getMode() != WIFI_AP) {
169 String lhostname =hostname;
170 lhostname.toLowerCase();
171 if (!MDNS.begin(hostname.c_str())) {
175 String stmp =
"mDNS started with '" + lhostname +
".local'";
179 #endif //MDNS_FEATURE && ARDUINO_ARCH_ESP8266
181 #ifdef CAPTIVE_PORTAL_FEATURE
182 if(WiFi.getMode() == WIFI_AP) {
186 output.
printMSG(
"Captive Portal started");
188 output.
printERROR(
"Failed start Captive Portal");
191 #endif //CAPTIVE_PORTAL_FEATURE
203 #endif //HTTP_FEATURE
204 #ifdef TELNET_FEATURE
214 #endif //TELNET_FEATURE
226 #ifdef WS_DATA_FEATURE
228 output.
printMSG(
"Failed start Terminal Web Socket");
235 #endif //WS_DATA_FEATURE
236 #if defined(HTTP_FEATURE)
238 output.
printMSG(
"Failed start Terminal Web Socket");
240 #endif //HTTP_FEATURE
242 if(WiFi.getMode() != WIFI_AP) {
244 MDNS.addService(
"http",
"tcp", 80);
246 #endif //MDNS_FEATURE
252 SSDP.setSchemaURL (
"description.xml");
254 SSDP.setName (hostname.c_str());
256 SSDP.setDeviceType (
"upnp:rootdevice");
265 stmp =
"SSDP started with '" + hostname +
"'";
268 #endif //SSDP_FEATURE
269 #ifdef NOTIFICATION_FEATURE
272 #endif //NOTIFICATION_FEATURE
275 output.
printMSG(
"Failed start camera streaming server");
277 #endif //CAMERA_DEVICE
293 #endif //CAMERA_DEVICE
294 #ifdef NOTIFICATION_FEATURE
296 #endif //NOTIFICATION_FEATURE
297 #ifdef CAPTIVE_PORTAL_FEATURE
298 if(WiFi.getMode() == WIFI_AP) {
301 #endif //CAPTIVE_PORTAL_FEATURE
303 #if defined(ARDUINO_ARCH_ESP32)
305 #endif //ARDUINO_ARCH_ESP32
306 #endif //SSDP_FEATURE
308 #if defined(ARDUINO_ARCH_ESP32)
309 if(WiFi.getMode() != WIFI_AP) {
310 mdns_service_remove(
"_http",
"_tcp");
313 #endif // ARDUINO_ARCH_ESP32
314 #endif //MDNS_FEATURE
317 #if defined(ARDUINO_ARCH_ESP32)
318 if(WiFi.getMode() != WIFI_AP) {
321 #endif // ARDUINO_ARCH_ESP32
323 #if defined(HTTP_FEATURE)
325 #endif //HTTP_FEATURE
328 #endif //HTTP_FEATURE
329 #ifdef WS_DATA_FEATURE
331 #endif //WS_DATA_FEATURE
332 #ifdef TELNET_FEATURE
334 #endif //TELNET_FEATURE
344 #if defined(ARDUINO_ARCH_ESP8266)
346 #endif //ARDUINO_ARCH_ESP8266
347 #endif //MDNS_FEATURE
351 #ifdef CAPTIVE_PORTAL_FEATURE
352 if (WiFi.getMode()== WIFI_AP ) {
355 #endif //CAPTIVE_PORTAL_FEATURE
358 #endif //HTTP_FEATURE
359 #ifdef WS_DATA_FEATURE
361 #endif //WS_DATA_FEATURE
362 #if defined(HTTP_FEATURE)
364 #endif //HTTP_FEATURE
365 #ifdef TELNET_FEATURE
367 #endif //TELNET_FEATURE
371 #ifdef NOTIFICATION_FEATURE
373 #endif //NOTIFICATION_FEATURE