Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/framework/APStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void APStatus::begin()
_securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1),
AuthenticationPredicates::IS_AUTHENTICATED));

ESP_LOGV("APStatus", "Registered GET endpoint: %s", AP_STATUS_SERVICE_PATH);
ESP_LOGV(TAG, "Registered GET endpoint: %s", AP_STATUS_SERVICE_PATH);
}

esp_err_t APStatus::apStatus(PsychicRequest *request)
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/AuthenticationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ void AuthenticationService::begin()
}
return request->reply(401); });

ESP_LOGV("AuthenticationService", "Registered POST endpoint: %s", SIGN_IN_PATH);
ESP_LOGV(TAG, "Registered POST endpoint: %s", SIGN_IN_PATH);

// Verifies that the request supplied a valid JWT
_server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, [this](PsychicRequest *request)
{
Authentication authentication = _securityManager->authenticateRequest(request);
return request->reply(authentication.authenticated ? 200 : 401); });

ESP_LOGV("AuthenticationService", "Registered GET endpoint: %s", VERIFY_AUTHORIZATION_PATH);
ESP_LOGV(TAG, "Registered GET endpoint: %s", VERIFY_AUTHORIZATION_PATH);
}

#endif // end FT_ENABLED(FT_SECURITY)
14 changes: 7 additions & 7 deletions lib/framework/DownloadFirmwareService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void update_progress(int currentBytes, int totalBytes)
doc["progress"] = progress;
JsonObject jsonObject = doc.as<JsonObject>();
_socket->emitEvent(EVENT_DOWNLOAD_OTA, jsonObject);
ESP_LOGV("Download OTA", "HTTP update process at %d of %d bytes... (%d %%)", currentBytes, totalBytes, progress);
ESP_LOGV(TAG, "HTTP update process at %d of %d bytes... (%d %%)", currentBytes, totalBytes, progress);
}
previousProgress = progress;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ void updateTask(void *param)
jsonObject = doc.as<JsonObject>();
_socket->emitEvent(EVENT_DOWNLOAD_OTA, jsonObject);

ESP_LOGE("Download OTA", "HTTP Update failed with error (%d): %s", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
ESP_LOGE(TAG, "HTTP Update failed with error (%d): %s", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
#ifdef SERIAL_INFO
Serial.printf("HTTP Update failed with error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
#endif
Expand All @@ -97,13 +97,13 @@ void updateTask(void *param)
jsonObject = doc.as<JsonObject>();
_socket->emitEvent(EVENT_DOWNLOAD_OTA, jsonObject);

ESP_LOGE("Download OTA", "HTTP Update failed, has same firmware version");
ESP_LOGE(TAG, "HTTP Update failed, has same firmware version");
#ifdef SERIAL_INFO
Serial.println("HTTP Update failed, has same firmware version");
#endif
break;
case HTTP_UPDATE_OK:
ESP_LOGI("Download OTA", "HTTP Update successful - Restarting");
ESP_LOGI(TAG, "HTTP Update successful - Restarting");
#ifdef SERIAL_INFO
Serial.println("HTTP Update successful - Restarting");
#endif
Expand All @@ -130,7 +130,7 @@ void DownloadFirmwareService::begin()
std::bind(&DownloadFirmwareService::downloadUpdate, this, std::placeholders::_1, std::placeholders::_2),
AuthenticationPredicates::IS_ADMIN));

ESP_LOGV("DownloadFirmwareService", "Registered POST endpoint: %s", GITHUB_FIRMWARE_PATH);
ESP_LOGV(TAG, "Registered POST endpoint: %s", GITHUB_FIRMWARE_PATH);
}

esp_err_t DownloadFirmwareService::downloadUpdate(PsychicRequest *request, JsonVariant &json)
Expand All @@ -141,7 +141,7 @@ esp_err_t DownloadFirmwareService::downloadUpdate(PsychicRequest *request, JsonV
}

