21 #include "../../include/esp3d_config.h"
22 #if defined (WIFI_FEATURE)
23 #ifdef ARDUINO_ARCH_ESP32
25 #endif //ARDUINO_ARCH_ESP32
26 #ifdef ARDUINO_ARCH_ESP8266
27 #endif //ARDUINO_ARCH_ESP8266
28 #include "../wifi/wificonfig.h"
29 #include "../network/netconfig.h"
30 #include "../../core/esp3doutput.h"
31 #include "../../core/settings_esp3d.h"
55 for (uint i = 0; i < strlen (ssid); i++) {
56 if (!isPrintable (ssid[i]) ) {
66 #if defined (ARDUINO_ARCH_ESP8266)
67 if (WiFi.getMode() == WIFI_AP) {
71 tmp = WiFi.hostname();
74 #endif //ARDUINO_ARCH_ESP8266
75 #if defined (ARDUINO_ARCH_ESP32)
76 if (WiFi.getMode() == WIFI_AP) {
79 tmp = WiFi.softAPgetHostname();
81 tmp = WiFi.getHostname();
83 #endif //ARDUINO_ARCH_ESP8266
93 if (strlen (password) == 0) {
115 return (2 * (RSSI + 100) );
122 bool WiFiConfig::ConnectSTA2AP()
127 wl_status_t status = WiFi.status();
129 while (status != WL_CONNECTED && count < 40) {
132 case WL_NO_SSID_AVAIL:
135 case WL_CONNECT_FAILED:
136 msg=
"Connection failed";
141 if ((dot>3) || (dot==0) ) {
143 msg_out =
"Connecting";
151 output.printMSG(msg.c_str());
155 status = WiFi.status();
157 return (status == WL_CONNECTED);
166 if((WiFi.getMode() == WIFI_STA) || (WiFi.getMode() == WIFI_AP_STA)) {
169 if((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA)) {
170 WiFi.softAPdisconnect();
172 WiFi.enableAP (
false);
182 IPAddress ip(IP), mask(MK), gateway(GW);
183 WiFi.config(ip, gateway,mask);
187 stmp =
"Connecting to '" + SSID +
"'";;
189 if (WiFi.begin(SSID.c_str(), (password.length() > 0)?password.c_str():
nullptr)) {
190 #if defined (ARDUINO_ARCH_ESP8266)
191 WiFi.setSleepMode(WIFI_NONE_SLEEP);
195 #endif //ARDUINO_ARCH_ESP8266
196 #if defined (ARDUINO_ARCH_ESP32)
197 WiFi.setSleep(
false);
199 #endif //ARDUINO_ARCH_ESP32
200 return ConnectSTA2AP();
215 if((WiFi.getMode() == WIFI_STA) || (WiFi.getMode() == WIFI_AP_STA)) {
218 if((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA)) {
219 WiFi.softAPdisconnect();
221 WiFi.enableSTA (
false);
224 #if defined (ARDUINO_ARCH_ESP8266)
225 WiFi.setSleepMode(WIFI_NONE_SLEEP);
230 #endif //ARDUINO_ARCH_ESP8266
242 if (!WiFi.softAPConfig(ip, ip, mask)) {
245 output.
printMSG(ip.toString().c_str());
248 if(WiFi.softAP(SSID.c_str(), (password.length() > 0)?password.c_str():
nullptr, channel)) {
249 String stmp =
"AP SSID: '" + SSID;
250 if (password.length() > 0) {
251 stmp +=
"' is started and protected by password";
253 stmp +=
" is started not protected by passord";
257 #if defined (ARDUINO_ARCH_ESP32)
258 WiFi.setSleep(
false);
262 #endif //ARDUINO_ARCH_ESP32
272 return (WiFi.getMode() != WIFI_OFF);
304 if((WiFi.getMode() == WIFI_STA) || (WiFi.getMode() == WIFI_AP_STA)) {
305 WiFi.disconnect(
true);
307 if((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA)) {
308 WiFi.softAPdisconnect(
true);
322 if (WiFi.getMode() == WIFI_AP_STA) {
323 if (WiFi.scanComplete() != WIFI_SCAN_RUNNING) {
324 WiFi.enableSTA (
false);
331 #ifdef ARDUINO_ARCH_ESP32
332 if (WiFi.getSleep()) {
337 #endif //ARDUINO_ARCH_ESP32
338 #ifdef ARDUINO_ARCH_ESP8266
339 WiFiSleepType_t ps_type = WiFi.getSleepMode();
340 if (ps_type == WIFI_NONE_SLEEP) {
342 }
else if (ps_type == WIFI_LIGHT_SLEEP) {
344 }
else if (ps_type == WIFI_MODEM_SLEEP) {
349 #endif //ARDUINO_ARCH_ESP8266
354 #ifdef ARDUINO_ARCH_ESP32
356 esp_wifi_get_protocol ((wifimode == WIFI_STA)?ESP_IF_WIFI_STA:ESP_IF_WIFI_AP, &PhyMode);
357 #endif //ARDUINO_ARCH_ESP32
358 #ifdef ARDUINO_ARCH_ESP8266
360 WiFiPhyMode_t PhyMode = WiFi.getPhyMode();
361 #endif //ARDUINO_ARCH_ESP8266
362 if (PhyMode == (WIFI_PHY_MODE_11G) ) {
364 }
else if (PhyMode == (WIFI_PHY_MODE_11B) ) {
366 }
else if (PhyMode == (WIFI_PHY_MODE_11N) ) {
375 #ifdef ARDUINO_ARCH_ESP32
377 esp_wifi_get_config (ESP_IF_WIFI_AP, &conf);
378 return (conf.ap.ssid_hidden == 0);
379 #endif //ARDUINO_ARCH_ESP32
380 #ifdef ARDUINO_ARCH_ESP8266
381 struct softap_config apconfig;
382 wifi_softap_get_config (&apconfig);
383 return (apconfig.ssid_hidden == 0);
384 #endif //ARDUINO_ARCH_ESP8266
390 #ifdef ARDUINO_ARCH_ESP32
392 esp_wifi_get_config (ESP_IF_WIFI_AP, &conf);
393 ssid = (
const char*) conf.ap.ssid;
395 #ifdef ARDUINO_ARCH_ESP8266
396 struct softap_config apconfig;
397 wifi_softap_get_config (&apconfig);
398 ssid = (
const char*) apconfig.ssid;
406 #ifdef ARDUINO_ARCH_ESP32
408 esp_wifi_get_config (ESP_IF_WIFI_AP, &conf);
409 mode = conf.ap.authmode;
411 #endif //ARDUINO_ARCH_ESP32
412 #ifdef ARDUINO_ARCH_ESP8266
413 struct softap_config apconfig;
414 wifi_softap_get_config (&apconfig);
415 mode = apconfig.authmode;
416 #endif //ARDUINO_ARCH_ESP8266
417 if (mode == AUTH_OPEN) {
419 }
else if (mode == AUTH_WEP) {
421 }
else if (mode == AUTH_WPA_PSK) {
423 }
else if (mode == AUTH_WPA2_PSK) {
433 #ifdef ARDUINO_ARCH_ESP32
434 tcpip_adapter_ip_info_t ip_AP;
435 tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_AP, &ip_AP);
436 tmp = IPAddress (ip_AP.gw.addr).toString();
437 #endif //ARDUINO_ARCH_ESP32
438 #ifdef ARDUINO_ARCH_ESP8266
439 struct ip_info ip_AP;
440 if (!wifi_get_ip_info (SOFTAP_IF, &ip_AP)) {
443 tmp = IPAddress (ip_AP.gw).toString();
444 #endif //ARDUINO_ARCH_ESP8266
451 #ifdef ARDUINO_ARCH_ESP32
452 tcpip_adapter_ip_info_t ip_AP;
453 tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_AP, &ip_AP);
454 tmp = IPAddress (ip_AP.netmask.addr).toString();
455 #endif //ARDUINO_ARCH_ESP32
456 #ifdef ARDUINO_ARCH_ESP8266
457 struct ip_info ip_AP;
458 if (!wifi_get_ip_info (SOFTAP_IF, &ip_AP)) {
461 tmp = IPAddress (ip_AP.netmask).toString();
462 #endif //ARDUINO_ARCH_ESP8266
468 static uint8_t count = 0;
469 static uint8_t current = 0;
473 #ifdef ARDUINO_ARCH_ESP32
474 if (current > count) {
477 static wifi_sta_list_t station;
478 static tcpip_adapter_sta_list_t tcpip_sta_list;
484 esp_wifi_ap_get_sta_list (&station);
485 tcpip_adapter_get_sta_list (&station, &tcpip_sta_list);
489 data = IPAddress (tcpip_sta_list.sta[current].ip.addr).toString();
496 #endif //ARDUINO_ARCH_ESP32
497 #ifdef ARDUINO_ARCH_ESP8266
498 static struct station_info * station;
499 if (current > count) {
508 station = wifi_softap_get_station_info();
509 struct station_info * station_tmp = station;
513 station = STAILQ_NEXT (station, next);
515 station = station_tmp;
517 if ((count > 0) && station) {
518 data = IPAddress ((
const uint8_t *) &station->ip).toString();
523 station = STAILQ_NEXT (station, next);
524 if ((current == count) || !station) {
525 wifi_softap_free_station_info();
528 #endif //ARDUINO_ARCH_ESP8266
535 #endif // WIFI_FEATURE