Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/MDNSAnnouncer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace OpenShock::MDNSAnnouncer {
bool Init();
bool IsEnabled();
void SetEnabled(bool enabled);
} // namespace OpenShock::MDNSAnnouncer
21 changes: 0 additions & 21 deletions src/CaptivePortal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const char* const TAG = "CaptivePortal";
#include <WiFi.h>

#include <esp_timer.h>
#include <mdns.h>

#include <memory>

Expand Down Expand Up @@ -54,26 +53,6 @@ static bool captiveportal_start()
return false;
}

esp_err_t err = mdns_init();
if (err != ESP_OK) {
OS_LOGE(TAG, "Failed to initialize mDNS");
WiFi.softAPdisconnect(true);
return false;
}

std::string hostname;
if (!Config::GetWiFiHostname(hostname)) {
OS_LOGE(TAG, "Failed to get WiFi hostname, reverting to default");
hostname = OPENSHOCK_FW_HOSTNAME;
}

err = mdns_hostname_set(hostname.c_str());
if (err != ESP_OK) {
OS_LOGE(TAG, "Failed to set mDNS hostname");
WiFi.softAPdisconnect(true);
return false;
}

s_instance = std::make_unique<CaptivePortalInstance>();

return true;
Expand Down
48 changes: 48 additions & 0 deletions src/MDNSAnnouncer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "MDNSAnnouncer.h"

#include "config/Config.h"

#include <mdns.h>

#include <string>

static const char* TAG = "MDNSAnnouncer";

using namespace OpenShock;

bool MDNSAnnouncer::Init() {
esp_err_t err = mdns_init();
if (err != ESP_OK) {
OS_LOGE(TAG, "Failed to initialize mDNS");
WiFi.softAPdisconnect(true);
return false;
}

mdns_instance_name_set("OpenShock");

std::string hostname;
if (Config::GetWiFiHostname(hostname)) {
OS_LOGE(TAG, "Failed to get WiFi hostname, reverting to default");
hostname = OPENSHOCK_FW_HOSTNAME;
}

err = mdns_hostname_set(hostname.c_str());
if (err != ESP_OK) {
OS_LOGE(TAG, "Failed to set mDNS hostname");
WiFi.softAPdisconnect(true);
return false;
}

return true;
}

bool MDNSAnnouncer::IsEnabled() {
mdns_service_add("http", "_tcp", 80);
return Config::GetCaptivePortalConfig().mdnsEnabled;
}

void MDNSAnnouncer::SetEnabled(bool enabled) {
Config::SetCaptivePortalConfig({
.mdnsEnabled = enabled,
});
}
1 change: 0 additions & 1 deletion src/wifi/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ bool WiFiManager::Init()
hostname = OPENSHOCK_FW_HOSTNAME;
}

WiFi.setAutoConnect(false);
WiFi.setAutoReconnect(false);
WiFi.enableSTA(true);
WiFi.setHostname(hostname.c_str());
Expand Down
Loading