feat: change icon and display, add time
This commit is contained in:
@ -16,9 +16,43 @@
|
||||
#include <driver/gpio.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <font_awesome.h>
|
||||
#include <lwip/apps/sntp.h>
|
||||
#include <time.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#define TAG "Application"
|
||||
|
||||
namespace {
|
||||
constexpr const char* kDirectWebsocketUrl = "ws://172.19.0.240:8080";
|
||||
constexpr int kDirectWebsocketVersion = 3;
|
||||
constexpr bool kUseDirectWebsocketWithoutOta = true;
|
||||
|
||||
void StartDirectTimeSync() {
|
||||
setenv("TZ", "CST-8", 1);
|
||||
tzset();
|
||||
|
||||
static bool sntp_started = false;
|
||||
if (sntp_started) {
|
||||
return;
|
||||
}
|
||||
sntp_started = true;
|
||||
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
sntp_setservername(0, "ntp.aliyun.com");
|
||||
sntp_init();
|
||||
}
|
||||
|
||||
void ConfigureDirectWebsocket() {
|
||||
Settings settings("websocket", true);
|
||||
if (settings.GetString("url") != kDirectWebsocketUrl) {
|
||||
settings.SetString("url", kDirectWebsocketUrl);
|
||||
}
|
||||
if (settings.GetInt("version") != kDirectWebsocketVersion) {
|
||||
settings.SetInt("version", kDirectWebsocketVersion);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
Application::Application() {
|
||||
event_group_ = xEventGroupCreate();
|
||||
@ -324,6 +358,16 @@ void Application::ActivationTask() {
|
||||
// Create OTA object for activation process
|
||||
ota_ = std::make_unique<Ota>();
|
||||
|
||||
if (kUseDirectWebsocketWithoutOta) {
|
||||
ConfigureDirectWebsocket();
|
||||
StartDirectTimeSync();
|
||||
ESP_LOGI(TAG, "Using direct websocket without OTA: %s", kDirectWebsocketUrl);
|
||||
CheckAssetsVersion();
|
||||
InitializeProtocol();
|
||||
xEventGroupSetBits(event_group_, MAIN_EVENT_ACTIVATION_DONE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for new assets version
|
||||
CheckAssetsVersion();
|
||||
|
||||
@ -477,9 +521,12 @@ void Application::InitializeProtocol() {
|
||||
|
||||
display->SetStatus(Lang::Strings::LOADING_PROTOCOL);
|
||||
|
||||
Settings websocket_settings("websocket", false);
|
||||
bool has_direct_websocket_config = !websocket_settings.GetString("url").empty();
|
||||
|
||||
if (ota_->HasMqttConfig()) {
|
||||
protocol_ = std::make_unique<MqttProtocol>();
|
||||
} else if (ota_->HasWebsocketConfig()) {
|
||||
} else if (ota_->HasWebsocketConfig() || has_direct_websocket_config) {
|
||||
protocol_ = std::make_unique<WebsocketProtocol>();
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No protocol specified in the OTA config, using MQTT");
|
||||
@ -1116,4 +1163,3 @@ void Application::ResetProtocol() {
|
||||
protocol_.reset();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user