String downloadURL = json["download_url"];
ESP_LOGI("Download OTA", "Starting OTA from: %s", downloadURL.c_str());
ESP_LOGI(TAG, "Starting OTA from: %s", downloadURL.c_str());
#ifdef SERIAL_INFO
Serial.println("Starting OTA from: " + downloadURL);
#endif
Expand All @@ -163,7 +163,7 @@ esp_err_t DownloadFirmwareService::downloadUpdate(PsychicRequest *request, JsonV
1 // Have it on application core
) != pdPASS)
{
ESP_LOGE("Download OTA", "Couldn't create download OTA task");
ESP_LOGE(TAG, "Couldn't create download OTA task");
return request->reply(500);
}
return request->reply(200);
Expand Down
12 changes: 6 additions & 6 deletions lib/framework/ESP32SvelteKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ESP32SvelteKit::ESP32SvelteKit(PsychicHttpServer *server, unsigned int numberEnd

void ESP32SvelteKit::begin()
{
ESP_LOGV("ESP32SvelteKit", "Loading settings from files system");
ESP_LOGV(TAG, "Loading settings from files system");
ESPFS.begin(true);

_wifiSettingsService.initWiFi();
Expand All @@ -71,7 +71,7 @@ void ESP32SvelteKit::begin()

#ifdef EMBED_WWW
// Serve static resources from PROGMEM
ESP_LOGV("ESP32SvelteKit", "Registering routes from PROGMEM static resources");
ESP_LOGV(TAG, "Registering routes from PROGMEM static resources");
WWWData::registerRoutes(
[&](const String &uri, const String &contentType, const uint8_t *content, size_t len)
{
Expand All @@ -98,7 +98,7 @@ void ESP32SvelteKit::begin()
});
#else
// Serve static resources from /www/
ESP_LOGV("ESP32SvelteKit", "Registering routes from FS /www/ static resources");
ESP_LOGV(TAG, "Registering routes from FS /www/ static resources");
_server->serveStatic("/_app/", ESPFS, "/www/_app/");
_server->serveStatic("/favicon.png", ESPFS, "/www/favicon.png");
// Serving all other get requests with "/www/index.htm"
Expand All @@ -118,13 +118,13 @@ void ESP32SvelteKit::begin()
#endif

#if defined(ENABLE_CORS)
ESP_LOGV("ESP32SvelteKit", "Enabling CORS headers");
ESP_LOGV(TAG, "Enabling CORS headers");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", CORS_ORIGIN);
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Credentials", "true");
#endif

ESP_LOGV("ESP32SvelteKit", "Starting MDNS");
ESP_LOGV(TAG, "Starting MDNS");
MDNS.begin(_wifiSettingsService.getHostname().c_str());
MDNS.setInstanceName(_appName);
MDNS.addService("http", "tcp", 80);
Expand Down Expand Up @@ -177,7 +177,7 @@ void ESP32SvelteKit::begin()
#endif

// Start the loop task
ESP_LOGV("ESP32SvelteKit", "Starting loop task");
ESP_LOGV(TAG, "Starting loop task");
xTaskCreatePinnedToCore(
this->_loopImpl, // Function that should be called
"ESP32 SvelteKit Loop", // Name of the task (for debugging)
Expand Down
32 changes: 16 additions & 16 deletions lib/framework/EventSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ void EventSocket::begin()
_socket.onFrame(std::bind(&EventSocket::onFrame, this, std::placeholders::_1, std::placeholders::_2));
_server->on(EVENT_SERVICE_PATH, &_socket);

ESP_LOGV("EventSocket", "Registered event socket endpoint: %s", EVENT_SERVICE_PATH);
ESP_LOGV(TAG, "Registered event socket endpoint: %s", EVENT_SERVICE_PATH);
}

void EventSocket::registerEvent(String event)
{
if (!isEventValid(event))
{
ESP_LOGD("EventSocket", "Registering event: %s", event.c_str());
ESP_LOGD(TAG, "Registering event: %s", event.c_str());
events.push_back(event);
}
else
{
ESP_LOGW("EventSocket", "Event already registered: %s", event.c_str());
ESP_LOGW(TAG, "Event already registered: %s", event.c_str());
}
}

void EventSocket::onWSOpen(PsychicWebSocketClient *client)
{
ESP_LOGI("EventSocket", "ws[%s][%u] connect", client->remoteIP().toString().c_str(), client->socket());
ESP_LOGI(TAG, "ws[%s][%u] connect", client->remoteIP().toString().c_str(), client->socket());
}

void EventSocket::onWSClose(PsychicWebSocketClient *client)
Expand All @@ -47,26 +47,26 @@ void EventSocket::onWSClose(PsychicWebSocketClient *client)
event_subscriptions.second.remove(client->socket());
}
xSemaphoreGive(clientSubscriptionsMutex);
ESP_LOGI("EventSocket", "ws[%s][%u] disconnect", client->remoteIP().toString().c_str(), client->socket());
ESP_LOGI(TAG, "ws[%s][%u] disconnect", client->remoteIP().toString().c_str(), client->socket());
}

