mirror of
https://github.com/esphome/esphome.git
synced 2026-02-13 19:21:55 +00:00
Compare commits
2 Commits
dev
...
web_server
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14b42d5997 | ||
|
|
4db761ef03 |
@@ -15,6 +15,8 @@
|
|||||||
#include "StreamString.h"
|
#include "StreamString.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <cinttypes>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#ifdef USE_LIGHT
|
#ifdef USE_LIGHT
|
||||||
@@ -365,7 +367,13 @@ void WebServer::set_css_include(const char *css_include) { this->css_include_ =
|
|||||||
void WebServer::set_js_include(const char *js_include) { this->js_include_ = js_include; }
|
void WebServer::set_js_include(const char *js_include) { this->js_include_ = js_include; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string WebServer::get_config_json() {
|
/// Get uptime in milliseconds using std::chrono::steady_clock (64-bit, no rollover)
|
||||||
|
static int64_t get_uptime_ms() {
|
||||||
|
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch())
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
json::SerializationBuffer<> WebServer::get_config_json() {
|
||||||
json::JsonBuilder builder;
|
json::JsonBuilder builder;
|
||||||
JsonObject root = builder.root();
|
JsonObject root = builder.root();
|
||||||
|
|
||||||
@@ -380,6 +388,7 @@ std::string WebServer::get_config_json() {
|
|||||||
#endif
|
#endif
|
||||||
root[ESPHOME_F("log")] = this->expose_log_;
|
root[ESPHOME_F("log")] = this->expose_log_;
|
||||||
root[ESPHOME_F("lang")] = "en";
|
root[ESPHOME_F("lang")] = "en";
|
||||||
|
root[ESPHOME_F("uptime")] = get_uptime_ms();
|
||||||
|
|
||||||
return builder.serialize();
|
return builder.serialize();
|
||||||
}
|
}
|
||||||
@@ -403,7 +412,11 @@ void WebServer::setup() {
|
|||||||
|
|
||||||
// doesn't need defer functionality - if the queue is full, the client JS knows it's alive because it's clearly
|
// doesn't need defer functionality - if the queue is full, the client JS knows it's alive because it's clearly
|
||||||
// getting a lot of events
|
// getting a lot of events
|
||||||
this->set_interval(10000, [this]() { this->events_.try_send_nodefer("", "ping", millis(), 30000); });
|
this->set_interval(10000, [this]() {
|
||||||
|
char buf[32];
|
||||||
|
buf_append_printf(buf, sizeof(buf), 0, "{\"uptime\":%" PRId64 "}", get_uptime_ms());
|
||||||
|
this->events_.try_send_nodefer(buf, "ping", millis(), 30000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
void WebServer::loop() { this->events_.loop(); }
|
void WebServer::loop() { this->events_.loop(); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user