MCPcopy Create free account
hub / github.com/bmorcelli/Launcher / nvsHandler

Function nvsHandler

src/webInterface.cpp:719–876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

717}
718
719esp_err_t nvsHandler(httpd_req_t *req) {
720 if (!checkUserWebAuth(req)) return ESP_OK;
721
722 if (req->method == HTTP_GET) {
723 JsonDocument doc;
724
725 nvs_iterator_t it = nullptr;
726 esp_err_t res = nvs_entry_find("nvs", nullptr, NVS_TYPE_ANY, &it);
727
728 nvs_handle_t h = 0;
729 char curNs[16] = "";
730
731 while (res == ESP_OK && it != nullptr) {
732 nvs_entry_info_t info;
733 nvs_entry_info(it, &info);
734
735 bool skip = (info.type == NVS_TYPE_BLOB) ||
736 (strcmp(info.namespace_name, "launcher") == 0 && strcmp(info.key, "token") == 0);
737
738 if (!skip) {
739 if (strcmp(curNs, info.namespace_name) != 0) {
740 if (h) {
741 nvs_close(h);
742 h = 0;
743 }
744 nvs_open(info.namespace_name, NVS_READONLY, &h);
745 strncpy(curNs, info.namespace_name, sizeof(curNs) - 1);
746 }
747 if (h) {
748 if (!doc[info.namespace_name].is<JsonArray>()) doc[info.namespace_name].to<JsonArray>();
749 JsonObject field = doc[info.namespace_name].as<JsonArray>().add<JsonObject>();
750 field["k"] = info.key;
751 switch (info.type) {
752 case NVS_TYPE_U8: {
753 uint8_t v = 0;
754 nvs_get_u8(h, info.key, &v);
755 field["t"] = "u8";
756 field["v"] = v;
757 break;
758 }
759 case NVS_TYPE_I8: {
760 int8_t v = 0;
761 nvs_get_i8(h, info.key, &v);
762 field["t"] = "i8";
763 field["v"] = v;
764 break;
765 }
766 case NVS_TYPE_U16: {
767 uint16_t v = 0;
768 nvs_get_u16(h, info.key, &v);
769 field["t"] = "u16";
770 field["v"] = v;
771 break;
772 }
773 case NVS_TYPE_I16: {
774 int16_t v = 0;
775 nvs_get_i16(h, info.key, &v);
776 field["t"] = "i16";

Callers

nothing calls this directly

Calls 5

checkUserWebAuthFunction · 0.85
sendTextFunction · 0.85
receiveBodyFunction · 0.85
getFromNVSFunction · 0.85
getWifiFromNVSFunction · 0.85

Tested by

no test coverage detected