esp_err_t EventSocket::onFrame(PsychicWebSocketRequest *request, httpd_ws_frame *frame)
{
ESP_LOGV("EventSocket", "ws[%s][%u] opcode[%d]", request->client()->remoteIP().toString().c_str(),
ESP_LOGV(TAG, "ws[%s][%u] opcode[%d]", request->client()->remoteIP().toString().c_str(),
request->client()->socket(), frame->type);

JsonDocument doc;
#if FT_ENABLED(EVENT_USE_JSON)
if (frame->type == HTTPD_WS_TYPE_TEXT)
{
ESP_LOGV("EventSocket", "ws[%s][%u] request: %s", request->client()->remoteIP().toString().c_str(),
ESP_LOGV(TAG, "ws[%s][%u] request: %s", request->client()->remoteIP().toString().c_str(),
request->client()->socket(), (char *)frame->payload);

DeserializationError error = deserializeJson(doc, (char *)frame->payload, frame->len);
#else
if (frame->type == HTTPD_WS_TYPE_BINARY)
{
ESP_LOGV("EventSocket", "ws[%s][%u] request: %s", request->client()->remoteIP().toString().c_str(),
ESP_LOGV(TAG, "ws[%s][%u] request: %s", request->client()->remoteIP().toString().c_str(),
request->client()->socket(), (char *)frame->payload);

DeserializationError error = deserializeMsgPack(doc, (char *)frame->payload, frame->len);
Expand All @@ -85,7 +85,7 @@ esp_err_t EventSocket::onFrame(PsychicWebSocketRequest *request, httpd_ws_frame
}
else
{
ESP_LOGW("EventSocket", "Client tried to subscribe to unregistered event: %s", doc["data"].as<String>().c_str());
ESP_LOGW(TAG, "Client tried to subscribe to unregistered event: %s", doc["data"].as<String>().c_str());
}
}
else if (event == "unsubscribe")
Expand All @@ -99,7 +99,7 @@ esp_err_t EventSocket::onFrame(PsychicWebSocketRequest *request, httpd_ws_frame
}
return ESP_OK;
}
ESP_LOGW("EventSocket", "Error[%d] parsing JSON: %s", error, (char *)frame->payload);
ESP_LOGW(TAG, "Error[%d] parsing JSON: %s", error, (char *)frame->payload);
}
return ESP_OK;
}
Expand All @@ -109,7 +109,7 @@ void EventSocket::emitEvent(String event, JsonObject &jsonObject, const char *or
// Only process valid events
if (!isEventValid(String(event)))
{
ESP_LOGW("EventSocket", "Method tried to emit unregistered event: %s", event);
ESP_LOGW(TAG, "Method tried to emit unregistered event: %s", event);
return;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ void EventSocket::emitEvent(String event, JsonObject &jsonObject, const char *or
auto *client = _socket.getClient(originSubscriptionId);
if (client)
{
ESP_LOGV("EventSocket", "Emitting event: %s to %s[%u], Message[%d]: %s", event, client->remoteIP().toString().c_str(), client->socket(), len, output);
ESP_LOGV(TAG, "Emitting event: %s to %s[%u], Message[%d]: %s", event, client->remoteIP().toString().c_str(), client->socket(), len, output);
#if FT_ENABLED(EVENT_USE_JSON)
client->sendMessage(HTTPD_WS_TYPE_TEXT, output, len);
#else
Expand All @@ -170,7 +170,7 @@ void EventSocket::emitEvent(String event, JsonObject &jsonObject, const char *or
subscriptions.remove(subscription);
continue;
}
ESP_LOGV("EventSocket", "Emitting event: %s to %s[%u], Message[%d]: %s", event, client->remoteIP().toString().c_str(), client->socket(), len, output);
ESP_LOGV(TAG, "Emitting event: %s to %s[%u], Message[%d]: %s", event, client->remoteIP().toString().c_str(), client->socket(), len, output);
#if FT_ENABLED(EVENT_USE_JSON)
client->sendMessage(HTTPD_WS_TYPE_TEXT, output, len);
#else
Expand Down Expand Up @@ -203,7 +203,7 @@ void EventSocket::onEvent(String event, EventCallback callback)
{
if (!isEventValid(event))
{
ESP_LOGW("EventSocket", "Method tried to register unregistered event: %s", event.c_str());
ESP_LOGW(TAG, "Method tried to register unregistered event: %s", event.c_str());
return;
}
event_callbacks[event].push_back(callback);
Expand All @@ -213,11 +213,11 @@ void EventSocket::onSubscribe(String event, SubscribeCallback callback)
{
if (!isEventValid(event))
{
ESP_LOGW("EventSocket", "Method tried to subscribe to unregistered event: %s", event.c_str());
ESP_LOGW(TAG, "Method tried to subscribe to unregistered event: %s", event.c_str());
return;
}
subscribe_callbacks[event].push_back(callback);
ESP_LOGI("EventSocket", "onSubscribe for event: %s", event.c_str());
ESP_LOGI(TAG, "onSubscribe for event: %s", event.c_str());
}

bool EventSocket::isEventValid(String event)
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/FactoryResetService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void FactoryResetService::begin()
HTTP_POST,
_securityManager->wrapRequest(std::bind(&FactoryResetService::handleRequest, this, _1), AuthenticationPredicates::IS_ADMIN));

ESP_LOGV("FactoryResetService", "Registered POST endpoint: %s", FACTORY_RESET_SERVICE_PATH);
ESP_LOGV(TAG, "Registered POST endpoint: %s", FACTORY_RESET_SERVICE_PATH);
}

esp_err_t FactoryResetService::handleRequest(PsychicRequest *request)
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/FeaturesService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ void FeaturesService::begin()
createJSON(root);
return response.send(); });

ESP_LOGV("FeaturesService", "Registered GET endpoint: %s", FEATURES_SERVICE_PATH);
ESP_LOGV(TAG, "Registered GET endpoint: %s", FEATURES_SERVICE_PATH);

_socket->registerEvent(FEATURES_SERVICE_EVENT);

_socket->onSubscribe(FEATURES_SERVICE_EVENT, [&](const String &originId)
{
ESP_LOGV("FeaturesService", "Sending features to %s", originId.c_str());
ESP_LOGV(TAG, "Sending features to %s", originId.c_str());
JsonDocument doc;
JsonObject root = doc.as<JsonObject>();
createJSON(root);
Expand Down
4 changes: 2 additions & 2 deletions lib/framework/HttpEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class HttpEndpoint
return response.send();
},
_authenticationPredicate));
ESP_LOGV("HttpEndpoint", "Registered GET endpoint: %s", _servicePath);
ESP_LOGV(TAG, "Registered GET endpoint: %s", _servicePath);

// POST
_server->on(_servicePath,
Expand Down Expand Up @@ -105,7 +105,7 @@ class HttpEndpoint
},
_authenticationPredicate));

