System status esp + svelte - protobuf complete
This commit is contained in:
+14
-6
@@ -46,9 +46,6 @@ void setupServer() {
|
||||
server.config.max_uri_handlers = 50 + WWW_ASSETS_COUNT;
|
||||
server.maxUploadSize = 1000000; // 1 MB;
|
||||
server.listen(80);
|
||||
server.on("/api/features", feature_service::getFeatures);
|
||||
server.on("/api/system/status", HTTP_GET,
|
||||
[&](PsychicRequest *request) { return system_service::getStatus(request); });
|
||||
server.on("/api/system/reset", HTTP_POST,
|
||||
[&](PsychicRequest *request, JsonVariant &json) { return system_service::handleReset(request); });
|
||||
server.on("/api/system/restart", HTTP_POST,
|
||||
@@ -162,22 +159,33 @@ void setupEventSocket() {
|
||||
using CorrelationHandler =
|
||||
std::function<void(const socket_message_CorrelationRequest &, socket_message_CorrelationResponse &)>;
|
||||
static std::map<pb_size_t, CorrelationHandler> correlationHandlers = {
|
||||
{socket_message_CorrelationRequest_features_data_request_tag,
|
||||
{socket_message_CorrelationRequest_features_data_request_tag, // Features data
|
||||
[](const auto &req, auto &res) {
|
||||
res.which_response = socket_message_CorrelationResponse_features_data_response_tag;
|
||||
feature_service::features_request(req.request.features_data_request, res.response.features_data_response);
|
||||
}},
|
||||
{socket_message_CorrelationRequest_i2c_scan_data_request_tag,
|
||||
|
||||
{socket_message_CorrelationRequest_i2c_scan_data_request_tag, // i2c data
|
||||
[](const auto &req, auto &res) {
|
||||
res.which_response = socket_message_CorrelationResponse_i2c_scan_data_tag;
|
||||
peripherals.scanI2C();
|
||||
peripherals.getI2CScanProto(res.response.i2c_scan_data);
|
||||
}},
|
||||
{socket_message_CorrelationRequest_imu_calibrate_execute_tag,
|
||||
|
||||
{socket_message_CorrelationRequest_imu_calibrate_execute_tag, // Calibration request
|
||||
[](const auto &req, auto &res) {
|
||||
res.which_response = socket_message_CorrelationResponse_imu_calibrate_data_tag;
|
||||
res.response.imu_calibrate_data.success = peripherals.calibrateIMU();
|
||||
}},
|
||||
|
||||
{socket_message_CorrelationRequest_system_information_request_tag, // All system information data
|
||||
[](const auto &req, auto &res) {
|
||||
res.which_response = socket_message_CorrelationResponse_system_information_response_tag;
|
||||
res.response.system_information_response.has_analytics_data = true;
|
||||
res.response.system_information_response.has_static_system_information = true;
|
||||
system_service::getAnalytics(res.response.system_information_response.analytics_data);
|
||||
system_service::getStaticSystemInformation(res.response.system_information_response.static_system_information);
|
||||
}},
|
||||
};
|
||||
|
||||
socket.on<socket_message_CorrelationRequest>([&](const socket_message_CorrelationRequest &data, int clientId) {
|
||||
|
||||
@@ -19,12 +19,7 @@ esp_err_t handleSleep(PsychicRequest *request) {
|
||||
return request->reply(200);
|
||||
}
|
||||
|
||||
esp_err_t getStatus(PsychicRequest *request) {
|
||||
PsychicJsonResponse response = PsychicJsonResponse(request, false);
|
||||
JsonObject root = response.getRoot();
|
||||
status(root);
|
||||
return response.send();
|
||||
}
|
||||
|
||||
|
||||
void reset() {
|
||||
ESP_LOGI(TAG, "Resetting device");
|
||||
@@ -78,32 +73,25 @@ void sleep() {
|
||||
ESP_LOGI(TAG, "Setting device to sleep");
|
||||
}
|
||||
|
||||
void status(JsonObject &root) {
|
||||
|
||||
|
||||
void getStaticSystemInformation(socket_message_StaticSystemInformation &info) {
|
||||
size_t fs_total = 0, fs_used = 0;
|
||||
esp_littlefs_info("spiffs", &fs_total, &fs_used);
|
||||
|
||||
root["esp_platform"] = ESP_PLATFORM;
|
||||
root["firmware_version"] = APP_VERSION;
|
||||
root["max_alloc_heap"] = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
|
||||
root["psram_size"] = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
|
||||
root["free_psram"] = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
|
||||
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
|
||||
root["cpu_type"] = ESP.getChipModel();
|
||||
root["cpu_rev"] = ESP.getChipRevision();
|
||||
root["cpu_cores"] = ESP.getChipCores();
|
||||
root["free_heap"] = esp_get_free_heap_size();
|
||||
root["min_free_heap"] = esp_get_minimum_free_heap_size();
|
||||
root["sketch_size"] = ESP.getSketchSize();
|
||||
root["free_sketch_space"] = ESP.getFreeSketchSpace();
|
||||
root["sdk_version"] = ESP.getSdkVersion();
|
||||
root["arduino_version"] = ARDUINO_VERSION;
|
||||
root["flash_chip_size"] = ESP.getFlashChipSize();
|
||||
root["flash_chip_speed"] = ESP.getFlashChipSpeed();
|
||||
root["fs_total"] = fs_total;
|
||||
root["fs_used"] = fs_used;
|
||||
root["core_temp"] = temperatureRead();
|
||||
root["cpu_reset_reason"] = resetReason(esp_reset_reason());
|
||||
root["uptime"] = esp_timer_get_time() / 1000000;
|
||||
info.esp_platform = (char*) ESP_PLATFORM_NAME;
|
||||
info.firmware_version = APP_VERSION;
|
||||
info.cpu_freq_mhz = ESP.getCpuFreqMHz();
|
||||
info.cpu_type = (char*) ESP.getChipModel();
|
||||
info.cpu_rev = ESP.getChipRevision();
|
||||
info.cpu_cores = ESP.getChipCores();
|
||||
info.sketch_size = ESP.getSketchSize();
|
||||
info.free_sketch_space = ESP.getFreeSketchSpace();
|
||||
info.sdk_version = (char*) ESP.getSdkVersion();
|
||||
info.arduino_version = ARDUINO_VERSION;
|
||||
info.flash_chip_size = ESP.getFlashChipSize();
|
||||
info.flash_chip_speed = ESP.getFlashChipSpeed();
|
||||
info.cpu_reset_reason = (char*) resetReason(esp_reset_reason());
|
||||
}
|
||||
|
||||
void getAnalytics(socket_message_AnalyticsData &analytics) {
|
||||
|
||||
Reference in New Issue
Block a user