Skip to content

Commit

Permalink
Merge pull request #582 from SignalK/mdns_announce
Browse files Browse the repository at this point in the history
Announce only activated services on mDNS
  • Loading branch information
mairas authored Apr 6, 2022
2 parents 3644e36 + 9b901d8 commit 222e2e0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/sensesp/net/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ void MDNSDiscovery::start() {
debugI("mDNS responder started for hostname '%s'", hostname.c_str());
}
mdns_instance_name_set(hostname.c_str()); // mDNS hostname for ESP32
MDNS.addService("http", "tcp", 80);
MDNS.addService("signalk-sensesp", "tcp", 80);
}

} // namespace sensesp
2 changes: 1 addition & 1 deletion src/sensesp/net/discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace sensesp {

class MDNSDiscovery : public Startable {
public:
MDNSDiscovery() : Startable(0) {}
MDNSDiscovery() : Startable(79) {}
virtual void start() override;
};

Expand Down
12 changes: 8 additions & 4 deletions src/sensesp/net/http_server.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "http_server.h"

#include <ESPAsyncWebServer.h>
#include <ESPmDNS.h>
#include <FS.h>

#include <functional>
Expand Down Expand Up @@ -34,7 +35,8 @@ HTTPServer::HTTPServer() : Startable(50) {
// /config
AsyncCallbackJsonWebHandler* config_put_handler =
new AsyncCallbackJsonWebHandler(
"/config", [](AsyncWebServerRequest* request, JsonVariant& json) {
"/config",
[](AsyncWebServerRequest* request, JsonVariant& json) {
// omit the "/config" part of the url
String url_tail = request->url().substring(7);

Expand Down Expand Up @@ -63,7 +65,8 @@ HTTPServer::HTTPServer() : Startable(50) {
confable->save_configuration();
request->send(200, "text/plain", F("Configuration successful.\n"));
return;
}, 4096);
},
4096);
config_put_handler->setMethod(HTTP_PUT);
server->addHandler(config_put_handler);

Expand Down Expand Up @@ -136,8 +139,6 @@ HTTPServer::HTTPServer() : Startable(50) {
server->on("/info", HTTP_GET, std::bind(&HTTPServer::handle_info, this, _1));
}



void HTTPServer::start() {
// only start the server if WiFi is connected
if (WiFi.status() == WL_CONNECTED) {
Expand All @@ -152,6 +153,9 @@ void HTTPServer::start() {
debugI("HTTP server started");
}
});

// announce the server over mDNS
MDNS.addService("http", "tcp", 80);
}

void HTTPServer::handle_not_found(AsyncWebServerRequest* request) {
Expand Down
1 change: 1 addition & 0 deletions src/sensesp/net/ws_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ WSClient::WSClient(String config_path, SKDeltaQueue* sk_delta_queue,
void WSClient::start() {
xTaskCreate(ExecuteWebSocketTask, "WSClient", ws_client_task_stack_size, this,
1, NULL);
MDNS.addService("signalk-sensesp", "tcp", 80);
}

void WSClient::connect_loop() {
Expand Down

0 comments on commit 222e2e0

Please sign in to comment.