ESP_LOGV("HttpEndpoint", "Registered POST endpoint: %s", _servicePath);
ESP_LOGV(TAG, "Registered POST endpoint: %s", _servicePath);
}
};

Expand Down
10 changes: 5 additions & 5 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void MqttSettingsService::onMqttConnect(bool sessionPresent)
String uri = _mqttClient.getMqttConfig()->uri;
#endif

ESP_LOGI("MQTT", "Connected to MQTT: %s", uri.c_str());
ESP_LOGI(TAG, "Connected to MQTT: %s", uri.c_str());
#ifdef SERIAL_INFO
Serial.printf("Connected to MQTT: %s\n", uri.c_str());
#endif
Expand All @@ -134,7 +134,7 @@ void MqttSettingsService::onMqttConnect(bool sessionPresent)

void MqttSettingsService::onMqttDisconnect(bool sessionPresent)
{
ESP_LOGI("MQTT", "Disconnected from MQTT.");
ESP_LOGI(TAG, "Disconnected from MQTT.");
#ifdef SERIAL_INFO
Serial.println("Disconnected from MQTT.");
#endif
Expand All @@ -145,7 +145,7 @@ void MqttSettingsService::onMqttError(esp_mqtt_error_codes_t error)
if (error.error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT)
{
_lastError = strerror(error.esp_transport_sock_errno);
ESP_LOGE("MQTT", "MQTT TCP error: %s", _lastError.c_str());
ESP_LOGE(TAG, "MQTT TCP error: %s", _lastError.c_str());
}
}

