Skip to content

Commit

Permalink
Merge pull request #190 from mathieucarbou/getPort()
Browse files Browse the repository at this point in the history
Added server.getPort()
  • Loading branch information
mathieucarbou authored Sep 28, 2024
2 parents 595d8f3 + cb3c683 commit 9ac73f2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/PsychicHttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/PsychicHttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
5 changes: 5 additions & 0 deletions src/PsychicHttpsServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/PsychicHttpsServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9ac73f2

Please sign in to comment.