From cb3c683fda3ea24da0630d7a5a8b8369e6f8821d Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Sat, 28 Sep 2024 15:25:48 +0200 Subject: [PATCH] Added server.getPort() --- src/PsychicHttpServer.cpp | 7 +++++++ src/PsychicHttpServer.h | 1 + src/PsychicHttpsServer.cpp | 5 +++++ src/PsychicHttpsServer.h | 1 + 4 files changed, 14 insertions(+) diff --git a/src/PsychicHttpServer.cpp b/src/PsychicHttpServer.cpp index 7b29ce4..958e5d9 100644 --- a/src/PsychicHttpServer.cpp +++ b/src/PsychicHttpServer.cpp @@ -77,6 +77,11 @@ void PsychicHttpServer::setPort(uint16_t port) this->config.server_port = port; } +uint16_t PsychicHttpServer::getPort() +{ + return this->config.server_port; +} + bool PsychicHttpServer::isConnected() { if (WiFi.softAPIP()) @@ -152,6 +157,8 @@ esp_err_t PsychicHttpServer::start() if (ret != ESP_OK) ESP_LOGE(PH_TAG, "Add 404 handler failed (%s)", esp_err_to_name(ret)); + ESP_LOGI(PH_TAG, "Server started on port %" PRIu16, getPort()); + _running = true; return ret; } diff --git a/src/PsychicHttpServer.h b/src/PsychicHttpServer.h index f977c86..c4afb6c 100644 --- a/src/PsychicHttpServer.h +++ b/src/PsychicHttpServer.h @@ -71,6 +71,7 @@ class PsychicHttpServer static void destroy(void* ctx); virtual void setPort(uint16_t port); + virtual uint16_t getPort(); bool isConnected(); bool isRunning() { return _running; } diff --git a/src/PsychicHttpsServer.cpp b/src/PsychicHttpsServer.cpp index ea4f552..faaeb01 100644 --- a/src/PsychicHttpsServer.cpp +++ b/src/PsychicHttpsServer.cpp @@ -29,6 +29,11 @@ void PsychicHttpsServer::setPort(uint16_t port) this->ssl_config.port_secure = port; } +uint16_t PsychicHttpsServer::getPort() +{ + return this->ssl_config.port_secure; +} + void PsychicHttpsServer::setCertificate(const uint8_t* cert, size_t cert_size, const uint8_t* private_key, size_t private_key_size) { if (cert) { diff --git a/src/PsychicHttpsServer.h b/src/PsychicHttpsServer.h index 7c62d71..14927b3 100644 --- a/src/PsychicHttpsServer.h +++ b/src/PsychicHttpsServer.h @@ -30,6 +30,7 @@ class PsychicHttpsServer : public PsychicHttpServer // using PsychicHttpServer::listen; // keep the regular version virtual void setPort(uint16_t port) override final; + virtual uint16_t getPort() override final; // Pointer to certificate data in PEM format void setCertificate(const char* cert, const char* private_key = nullptr) { setCertificate((const uint8_t*)cert, strlen(cert) + 1, (const uint8_t*)private_key, private_key ? strlen(private_key) + 1 : 0); } // Pointer to certificate data in PEM or DER format. PEM-format must have a terminating NULL-character. DER-format requires the length to be passed in certSize and keySize.