Expand All @@ -158,7 +158,7 @@ void MqttSettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t
{
if (_state.enabled)
{
ESP_LOGI("MQTT", "WiFi connection established, starting MQTT client.");
ESP_LOGI(TAG, "WiFi connection established, starting MQTT client.");
onConfigUpdated();
}
}
Expand All @@ -167,7 +167,7 @@ void MqttSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEvent
{
if (_state.enabled)
{
ESP_LOGI("MQTT", "WiFi connection dropped, stopping MQTT client.");
ESP_LOGI(TAG, "WiFi connection dropped, stopping MQTT client.");
onConfigUpdated();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/MqttStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void MqttStatus::begin()
_securityManager->wrapRequest(std::bind(&MqttStatus::mqttStatus, this, std::placeholders::_1),
AuthenticationPredicates::IS_AUTHENTICATED));

ESP_LOGV("MqttStatus", "Registered GET endpoint: %s", MQTT_STATUS_SERVICE_PATH);
ESP_LOGV(TAG, "Registered GET endpoint: %s", MQTT_STATUS_SERVICE_PATH);
}

esp_err_t MqttStatus::mqttStatus(PsychicRequest *request)
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/NTPSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void NTPSettingsService::begin()
std::bind(&NTPSettingsService::configureTime, this, std::placeholders::_1, std::placeholders::_2),
AuthenticationPredicates::IS_ADMIN));

ESP_LOGV("NTPSettingsService", "Registered POST endpoint: %s", TIME_PATH);
ESP_LOGV(TAG, "Registered POST endpoint: %s", TIME_PATH);

_fsPersistence.readFromFS();
configureNTP();
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/NTPStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void NTPStatus::begin()
_securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1),
AuthenticationPredicates::IS_AUTHENTICATED));

ESP_LOGV("NTPStatus", "Registered GET endpoint: %s", NTP_STATUS_SERVICE_PATH);
ESP_LOGV(TAG, "Registered GET endpoint: %s", NTP_STATUS_SERVICE_PATH);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/RestartService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void RestartService::begin()
_securityManager->wrapRequest(std::bind(&RestartService::restart, this, std::placeholders::_1),
AuthenticationPredicates::IS_ADMIN));

ESP_LOGV("RestartService", "Registered POST endpoint: %s", RESTART_SERVICE_PATH);
ESP_LOGV(TAG, "Registered POST endpoint: %s", RESTART_SERVICE_PATH);
}

esp_err_t RestartService::restart(PsychicRequest *request)
Expand Down
Loading