Browse Source

Added captive portal when in AP mode

rfm69
Xose Pérez 6 years ago
parent
commit
0575a97fb3
2 changed files with 37 additions and 1 deletions
  1. +7
    -1
      code/espurna/config/general.h
  2. +30
    -0
      code/espurna/wifi.ino

+ 7
- 1
code/espurna/config/general.h View File

@ -78,7 +78,7 @@
#define DEBUG_UDP_PORT 514 #define DEBUG_UDP_PORT 514
#endif #endif
// If DEBUG_UDP_PORT is set to 514 syslog format is assumed
// If DEBUG_UDP_PORT is set to 514 syslog format is assumed
// (https://tools.ietf.org/html/rfc3164) // (https://tools.ietf.org/html/rfc3164)
// DEBUG_UDP_FAC_PRI is the facility+priority // DEBUG_UDP_FAC_PRI is the facility+priority
#define DEBUG_UDP_FAC_PRI (SYSLOG_LOCAL0 | SYSLOG_DEBUG) #define DEBUG_UDP_FAC_PRI (SYSLOG_LOCAL0 | SYSLOG_DEBUG)
@ -268,7 +268,13 @@
#define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms #define WIFI_RECONNECT_INTERVAL 180000 // If could not connect to WIFI, retry after this time in ms
#endif #endif
#ifndef WIFI_MAX_NETWORKS
#define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations #define WIFI_MAX_NETWORKS 5 // Max number of WIFI connection configurations
#endif
#ifndef WIFI_AP_CAPTIVE
#define WIFI_AP_CAPTIVE 1 // Captive portal enabled when in AP mode
#endif
#ifndef WIFI_AP_MODE #ifndef WIFI_AP_MODE
#define WIFI_AP_MODE AP_MODE_ALONE #define WIFI_AP_MODE AP_MODE_ALONE


+ 30
- 0
code/espurna/wifi.ino View File

@ -196,6 +196,27 @@ void _wifiInject() {
} }
} }
#if WIFI_AP_CAPTIVE
DNSServer _wifi_dnsServer;
void _wifiCaptivePortal(justwifi_messages_t code, char * parameter) {
if (MESSAGE_ACCESSPOINT_CREATED == code) {
_wifi_dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
_wifi_dnsServer.start(53, "*", WiFi.softAPIP());
DEBUG_MSG_P(PSTR("[WIFI] Captive portal enabled\n"));
}
if (MESSAGE_CONNECTED == code) {
_wifi_dnsServer.stop();
DEBUG_MSG_P(PSTR("[WIFI] Captive portal disabled\n"));
}
}
#endif // WIFI_AP_CAPTIVE
#if DEBUG_SUPPORT #if DEBUG_SUPPORT
void _wifiDebug(justwifi_messages_t code, char * parameter) { void _wifiDebug(justwifi_messages_t code, char * parameter) {
@ -422,6 +443,9 @@ void wifiSetup() {
_wifiConfigure(); _wifiConfigure();
// Message callbacks // Message callbacks
#if WIFI_AP_CAPTIVE
wifiRegister(_wifiCaptivePortal);
#endif
#if DEBUG_SUPPORT #if DEBUG_SUPPORT
wifiRegister(_wifiDebug); wifiRegister(_wifiDebug);
#endif #endif
@ -446,6 +470,12 @@ void wifiLoop() {
jw.loop(); jw.loop();
#if WIFI_AP_CAPTIVE
if ((WiFi.getMode() & WIFI_AP) == WIFI_AP) {
_wifi_dnsServer.processNextRequest();
}
#endif
if (_wifi_scan_client_id > 0) { if (_wifi_scan_client_id > 0) {
_wifiScan(_wifi_scan_client_id); _wifiScan(_wifi_scan_client_id);
_wifi_scan_client_id = 0; _wifi_scan_client_id = 0;


Loading…
Cancel
Save