Skip to content

Commit

Permalink
compile fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chl33 committed Feb 9, 2024
1 parent 10622e5 commit f846e64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 5 additions & 1 deletion include/og3/wifi_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#pragma once

#ifndef NATIVE
#include <DNSServer.h>
#endif

#include <functional>
#include <memory>
Expand Down Expand Up @@ -87,7 +89,9 @@ class WifiManager : public Module {
void onWifiEvent(arduino_event_id_t task, arduino_event_info_t info);
#endif

std::unique_ptr<DNSServer> m_dnsServer;
#ifndef NATIVE
std::unique_ptr<DNSServer> m_dns_server;
#endif
SingleDependency m_dependencies;
TaskScheduler m_scheduler;
TaskScheduler m_status_scheduler;
Expand Down
18 changes: 12 additions & 6 deletions src/wifi_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class OnExit {
const std::function<void()> m_exit_fn;
};

#ifndef NATIVE
constexpr uint8_t DNS_PORT = 53;
#endif
const IPAddress apSoftIP(192, 168, 4, 1);

static const char kStatusUninitialized[] = "init";
Expand Down Expand Up @@ -104,7 +106,9 @@ WifiManager::WifiManager(const char* default_board_name, Tasks* tasks,
return m_config != nullptr;
});
add_init_fn([this]() {
#ifndef NATIVE
WiFi.persistent(false); // Keep the esp from automatically writing essid+paswd to flash.
#endif
if (m_config) {
m_config->read_config(&m_vg);
}
Expand All @@ -123,11 +127,13 @@ WifiManager::WifiManager(const char* default_board_name, Tasks* tasks,
trySetup();
}
});
#ifndef NATIVE
add_update_fn([this]() {
if (m_ap_mode && m_dnsServer) {
m_dnsServer->processNextRequest();
if (m_ap_mode && m_dns_server) {
m_dns_server->processNextRequest();
}
});
#endif
}

void WifiManager::handleRequest(AsyncWebServerRequest* request, const char* title,
Expand Down Expand Up @@ -195,11 +201,11 @@ void WifiManager::trySetup() {
m_ap_mode = true;
if (WiFi.softAPConfig(apSoftIP, apSoftIP, IPAddress(255, 255, 255, 0)) &&
WiFi.softAP(board().c_str())) {
if (!m_dnsServer) {
m_dnsServer.reset(new DNSServer());
if (!m_dns_server) {
m_dns_server.reset(new DNSServer());
}
m_dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
m_dnsServer->start(DNS_PORT, "*", apSoftIP);
m_dns_server->setErrorReplyCode(DNSReplyCode::NoError);
m_dns_server->start(DNS_PORT, "*", apSoftIP);
for (const auto& callback : m_softAPCallbacks) {
callback();
}
Expand Down

0 comments on commit f846e64

Please sign in to comment.