Просмотр исходного кода

Merge flip_store from https://github.com/jblanked/FlipStore

Willy-JL 1 год назад
Родитель
Сommit
b3da7acbde

BIN
flip_store/.DS_Store


+ 1 - 1
flip_store/README.md

@@ -20,7 +20,7 @@ Download Flipper Zero apps directly to your Flipper Zero using WiFi. You no long
 - App Categories
 
 **v0.3**
-- Caching
+- Improved memory allocation
 - Stability Patch 2
 - App Catalog Patch (add in required functionalility)
 

+ 3 - 7
flip_store/flip_store_i.h → flip_store/alloc/flip_store_alloc.c

@@ -1,8 +1,6 @@
-#ifndef FLIP_STORE_I_H
-#define FLIP_STORE_I_H
-
+#include <alloc/flip_store_alloc.h>
 // Function to allocate resources for the FlipStoreApp
-static FlipStoreApp* flip_store_app_alloc() {
+FlipStoreApp* flip_store_app_alloc() {
     FlipStoreApp* app = (FlipStoreApp*)malloc(sizeof(FlipStoreApp));
 
     Gui* gui = furi_record_open(RECORD_GUI);
@@ -151,7 +149,7 @@ static FlipStoreApp* flip_store_app_alloc() {
     if(!easy_flipper_set_submenu(
            &app->submenu,
            FlipStoreViewSubmenu,
-           "FlipStore",
+           "FlipStore v0.3",
            callback_exit_app,
            &app->view_dispatcher)) {
         return NULL;
@@ -364,5 +362,3 @@ static FlipStoreApp* flip_store_app_alloc() {
 
     return app;
 }
-
-#endif // FLIP_STORE_I_H

+ 10 - 0
flip_store/alloc/flip_store_alloc.h

@@ -0,0 +1,10 @@
+#ifndef FLIP_STORE_I_H
+#define FLIP_STORE_I_H
+
+#include <flip_store.h>
+#include <callback/flip_store_callback.h>
+
+// Function to allocate resources for the FlipStoreApp
+FlipStoreApp* flip_store_app_alloc();
+
+#endif // FLIP_STORE_I_H

+ 2 - 5
flip_store/app.c

@@ -1,8 +1,5 @@
-#include <flip_store_e.h>
-#include <flip_store_storage.h>
-#include <flip_store_callback.h>
-#include <flip_store_i.h>
-#include <flip_store_free.h>
+#include <flip_store.h>
+#include <alloc/flip_store_alloc.h>
 
 // Entry point for the Hello World application
 int32_t main_flip_store(void* p) {

+ 1 - 1
flip_store/application.fam

@@ -10,5 +10,5 @@ App(
     fap_description="Download apps via WiFi directly to your Flipper Zero",
     fap_author="JBlanked",
     fap_weburl="https://github.com/jblanked/FlipStore",
-    fap_version="0.2",
+    fap_version="0.3",
 )

+ 113 - 118
flip_store/flip_store_apps.h → flip_store/apps/flip_store_apps.c

@@ -1,60 +1,62 @@
-#ifndef FLIP_STORE_APPS_H
-#define FLIP_STORE_APPS_H
-
-// Define maximum limits
-#define MAX_APP_NAME_LENGTH 32
-#define MAX_ID_LENGTH       32
-#define MAX_APP_COUNT       100
-
-typedef struct {
-    char app_name[MAX_APP_NAME_LENGTH];
-    char app_id[MAX_APP_NAME_LENGTH];
-    char app_build_id[MAX_ID_LENGTH];
-} FlipStoreAppInfo;
-
-static FlipStoreAppInfo* flip_catalog = NULL;
-
-static uint32_t app_selected_index = 0;
-static bool flip_store_sent_request = false;
-static bool flip_store_success = false;
-static bool flip_store_saved_data = false;
-static bool flip_store_saved_success = false;
-static uint32_t flip_store_category_index = 0;
-
-enum ObjectState {
-    OBJECT_EXPECT_KEY,
-    OBJECT_EXPECT_COLON,
-    OBJECT_EXPECT_VALUE,
-    OBJECT_EXPECT_COMMA_OR_END
-};
-
-static void flip_catalog_free() {
-    if(flip_catalog) {
-        free(flip_catalog);
-        flip_catalog = NULL;
+#include <apps/flip_store_apps.h>
+
+FlipStoreAppInfo* flip_catalog = NULL;
+
+uint32_t app_selected_index = 0;
+bool flip_store_sent_request = false;
+bool flip_store_success = false;
+bool flip_store_saved_data = false;
+bool flip_store_saved_success = false;
+uint32_t flip_store_category_index = 0;
+
+FlipStoreAppInfo* flip_catalog_alloc() {
+    FlipStoreAppInfo* app_catalog =
+        (FlipStoreAppInfo*)malloc(MAX_APP_COUNT * sizeof(FlipStoreAppInfo));
+    if(!app_catalog) {
+        FURI_LOG_E(TAG, "Failed to allocate memory for flip_catalog.");
+        return NULL;
+    }
+    for(int i = 0; i < MAX_APP_COUNT; i++) {
+        app_catalog[i].app_name = (char*)malloc(MAX_APP_NAME_LENGTH * sizeof(char));
+        if(!app_catalog[i].app_name) {
+            FURI_LOG_E(TAG, "Failed to allocate memory for app_name.");
+            return NULL;
+        }
+        app_catalog[i].app_id = (char*)malloc(MAX_APP_NAME_LENGTH * sizeof(char));
+        if(!app_catalog[i].app_id) {
+            FURI_LOG_E(TAG, "Failed to allocate memory for app_id.");
+            return NULL;
+        }
+        app_catalog[i].app_build_id = (char*)malloc(MAX_ID_LENGTH * sizeof(char));
+        if(!app_catalog[i].app_build_id) {
+            FURI_LOG_E(TAG, "Failed to allocate memory for app_build_id.");
+            return NULL;
+        }
     }
+    return app_catalog;
 }
-
-static bool flip_catalog_alloc() {
+void flip_catalog_free() {
     if(!flip_catalog) {
-        flip_catalog = (FlipStoreAppInfo*)malloc(MAX_APP_COUNT * sizeof(FlipStoreAppInfo));
+        return;
     }
-    if(!flip_catalog) {
-        FURI_LOG_E(TAG, "Failed to allocate memory for flip_catalog.");
-        return false;
+    for(int i = 0; i < MAX_APP_COUNT; i++) {
+        if(flip_catalog[i].app_name) {
+            free(flip_catalog[i].app_name);
+        }
+        if(flip_catalog[i].app_id) {
+            free(flip_catalog[i].app_id);
+        }
+        if(flip_catalog[i].app_build_id) {
+            free(flip_catalog[i].app_build_id);
+        }
     }
-    return true;
 }
 
 // Utility function to parse JSON incrementally from a file
-static bool flip_store_process_app_list(const char* file_path) {
-    if(file_path == NULL) {
-        FURI_LOG_E(TAG, "JSON file path is NULL.");
-        return false;
-    }
-
+bool flip_store_process_app_list() {
     // initialize the flip_catalog
-    if(!flip_catalog_alloc()) {
+    flip_catalog = flip_catalog_alloc();
+    if(!flip_catalog) {
         FURI_LOG_E(TAG, "Failed to allocate memory for flip_catalog.");
         return false;
     }
@@ -100,7 +102,7 @@ static bool flip_store_process_app_list(const char* file_path) {
         return false;
     }
 
-    if(!storage_file_open(_file, file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
+    if(!storage_file_open(_file, fhttp.file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
         FURI_LOG_E(TAG, "Failed to open JSON file for reading.");
         storage_file_free(_file);
         furi_record_close(RECORD_STORAGE);
@@ -170,25 +172,25 @@ static bool flip_store_process_app_list(const char* file_path) {
 
                         if(inside_app_object) {
                             if(strcmp(current_key, "name") == 0) {
-                                strncpy(
+                                snprintf(
                                     flip_catalog[app_count].app_name,
-                                    current_value,
-                                    MAX_APP_NAME_LENGTH - 1);
-                                flip_catalog[app_count].app_name[MAX_APP_NAME_LENGTH - 1] = '\0';
+                                    MAX_APP_NAME_LENGTH,
+                                    "%.31s",
+                                    current_value);
                                 found_name = true;
                             } else if(strcmp(current_key, "id") == 0) {
-                                strncpy(
+                                snprintf(
                                     flip_catalog[app_count].app_id,
-                                    current_value,
-                                    MAX_APP_NAME_LENGTH - 1);
-                                flip_catalog[app_count].app_id[MAX_APP_NAME_LENGTH - 1] = '\0';
+                                    MAX_ID_LENGTH,
+                                    "%.31s",
+                                    current_value);
                                 found_id = true;
                             } else if(strcmp(current_key, "build_id") == 0) {
-                                strncpy(
+                                snprintf(
                                     flip_catalog[app_count].app_build_id,
-                                    current_value,
-                                    MAX_APP_NAME_LENGTH - 1);
-                                flip_catalog[app_count].app_build_id[MAX_ID_LENGTH - 1] = '\0';
+                                    MAX_ID_LENGTH,
+                                    "%.31s",
+                                    current_value);
                                 found_build_id = true;
                             }
 
@@ -271,20 +273,17 @@ static bool flip_store_process_app_list(const char* file_path) {
     storage_file_free(_file);
     furi_record_close(RECORD_STORAGE);
 
-    if(app_count == 0) {
-        FURI_LOG_E(TAG, "No valid apps were parsed.");
-        return false;
-    }
-    return true;
+    return app_count > 0;
 }
 
-static bool flip_store_get_fap_file(
+bool flip_store_get_fap_file(
     char* build_id,
     uint8_t target,
     uint16_t api_major,
     uint16_t api_minor) {
-    is_compile_app_request = true;
-    char url[164];
+    char url[128];
+    fhttp.save_received_data = false;
+    fhttp.is_bytes_request = true;
     snprintf(
         url,
         sizeof(url),
@@ -299,40 +298,34 @@ static bool flip_store_get_fap_file(
     return sent_request;
 }
 
-static void flip_store_request_error(Canvas* canvas) {
-    if(fhttp.received_data == NULL) {
-        if(fhttp.last_response != NULL) {
-            if(strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") !=
-               NULL) {
-                canvas_clear(canvas);
-                canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
-                canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
-                canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            } else if(strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL) {
-                canvas_clear(canvas);
-                canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
-                canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
-                canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            } else {
-                FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
-                canvas_draw_str(canvas, 0, 42, "Unusual error...");
-                canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
-                canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
-            }
-        } else {
+void flip_store_request_error(Canvas* canvas) {
+    if(fhttp.last_response != NULL) {
+        if(strstr(fhttp.last_response, "[ERROR] Not connected to Wifi. Failed to reconnect.") !=
+           NULL) {
+            canvas_clear(canvas);
+            canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
+            canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
+            canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
+        } else if(strstr(fhttp.last_response, "[ERROR] Failed to connect to Wifi.") != NULL) {
             canvas_clear(canvas);
-            canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
+            canvas_draw_str(canvas, 0, 10, "[ERROR] Not connected to Wifi.");
+            canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
+            canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
+        } else {
+            FURI_LOG_E(TAG, "Received an error: %s", fhttp.last_response);
+            canvas_draw_str(canvas, 0, 42, "Unusual error...");
             canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
             canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
         }
     } else {
         canvas_clear(canvas);
-        canvas_draw_str(canvas, 0, 10, "Failed to receive data.");
+        canvas_draw_str(canvas, 0, 10, "[ERROR] Unknown error.");
+        canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
         canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
     }
 }
 // function to handle the entire installation process "asynchronously"
-static bool flip_store_install_app(Canvas* canvas, char* category) {
+bool flip_store_install_app(Canvas* canvas, char* category) {
     // create /apps/FlipStore directory if it doesn't exist
     char directory_path[128];
     snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps/%s", category);
@@ -342,17 +335,18 @@ static bool flip_store_install_app(Canvas* canvas, char* category) {
     storage_common_mkdir(storage, directory_path);
 
     // Adjusted to access flip_catalog as an array of structures
-    char* app_name = flip_catalog[app_selected_index].app_name;
-    char installing_text[128];
-    snprintf(installing_text, sizeof(installing_text), "Installing %s", app_name);
-    char bin_path[256];
+    char installing_text[64];
     snprintf(
-        bin_path,
-        sizeof(bin_path),
+        installing_text,
+        sizeof(installing_text),
+        "Installing %s",
+        flip_catalog[app_selected_index].app_name);
+    snprintf(
+        fhttp.file_path,
+        sizeof(fhttp.file_path),
         STORAGE_EXT_PATH_PREFIX "/apps/%s/%s.fap",
         category,
         flip_catalog[app_selected_index].app_id);
-    strncpy(fhttp.file_path, bin_path, sizeof(fhttp.file_path) - 1);
     canvas_draw_str(canvas, 0, 10, installing_text);
     canvas_draw_str(canvas, 0, 20, "Sending request..");
     uint8_t target = furi_hal_version_get_hw_target();
@@ -375,7 +369,7 @@ static bool flip_store_install_app(Canvas* canvas, char* category) {
         furi_delay_ms(10);
     }
     // furi_timer_stop(fhttp.get_timeout_timer);
-    if(fhttp.state == ISSUE || fhttp.received_data == NULL) {
+    if(fhttp.state == ISSUE) {
         flip_store_request_error(canvas);
         flip_store_success = false;
         return false;
@@ -385,32 +379,38 @@ static bool flip_store_install_app(Canvas* canvas, char* category) {
 }
 
 // process the app list and return view
-static int32_t flip_store_handle_app_list(
+int32_t flip_store_handle_app_list(
     FlipStoreApp* app,
     int32_t success_view,
     char* category,
     Submenu** submenu) {
     // reset the flip_catalog
-    if(flip_catalog) {
-        flip_catalog_free();
-    }
+    flip_catalog_free();
 
     if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return FlipStoreViewPopup;
     }
     char url[128];
-    is_compile_app_request = false;
-    // append the category to the end of the url
+    snprintf(
+        fhttp.file_path,
+        sizeof(fhttp.file_path),
+        STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/apps.txt");
+
+    fhttp.save_received_data = true;
+    fhttp.is_bytes_request = false;
     snprintf(
         url, sizeof(url), "https://www.flipsocial.net/api/flipper/apps/%s/extended/", category);
+    char* headers = jsmn("Content-Type", "application/json");
     // async call to the app list with timer
-    if(fhttp.state != INACTIVE &&
-       flipper_http_get_request_with_headers(url, jsmn("Content-Type", "application/json"))) {
+    if(fhttp.state != INACTIVE && flipper_http_get_request_with_headers(url, headers)) {
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+        free(headers);
         fhttp.state = RECEIVING;
     } else {
         FURI_LOG_E(TAG, "Failed to send the request");
+        free(headers);
+        fhttp.state = ISSUE;
         return FlipStoreViewPopup;
     }
     while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
@@ -418,9 +418,9 @@ static int32_t flip_store_handle_app_list(
         furi_delay_ms(100);
     }
     furi_timer_stop(fhttp.get_timeout_timer);
-    if(fhttp.state == ISSUE || fhttp.received_data == NULL) {
-        if(fhttp.received_data == NULL) {
-            FURI_LOG_E(TAG, "Failed to receive data");
+    if(fhttp.state == ISSUE) {
+        FURI_LOG_E(TAG, "Failed to receive data");
+        if(fhttp.last_response == NULL) {
             if(fhttp.last_response != NULL) {
                 if(strstr(
                        fhttp.last_response,
@@ -454,15 +454,12 @@ static int32_t flip_store_handle_app_list(
             }
             return FlipStoreViewPopup;
         } else {
-            FURI_LOG_E(TAG, "Failed to receive data");
             popup_set_text(app->popup, "Failed to received data.", 0, 10, AlignLeft, AlignTop);
             return FlipStoreViewPopup;
         }
     } else {
         // process the app list
-        const char* output_file_path = STORAGE_EXT_PATH_PREFIX "/apps_data/" http_tag
-                                                               "/received_data.txt";
-        if(flip_store_process_app_list(output_file_path)) {
+        if(flip_store_process_app_list()) {
             submenu_reset(*submenu);
             // add each app name to submenu
             for(int i = 0; i < MAX_APP_COUNT; i++) {
@@ -484,5 +481,3 @@ static int32_t flip_store_handle_app_list(
         }
     }
 }
-
-#endif // FLIP_STORE_APPS_H

+ 60 - 0
flip_store/apps/flip_store_apps.h

@@ -0,0 +1,60 @@
+#ifndef FLIP_STORE_APPS_H
+#define FLIP_STORE_APPS_H
+
+#include <flip_store.h>
+#include <flip_storage/flip_store_storage.h>
+#include <callback/flip_store_callback.h>
+
+// Define maximum limits
+#define MAX_APP_NAME_LENGTH 32
+#define MAX_ID_LENGTH       32
+#define MAX_APP_COUNT       100
+
+typedef struct {
+    char* app_name;
+    char* app_id;
+    char* app_build_id;
+} FlipStoreAppInfo;
+
+extern FlipStoreAppInfo* flip_catalog;
+
+extern uint32_t app_selected_index;
+extern bool flip_store_sent_request;
+extern bool flip_store_success;
+extern bool flip_store_saved_data;
+extern bool flip_store_saved_success;
+extern uint32_t flip_store_category_index;
+
+enum ObjectState {
+    OBJECT_EXPECT_KEY,
+    OBJECT_EXPECT_COLON,
+    OBJECT_EXPECT_VALUE,
+    OBJECT_EXPECT_COMMA_OR_END
+};
+
+FlipStoreAppInfo* flip_catalog_alloc();
+
+void flip_catalog_free();
+
+// Utility function to parse JSON incrementally from a file
+bool flip_store_process_app_list();
+
+bool flip_store_get_fap_file(
+    char* build_id,
+    uint8_t target,
+    uint16_t api_major,
+    uint16_t api_minor);
+
+void flip_store_request_error(Canvas* canvas);
+
+// function to handle the entire installation process "asynchronously"
+bool flip_store_install_app(Canvas* canvas, char* category);
+
+// process the app list and return view
+int32_t flip_store_handle_app_list(
+    FlipStoreApp* app,
+    int32_t success_view,
+    char* category,
+    Submenu** submenu);
+
+#endif // FLIP_STORE_APPS_H

BIN
flip_store/assets/01-main-menu.png


BIN
flip_store/assets/01-main.png


BIN
flip_store/assets/02-catalog.png


+ 0 - 0
flip_store/assets/02-list.png → flip_store/assets/03-list.png


BIN
flip_store/assets/04-app-folder.png


+ 0 - 0
flip_store/assets/03-success.png → flip_store/assets/04-success.png


+ 5 - 1
flip_store/assets/CHANGELOG.md

@@ -1,5 +1,9 @@
+## v0.3
+- Edits by Willy-JL
+- Improved memory allocation
+- Stability Patch
+
 ## v0.2
-- Refactored using the Easy Flipper library.
 - Added categories: Users can now navigate through categories, and when FlipStore installs a selected app, it will download directly to the corresponding category's folder in the apps directory.
 - Improved memory allocation to prevent "Out of Memory" warnings
 - Updated installation messages

+ 6 - 7
flip_store/assets/README.md

@@ -10,7 +10,7 @@ Download Flipper Zero apps directly to your Flipper Zero using WiFi. You no long
 - Install Official Firmware (coming soon)
 
 ## Installation
-1. Flash your WiFi Devboard: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
+1. Flash your WiFi Devboard: https://github.com/jblanked/FlipperHTTP
 2. Install the app.
 3. Enjoy :D
 
@@ -20,7 +20,8 @@ Download Flipper Zero apps directly to your Flipper Zero using WiFi. You no long
 - App Categories
 
 **v0.3**
-- Caching
+- Improved memory allocation
+- Stability Patch 2
 - App Catalog Patch (add in required functionalility)
 
 **v0.4**
@@ -46,9 +47,7 @@ Download Flipper Zero apps directly to your Flipper Zero using WiFi. You no long
 This is a big task, and I welcome all contributors, especially developers interested in animations and graphics. Fork the repository, create a pull request, and I will review your edits.
 
 ## Known Bugs
-1. When clicking the Catalog, I get an "out of memory" error.
-   - This has been addressed but may still occur. If it does, just restart the app.
+1. Clicking the catalog results in an "Out of Memory" error.
+   - This issue has been addressed, but it may still occur. If it does, restart the app.
 2. The app file is corrupted.
-   - It's likely there was an error parsing the data. Restart the app and wait until the green LED light turns off after downloading the app before exiting the view.
-3. The app is stuck on "receiving".
-   - Restart your Flipper Zero with your WiFi Devboard plugged in.
+   - This is likely due to an error parsing the data. Restart the app and wait until the green LED light turns off after downloading the app before exiting the view. If this happens more than three times, the current version of FlipStore may not be able to download that app successfully.

+ 11 - 21
flip_store/flip_store_callback.h → flip_store/callback/flip_store_callback.c

@@ -1,15 +1,7 @@
-#ifndef FLIP_STORE_CALLBACK_H
-#define FLIP_STORE_CALLBACK_H
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <stdbool.h>
-#include <flip_store_apps.h>
-#include "flip_store_icons.h"
+#include <callback/flip_store_callback.h>
 
 // Callback for drawing the main screen
-static void flip_store_view_draw_callback_main(Canvas* canvas, void* model) {
+void flip_store_view_draw_callback_main(Canvas* canvas, void* model) {
     UNUSED(model);
     canvas_set_font(canvas, FontSecondary);
 
@@ -51,7 +43,7 @@ static void flip_store_view_draw_callback_main(Canvas* canvas, void* model) {
     }
 }
 
-static void flip_store_view_draw_callback_app_list(Canvas* canvas, void* model) {
+void flip_store_view_draw_callback_app_list(Canvas* canvas, void* model) {
     UNUSED(model);
     canvas_clear(canvas);
     canvas_set_font(canvas, FontPrimary);
@@ -65,7 +57,7 @@ static void flip_store_view_draw_callback_app_list(Canvas* canvas, void* model)
     canvas_draw_str_aligned(canvas, 97, 54, AlignLeft, AlignTop, "Install");
 }
 
-static bool flip_store_input_callback(InputEvent* event, void* context) {
+bool flip_store_input_callback(InputEvent* event, void* context) {
     FlipStoreApp* app = (FlipStoreApp*)context;
     if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
@@ -95,7 +87,7 @@ static bool flip_store_input_callback(InputEvent* event, void* context) {
     return false;
 }
 
-static void flip_store_text_updated_ssid(void* context) {
+void flip_store_text_updated_ssid(void* context) {
     FlipStoreApp* app = (FlipStoreApp*)context;
     if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
@@ -133,7 +125,7 @@ static void flip_store_text_updated_ssid(void* context) {
     // switch to the settings view
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSettings);
 }
-static void flip_store_text_updated_pass(void* context) {
+void flip_store_text_updated_pass(void* context) {
     FlipStoreApp* app = (FlipStoreApp*)context;
     if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
@@ -172,7 +164,7 @@ static void flip_store_text_updated_pass(void* context) {
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipStoreViewSettings);
 }
 
-static uint32_t callback_to_submenu(void* context) {
+uint32_t callback_to_submenu(void* context) {
     if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
@@ -181,7 +173,7 @@ static uint32_t callback_to_submenu(void* context) {
     return FlipStoreViewSubmenu;
 }
 
-static uint32_t callback_to_app_list(void* context) {
+uint32_t callback_to_app_list(void* context) {
     if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
         return VIEW_NONE;
@@ -194,7 +186,7 @@ static uint32_t callback_to_app_list(void* context) {
     return FlipStoreViewAppList;
 }
 
-static void settings_item_selected(void* context, uint32_t index) {
+void settings_item_selected(void* context, uint32_t index) {
     FlipStoreApp* app = (FlipStoreApp*)context;
     if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
@@ -245,7 +237,7 @@ void popup_callback(void* context) {
  * @param context The context - unused
  * @return next view id (VIEW_NONE to exit the app)
  */
-static uint32_t callback_exit_app(void* context) {
+uint32_t callback_exit_app(void* context) {
     // Exit the application
     if(!context) {
         FURI_LOG_E(TAG, "Context is NULL");
@@ -255,7 +247,7 @@ static uint32_t callback_exit_app(void* context) {
     return VIEW_NONE; // Return VIEW_NONE to exit the app
 }
 
-static void callback_submenu_choices(void* context, uint32_t index) {
+void callback_submenu_choices(void* context, uint32_t index) {
     FlipStoreApp* app = (FlipStoreApp*)context;
     if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
@@ -380,5 +372,3 @@ static void callback_submenu_choices(void* context, uint32_t index) {
         break;
     }
 }
-
-#endif // FLIP_STORE_CALLBACK_H

+ 40 - 0
flip_store/callback/flip_store_callback.h

@@ -0,0 +1,40 @@
+#ifndef FLIP_STORE_CALLBACK_H
+#define FLIP_STORE_CALLBACK_H
+#include <flip_store.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <stdbool.h>
+#include <apps/flip_store_apps.h>
+#include <flip_storage/flip_store_storage.h>
+
+// Callback for drawing the main screen
+void flip_store_view_draw_callback_main(Canvas* canvas, void* model);
+
+void flip_store_view_draw_callback_app_list(Canvas* canvas, void* model);
+
+bool flip_store_input_callback(InputEvent* event, void* context);
+
+void flip_store_text_updated_ssid(void* context);
+
+void flip_store_text_updated_pass(void* context);
+
+uint32_t callback_to_submenu(void* context);
+
+uint32_t callback_to_app_list(void* context);
+
+void settings_item_selected(void* context, uint32_t index);
+
+void dialog_callback(DialogExResult result, void* context);
+
+void popup_callback(void* context);
+/**
+ * @brief Navigation callback for exiting the application
+ * @param context The context - unused
+ * @return next view id (VIEW_NONE to exit the app)
+ */
+uint32_t callback_exit_app(void* context);
+void callback_submenu_choices(void* context, uint32_t index);
+
+#endif // FLIP_STORE_CALLBACK_H

+ 1 - 23
flip_store/easy_flipper.h → flip_store/easy_flipper/easy_flipper.c

@@ -1,24 +1,4 @@
-#ifndef EASY_FLIPPER_H
-#define EASY_FLIPPER_H
-
-#include <malloc.h>
-#include <furi.h>
-#include <furi_hal.h>
-#include <gui/gui.h>
-#include <gui/view.h>
-#include <gui/modules/submenu.h>
-#include <gui/view_dispatcher.h>
-#include <gui/modules/menu.h>
-#include <gui/modules/submenu.h>
-#include <gui/modules/widget.h>
-#include <gui/modules/text_input.h>
-#include <gui/modules/text_box.h>
-#include <gui/modules/variable_item_list.h>
-#include <gui/modules/dialog_ex.h>
-#include <gui/modules/popup.h>
-#include <gui/modules/loading.h>
-
-#define EASY_TAG "EasyFlipper"
+#include <easy_flipper/easy_flipper.h>
 
 /**
  * @brief Navigation callback for exiting the application
@@ -530,5 +510,3 @@ bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer
     furi_string_set_str(*furi_string, buffer);
     return true;
 }
-
-#endif // EASY_FLIPPER_H

+ 261 - 0
flip_store/easy_flipper/easy_flipper.h

@@ -0,0 +1,261 @@
+#ifndef EASY_FLIPPER_H
+#define EASY_FLIPPER_H
+
+#include <malloc.h>
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <gui/view.h>
+#include <gui/modules/submenu.h>
+#include <gui/view_dispatcher.h>
+#include <gui/modules/menu.h>
+#include <gui/modules/submenu.h>
+#include <gui/modules/widget.h>
+#include <gui/modules/text_input.h>
+#include <gui/modules/text_box.h>
+#include <gui/modules/variable_item_list.h>
+#include <gui/modules/dialog_ex.h>
+#include <gui/modules/popup.h>
+#include <gui/modules/loading.h>
+#include <stdio.h>
+#include <string.h>
+#include <jsmn/jsmn.h>
+
+#define EASY_TAG "EasyFlipper"
+
+/**
+ * @brief Navigation callback for exiting the application
+ * @param context The context - unused
+ * @return next view id (VIEW_NONE to exit the app)
+ */
+uint32_t easy_flipper_callback_exit_app(void* context);
+/**
+ * @brief Initialize a buffer
+ * @param buffer The buffer to initialize
+ * @param buffer_size The size of the buffer
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size);
+/**
+ * @brief Initialize a View object
+ * @param view The View object to initialize
+ * @param view_id The ID/Index of the view
+ * @param draw_callback The draw callback function (set to NULL if not needed)
+ * @param input_callback The input callback function (set to NULL if not needed)
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_view(
+    View** view,
+    int32_t view_id,
+    void draw_callback(Canvas*, void*),
+    bool input_callback(InputEvent*, void*),
+    uint32_t (*previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context);
+
+/**
+ * @brief Initialize a ViewDispatcher object
+ * @param view_dispatcher The ViewDispatcher object to initialize
+ * @param gui The GUI object
+ * @param context The context to pass to the event callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context);
+
+/**
+ * @brief Initialize a Submenu object
+ * @note This does not set the items in the submenu
+ * @param submenu The Submenu object to initialize
+ * @param view_id The ID/Index of the view
+ * @param title The title/header of the submenu
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_submenu(
+    Submenu** submenu,
+    int32_t view_id,
+    char* title,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher);
+
+/**
+ * @brief Initialize a Menu object
+ * @note This does not set the items in the menu
+ * @param menu The Menu object to initialize
+ * @param view_id The ID/Index of the view
+ * @param item_callback The item callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_menu(
+    Menu** menu,
+    int32_t view_id,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher);
+
+/**
+ * @brief Initialize a Widget object
+ * @param widget The Widget object to initialize
+ * @param view_id The ID/Index of the view
+ * @param text The text to display in the widget
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_widget(
+    Widget** widget,
+    int32_t view_id,
+    char* text,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher);
+
+/**
+ * @brief Initialize a VariableItemList object
+ * @note This does not set the items in the VariableItemList
+ * @param variable_item_list The VariableItemList object to initialize
+ * @param view_id The ID/Index of the view
+ * @param enter_callback The enter callback function (can be set to NULL)
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the enter callback (usually the app)
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_variable_item_list(
+    VariableItemList** variable_item_list,
+    int32_t view_id,
+    void (*enter_callback)(void*, uint32_t),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context);
+
+/**
+ * @brief Initialize a TextInput object
+ * @param text_input The TextInput object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_text_input(
+    TextInput** text_input,
+    int32_t view_id,
+    char* header_text,
+    char* text_input_temp_buffer,
+    uint32_t text_input_buffer_size,
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context);
+
+/**
+ * @brief Initialize a TextInput object with extra symbols
+ * @param uart_text_input The TextInput object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_uart_text_input(
+    TextInput** uart_text_input,
+    int32_t view_id,
+    char* header_text,
+    char* uart_text_input_temp_buffer,
+    uint32_t uart_text_input_buffer_size,
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context);
+
+/**
+ * @brief Initialize a DialogEx object
+ * @param dialog_ex The DialogEx object to initialize
+ * @param view_id The ID/Index of the view
+ * @param header The header of the dialog
+ * @param header_x The x coordinate of the header
+ * @param header_y The y coordinate of the header
+ * @param text The text of the dialog
+ * @param text_x The x coordinate of the dialog
+ * @param text_y The y coordinate of the dialog
+ * @param left_button_text The text of the left button
+ * @param right_button_text The text of the right button
+ * @param center_button_text The text of the center button
+ * @param result_callback The result callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the result callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_dialog_ex(
+    DialogEx** dialog_ex,
+    int32_t view_id,
+    char* header,
+    uint16_t header_x,
+    uint16_t header_y,
+    char* text,
+    uint16_t text_x,
+    uint16_t text_y,
+    char* left_button_text,
+    char* right_button_text,
+    char* center_button_text,
+    void (*result_callback)(DialogExResult, void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context);
+
+/**
+ * @brief Initialize a Popup object
+ * @param popup The Popup object to initialize
+ * @param view_id The ID/Index of the view
+ * @param header The header of the dialog
+ * @param header_x The x coordinate of the header
+ * @param header_y The y coordinate of the header
+ * @param text The text of the dialog
+ * @param text_x The x coordinate of the dialog
+ * @param text_y The y coordinate of the dialog
+ * @param result_callback The result callback function
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @param context The context to pass to the result callback
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_popup(
+    Popup** popup,
+    int32_t view_id,
+    char* header,
+    uint16_t header_x,
+    uint16_t header_y,
+    char* text,
+    uint16_t text_x,
+    uint16_t text_y,
+    void (*result_callback)(void*),
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher,
+    void* context);
+
+/**
+ * @brief Initialize a Loading object
+ * @param loading The Loading object to initialize
+ * @param view_id The ID/Index of the view
+ * @param previous_callback The previous callback function (can be set to NULL)
+ * @param view_dispatcher The ViewDispatcher object
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_loading(
+    Loading** loading,
+    int32_t view_id,
+    uint32_t(previous_callback)(void*),
+    ViewDispatcher** view_dispatcher);
+
+/**
+ * @brief Set a char butter to a FuriString
+ * @param furi_string The FuriString object
+ * @param buffer The buffer to copy the string to
+ * @return true if successful, false otherwise
+ */
+bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer);
+
+#endif

+ 3 - 15
flip_store/flip_store_storage.h → flip_store/flip_storage/flip_store_storage.c

@@ -1,12 +1,6 @@
-#ifndef FLIP_STORE_STORAGE_H
-#define FLIP_STORE_STORAGE_H
+#include "flip_storage/flip_store_storage.h"
 
-#include <furi.h>
-#include <storage/storage.h>
-
-#define SETTINGS_PATH STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/settings.bin"
-
-static void save_settings(const char* ssid, const char* password) {
+void save_settings(const char* ssid, const char* password) {
     // Create the directory for saving settings
     char directory_path[128];
     snprintf(
@@ -44,7 +38,7 @@ static void save_settings(const char* ssid, const char* password) {
     furi_record_close(RECORD_STORAGE);
 }
 
-static bool load_settings(char* ssid, size_t ssid_size, char* password, size_t password_size) {
+bool load_settings(char* ssid, size_t ssid_size, char* password, size_t password_size) {
     Storage* storage = furi_record_open(RECORD_STORAGE);
     File* file = storage_file_alloc(storage);
 
@@ -110,10 +104,6 @@ bool delete_app(const char* app_id, const char* app_category) {
     return true;
 }
 
-#define BUFFER_SIZE      64
-#define MAX_KEY_LENGTH   32
-#define MAX_VALUE_LENGTH 64
-
 // Function to parse JSON incrementally from a file
 bool parse_json_incrementally(
     const char* file_path,
@@ -271,5 +261,3 @@ cleanup:
     }
     return false;
 }
-
-#endif

+ 27 - 0
flip_store/flip_storage/flip_store_storage.h

@@ -0,0 +1,27 @@
+#ifndef FLIP_STORE_STORAGE_H
+#define FLIP_STORE_STORAGE_H
+
+#include <furi.h>
+#include <storage/storage.h>
+#include <flip_store.h>
+
+#define SETTINGS_PATH    STORAGE_EXT_PATH_PREFIX "/apps_data/flip_store/settings.bin"
+#define BUFFER_SIZE      64
+#define MAX_KEY_LENGTH   32
+#define MAX_VALUE_LENGTH 64
+
+void save_settings(const char* ssid, const char* password);
+
+bool load_settings(char* ssid, size_t ssid_size, char* password, size_t password_size);
+
+// future implenetation because we need the app category
+bool delete_app(const char* app_id, const char* app_category);
+
+// Function to parse JSON incrementally from a file
+bool parse_json_incrementally(
+    const char* file_path,
+    const char* target_key,
+    char* value_buffer,
+    size_t value_buffer_size);
+
+#endif

+ 17 - 8
flip_store/flip_store_free.h → flip_store/flip_store.c

@@ -1,8 +1,22 @@
-#ifndef FLIP_STORE_FREE_H
-#define FLIP_STORE_FREE_H
+#include <flip_store.h>
+
+// define the list of categories
+char* categories[] = {
+    "Bluetooth",
+    "Games",
+    "GPIO",
+    "Infrared",
+    "iButton",
+    "Media",
+    "NFC",
+    "RFID",
+    "Sub-GHz",
+    "Tools",
+    "USB",
+};
 
 // Function to free the resources used by FlipStoreApp
-static void flip_store_app_free(FlipStoreApp* app) {
+void flip_store_app_free(FlipStoreApp* app) {
     if(!app) {
         FURI_LOG_E(TAG, "FlipStoreApp is NULL");
         return;
@@ -106,9 +120,6 @@ static void flip_store_app_free(FlipStoreApp* app) {
         dialog_ex_free(app->dialog_delete);
     }
 
-    // Free the flip catalog
-    flip_catalog_free();
-
     // deinitalize flipper http
     flipper_http_deinit();
 
@@ -121,5 +132,3 @@ static void flip_store_app_free(FlipStoreApp* app) {
     // free the app
     free(app);
 }
-
-#endif // FLIP_STORE_FREE_H

+ 6 - 31
flip_store/flip_store_e.h → flip_store/flip_store.h

@@ -1,7 +1,7 @@
 #ifndef FLIP_STORE_E_H
 #define FLIP_STORE_E_H
-#include <flipper_http.h>
-#include <easy_flipper.h>
+#include <flipper_http/flipper_http.h>
+#include <easy_flipper/easy_flipper.h>
 #include <furi.h>
 #include <furi_hal.h>
 #include <gui/gui.h>
@@ -10,23 +10,12 @@
 #include <gui/view_dispatcher.h>
 #include <notification/notification.h>
 #include <dialogs/dialogs.h>
-#include <jsmn.h>
+#include <jsmn/jsmn.h>
+#include <flip_store_icons.h>
 #define TAG "FlipStore"
 
 // define the list of categories
-char* categories[] = {
-    "Bluetooth",
-    "Games",
-    "GPIO",
-    "Infrared",
-    "iButton",
-    "Media",
-    "NFC",
-    "RFID",
-    "Sub-GHz",
-    "Tools",
-    "USB",
-};
+extern char* categories[];
 
 // Define the submenu items for our FlipStore application
 typedef enum {
@@ -118,20 +107,6 @@ typedef struct {
     uint32_t uart_text_input_buffer_size_pass; // Size of the text input buffer
 } FlipStoreApp;
 
-// include strndup (otherwise NULL pointer dereference)
-char* strndup(const char* s, size_t n) {
-    char* result;
-    size_t len = strlen(s);
-
-    if(n < len) len = n;
-
-    result = (char*)malloc(len + 1);
-    if(!result) return NULL;
-
-    result[len] = '\0';
-    return (char*)memcpy(result, s, len);
-}
-
-static void callback_submenu_choices(void* context, uint32_t index);
+void flip_store_app_free(FlipStoreApp* app);
 
 #endif // FLIP_STORE_E_H

+ 373 - 367
flip_store/flipper_http.h → flip_store/flipper_http/flipper_http.c

@@ -1,133 +1,33 @@
-// flipper_http.h - Flipper HTTP Library (www.github.com/jblanked)
-// Author: JBlanked
-#ifndef FLIPPER_HTTP_H
-#define FLIPPER_HTTP_H
-
-#include <furi.h>
-#include <furi_hal.h>
-#include <furi_hal_gpio.h>
-#include <furi_hal_serial.h>
-#include <storage/storage.h>
-#include <stdlib.h>
-
-// STORAGE_EXT_PATH_PREFIX is defined in the Furi SDK as /ext
-
-#define HTTP_TAG               "FlipStore" // change this to your app name
-#define http_tag               "flip_store" // change this to your app id
-#define UART_CH                (FuriHalSerialIdUsart) // UART channel
-#define TIMEOUT_DURATION_TICKS (6 * 1000) // 6 seconds
-#define BAUDRATE               (115200) // UART baudrate
-#define RX_BUF_SIZE            1024 // UART RX buffer size
-#define RX_LINE_BUFFER_SIZE    5000 // UART RX line buffer size (increase for large responses)
-
-// Forward declaration for callback
-typedef void (*FlipperHTTP_Callback)(const char* line, void* context);
-
-// Functions
-bool flipper_http_init(FlipperHTTP_Callback callback, void* context);
-void flipper_http_deinit();
-//---
-void flipper_http_rx_callback(const char* line, void* context);
-bool flipper_http_send_data(const char* data);
-//---
-bool flipper_http_connect_wifi();
-bool flipper_http_disconnect_wifi();
-bool flipper_http_ping();
-bool flipper_http_scan_wifi();
-bool flipper_http_save_wifi(const char* ssid, const char* password);
-//---
-bool flipper_http_get_request(const char* url);
-bool flipper_http_get_request_with_headers(const char* url, const char* headers);
-bool flipper_http_post_request_with_headers(
-    const char* url,
-    const char* headers,
-    const char* payload);
-bool flipper_http_put_request_with_headers(
-    const char* url,
-    const char* headers,
-    const char* payload);
-bool flipper_http_delete_request_with_headers(
-    const char* url,
-    const char* headers,
-    const char* payload);
-//---
-bool flipper_http_get_request_bytes(const char* url, const char* headers);
-bool flipper_http_post_request_bytes(const char* url, const char* headers, const char* payload);
-//---
-bool flipper_http_save_received_data(size_t bytes_received, const char line_buffer[]);
-char* trim(const char* str);
-
-// State variable to track the UART state
-typedef enum {
-    INACTIVE, // Inactive state
-    IDLE, // Default state
-    RECEIVING, // Receiving data
-    SENDING, // Sending data
-    ISSUE, // Issue with connection
-} SerialState;
-
-// Event Flags for UART Worker Thread
-typedef enum {
-    WorkerEvtStop = (1 << 0),
-    WorkerEvtRxDone = (1 << 1),
-} WorkerEvtFlags;
-
-static bool is_compile_app_request = false; // personal use in flip_store_apps.h
-
-// FlipperHTTP Structure
-typedef struct {
-    FuriStreamBuffer* flipper_http_stream; // Stream buffer for UART communication
-    FuriHalSerialHandle* serial_handle; // Serial handle for UART communication
-    FuriThread* rx_thread; // Worker thread for UART
-    // uint8_t rx_buf[RX_BUF_SIZE];            // Buffer for received data
-    FuriThreadId rx_thread_id; // Worker thread ID
-    FlipperHTTP_Callback handle_rx_line_cb; // Callback for received lines
-    void* callback_context; // Context for the callback
-    SerialState state; // State of the UART
-
-    // variable to store the last received data from the UART
-    char* last_response;
-
-    // Timer-related members
-    FuriTimer* get_timeout_timer; // Timer for HTTP request timeout
-    char* received_data; // Buffer to store received data
-
-    bool started_receiving_get; // Indicates if a GET request has started
-    bool just_started_get; // Indicates if GET data reception has just started
-
-    bool started_receiving_post; // Indicates if a POST request has started
-    bool just_started_post; // Indicates if POST data reception has just started
-
-    bool started_receiving_put; // Indicates if a PUT request has started
-    bool just_started_put; // Indicates if PUT data reception has just started
-
-    bool started_receiving_delete; // Indicates if a DELETE request has started
-    bool just_started_delete; // Indicates if DELETE data reception has just started
-
-    // Buffer to hold the raw bytes received from the UART
-    uint8_t* received_bytes;
-    size_t received_bytes_len; // Length of the received bytes
-
-    // File path to save the bytes received
-    char file_path[256];
-
-    bool save_data; // Flag to save the received data
-
-} FlipperHTTP;
-
-static FlipperHTTP fhttp;
-
+#include <flipper_http/flipper_http.h>
+FlipperHTTP fhttp;
+char rx_line_buffer[RX_LINE_BUFFER_SIZE];
+uint8_t file_buffer[FILE_BUFFER_SIZE];
 // Function to append received data to file
-static bool append_to_file(const char* file_path, const void* data, size_t data_size) {
+// make sure to initialize the file path before calling this function
+bool flipper_http_append_to_file(
+    const void* data,
+    size_t data_size,
+    bool start_new_file,
+    char* file_path) {
     Storage* storage = furi_record_open(RECORD_STORAGE);
     File* file = storage_file_alloc(storage);
 
-    // Open the file in append mode
-    if(!storage_file_open(file, file_path, FSAM_WRITE, FSOM_OPEN_APPEND)) {
-        FURI_LOG_E(HTTP_TAG, "Failed to open file for appending: %s", file_path);
-        storage_file_free(file);
-        furi_record_close(RECORD_STORAGE);
-        return false;
+    if(start_new_file) {
+        // Open the file in write mode
+        if(!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
+            FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
+            storage_file_free(file);
+            furi_record_close(RECORD_STORAGE);
+            return false;
+        }
+    } else {
+        // Open the file in append mode
+        if(!storage_file_open(file, file_path, FSAM_WRITE, FSOM_OPEN_APPEND)) {
+            FURI_LOG_E(HTTP_TAG, "Failed to open file for appending: %s", file_path);
+            storage_file_free(file);
+            furi_record_close(RECORD_STORAGE);
+            return false;
+        }
     }
 
     // Write the data to the file
@@ -142,13 +42,83 @@ static bool append_to_file(const char* file_path, const void* data, size_t data_
     storage_file_close(file);
     storage_file_free(file);
     furi_record_close(RECORD_STORAGE);
-
     return true;
 }
-// Global static array for the line buffer
-static char rx_line_buffer[RX_LINE_BUFFER_SIZE];
-#define FILE_BUFFER_SIZE 512
-static uint8_t file_buffer[FILE_BUFFER_SIZE];
+
+FuriString* flipper_http_load_from_file(char* file_path) {
+    // Open the storage record
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    if(!storage) {
+        FURI_LOG_E(HTTP_TAG, "Failed to open storage record");
+        return NULL;
+    }
+
+    // Allocate a file handle
+    File* file = storage_file_alloc(storage);
+    if(!file) {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate storage file");
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Open the file for reading
+    if(!storage_file_open(file, file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL; // Return false if the file does not exist
+    }
+
+    // Allocate a FuriString to hold the received data
+    FuriString* str_result = furi_string_alloc();
+    if(!str_result) {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate FuriString");
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Reset the FuriString to ensure it's empty before reading
+    furi_string_reset(str_result);
+
+    // Define a buffer to hold the read data
+    uint8_t* buffer = (uint8_t*)malloc(MAX_FILE_SHOW);
+    if(!buffer) {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate buffer");
+        furi_string_free(str_result);
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Read data into the buffer
+    size_t read_count = storage_file_read(file, buffer, MAX_FILE_SHOW);
+    if(storage_file_get_error(file) != FSE_OK) {
+        FURI_LOG_E(HTTP_TAG, "Error reading from file.");
+        furi_string_free(str_result);
+        storage_file_close(file);
+        storage_file_free(file);
+        furi_record_close(RECORD_STORAGE);
+        return NULL;
+    }
+
+    // Append each byte to the FuriString
+    for(size_t i = 0; i < read_count; i++) {
+        furi_string_push_back(str_result, buffer[i]);
+    }
+
+    // Check if there is more data beyond the maximum size
+    char extra_byte;
+    storage_file_read(file, &extra_byte, 1);
+
+    // Clean up
+    storage_file_close(file);
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+    free(buffer);
+    return str_result;
+}
 
 // UART worker thread
 /**
@@ -158,7 +128,7 @@ static uint8_t file_buffer[FILE_BUFFER_SIZE];
  * @note       This function will handle received data asynchronously via the callback.
  */
 // UART worker thread
-static int32_t flipper_http_worker(void* context) {
+int32_t flipper_http_worker(void* context) {
     UNUSED(context);
     size_t rx_line_pos = 0;
     static size_t file_buffer_len = 0;
@@ -180,12 +150,13 @@ static int32_t flipper_http_worker(void* context) {
                 }
 
                 // Append the received byte to the file if saving is enabled
-                if(fhttp.save_data) {
+                if(fhttp.save_bytes) {
                     // Add byte to the buffer
                     file_buffer[file_buffer_len++] = c;
                     // Write to file if buffer is full
                     if(file_buffer_len >= FILE_BUFFER_SIZE) {
-                        if(!append_to_file(fhttp.file_path, file_buffer, file_buffer_len)) {
+                        if(!flipper_http_append_to_file(
+                               file_buffer, file_buffer_len, false, fhttp.file_path)) {
                             FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
                         }
                         file_buffer_len = 0;
@@ -211,17 +182,17 @@ static int32_t flipper_http_worker(void* context) {
         }
     }
 
-    if(fhttp.save_data) {
+    if(fhttp.save_bytes) {
         // Write the remaining data to the file
         if(file_buffer_len > 0) {
-            if(!append_to_file(fhttp.file_path, file_buffer, file_buffer_len)) {
+            if(!flipper_http_append_to_file(file_buffer, file_buffer_len, false, fhttp.file_path)) {
                 FURI_LOG_E(HTTP_TAG, "Failed to append remaining data to file");
             }
         }
     }
 
     // remove [POST/END] and/or [GET/END] from the file
-    if(fhttp.save_data) {
+    if(fhttp.save_bytes) {
         char* end = NULL;
         if((end = strstr(fhttp.file_path, "[POST/END]")) != NULL) {
             *end = '\0';
@@ -231,7 +202,7 @@ static int32_t flipper_http_worker(void* context) {
     }
 
     // remove newline from the from the end of the file
-    if(fhttp.save_data) {
+    if(fhttp.save_bytes) {
         char* end = NULL;
         if((end = strstr(fhttp.file_path, "\n")) != NULL) {
             *end = '\0';
@@ -243,7 +214,6 @@ static int32_t flipper_http_worker(void* context) {
 
     return 0;
 }
-
 // Timer callback function
 /**
  * @brief      Callback function for the GET timeout timer.
@@ -261,12 +231,6 @@ void get_timeout_timer_callback(void* context) {
     fhttp.started_receiving_put = false;
     fhttp.started_receiving_delete = false;
 
-    // Free received data if any
-    if(fhttp.received_data) {
-        free(fhttp.received_data);
-        fhttp.received_data = NULL;
-    }
-
     // Update UART state
     fhttp.state = ISSUE;
 }
@@ -280,7 +244,7 @@ void get_timeout_timer_callback(void* context) {
  * @param      context   The context to pass to the callback.
  * @note       This function will handle received data asynchronously via the callback.
  */
-static void _flipper_http_rx_callback(
+void _flipper_http_rx_callback(
     FuriHalSerialHandle* handle,
     FuriHalSerialRxEvent event,
     void* context) {
@@ -384,10 +348,13 @@ bool flipper_http_init(FlipperHTTP_Callback callback, void* context) {
     // Set the timer thread priority if needed
     furi_timer_set_thread_priority(FuriTimerThreadPriorityElevated);
 
-    fhttp.file_path[0] = '\0'; // Null-terminate the file path
-    fhttp.received_data = NULL;
-    fhttp.received_bytes = NULL;
-    fhttp.received_bytes_len = 0;
+    fhttp.last_response = (char*)malloc(RX_BUF_SIZE);
+    if(!fhttp.last_response) {
+        FURI_LOG_E(HTTP_TAG, "Failed to allocate memory for last_response.");
+        return false;
+    }
+
+    // FURI_LOG_I(HTTP_TAG, "UART initialized successfully.");
     return true;
 }
 
@@ -426,12 +393,6 @@ void flipper_http_deinit() {
         fhttp.get_timeout_timer = NULL;
     }
 
-    // Free received data if any
-    if(fhttp.received_data) {
-        free(fhttp.received_data);
-        fhttp.received_data = NULL;
-    }
-
     // Free the last response
     if(fhttp.last_response) {
         free(fhttp.last_response);
@@ -485,7 +446,7 @@ bool flipper_http_send_data(const char* data) {
 
 // Function to send a PING request
 /**
- * @brief      Send a PING request to check the connection status.
+ * @brief      Send a PING request to check if the Wifi Dev Board is connected.
  * @return     true if the request was successful, false otherwise.
  * @note       The received data will be handled asynchronously via the callback.
  * @note       This is best used to check if the Wifi Dev Board is connected.
@@ -503,6 +464,125 @@ bool flipper_http_ping() {
     return true;
 }
 
+// Function to list available commands
+/**
+ * @brief      Send a command to list available commands.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_list_commands() {
+    const char* command = "[LIST]";
+    if(!flipper_http_send_data(command)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to send LIST command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to turn on the LED
+/**
+ * @brief      Allow the LED to display while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_on() {
+    const char* command = "[LED/ON]";
+    if(!flipper_http_send_data(command)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to send LED ON command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to turn off the LED
+/**
+ * @brief      Disable the LED from displaying while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_off() {
+    const char* command = "[LED/OFF]";
+    if(!flipper_http_send_data(command)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to send LED OFF command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to parse JSON data
+/**
+ * @brief      Parse JSON data.
+ * @return     true if the JSON data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON data.
+ * @param      json_data The JSON data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json(const char* key, const char* json_data) {
+    if(!key || !json_data) {
+        FURI_LOG_E("FlipperHTTP", "Invalid arguments provided to flipper_http_parse_json.");
+        return false;
+    }
+
+    char buffer[256];
+    int ret =
+        snprintf(buffer, sizeof(buffer), "[PARSE]{\"key\":\"%s\",\"json\":%s}", key, json_data);
+    if(ret < 0 || ret >= (int)sizeof(buffer)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to format JSON parse command.");
+        return false;
+    }
+
+    if(!flipper_http_send_data(buffer)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to send JSON parse command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to parse JSON array data
+/**
+ * @brief      Parse JSON array data.
+ * @return     true if the JSON array data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON array data.
+ * @param      index     The index to parse from the JSON array data.
+ * @param      json_data The JSON array data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json_array(const char* key, int index, const char* json_data) {
+    if(!key || !json_data) {
+        FURI_LOG_E("FlipperHTTP", "Invalid arguments provided to flipper_http_parse_json_array.");
+        return false;
+    }
+
+    char buffer[256];
+    int ret = snprintf(
+        buffer,
+        sizeof(buffer),
+        "[PARSE/ARRAY]{\"key\":\"%s\",\"index\":%d,\"json\":%s}",
+        key,
+        index,
+        json_data);
+    if(ret < 0 || ret >= (int)sizeof(buffer)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to format JSON parse array command.");
+        return false;
+    }
+
+    if(!flipper_http_send_data(buffer)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to send JSON parse array command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
 // Function to scan for WiFi networks
 /**
  * @brief      Send a command to scan for WiFi networks.
@@ -548,6 +628,40 @@ bool flipper_http_save_wifi(const char* ssid, const char* password) {
     return true;
 }
 
+// Function to get IP address of WiFi Devboard
+/**
+ * @brief      Send a command to get the IP address of the WiFi Devboard
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_address() {
+    const char* command = "[IP/ADDRESS]";
+    if(!flipper_http_send_data(command)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to send IP address command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
+// Function to get IP address of the connected WiFi network
+/**
+ * @brief      Send a command to get the IP address of the connected WiFi network.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_wifi() {
+    const char* command = "[WIFI/IP]";
+    if(!flipper_http_send_data(command)) {
+        FURI_LOG_E("FlipperHTTP", "Failed to send WiFi IP command.");
+        return false;
+    }
+
+    // The response will be handled asynchronously via the callback
+    return true;
+}
+
 // Function to disconnect from WiFi (returns true if successful)
 /**
  * @brief      Send a command to disconnect from WiFi.
@@ -683,7 +797,7 @@ bool flipper_http_get_request_bytes(const char* url, const char* headers) {
  * @return     true if the request was successful, false otherwise.
  * @param      url  The URL to send the POST request to.
  * @param      headers  The headers to send with the POST request.
- * @param      payload  The data to send with the POST request.
+ * @param      data  The data to send with the POST request.
  * @note       The received data will be handled asynchronously via the callback.
  */
 bool flipper_http_post_request_with_headers(
@@ -765,7 +879,7 @@ bool flipper_http_post_request_bytes(const char* url, const char* headers, const
  * @return     true if the request was successful, false otherwise.
  * @param      url  The URL to send the PUT request to.
  * @param      headers  The headers to send with the PUT request.
- * @param      payload  The data to send with the PUT request.
+ * @param      data  The data to send with the PUT request.
  * @note       The received data will be handled asynchronously via the callback.
  */
 bool flipper_http_put_request_with_headers(
@@ -807,7 +921,7 @@ bool flipper_http_put_request_with_headers(
  * @return     true if the request was successful, false otherwise.
  * @param      url  The URL to send the DELETE request to.
  * @param      headers  The headers to send with the DELETE request.
- * @param      payload  The data to send with the DELETE request.
+ * @param      data  The data to send with the DELETE request.
  * @note       The received data will be handled asynchronously via the callback.
  */
 bool flipper_http_delete_request_with_headers(
@@ -862,7 +976,13 @@ void flipper_http_rx_callback(const char* line, void* context) {
     // Trim the received line to check if it's empty
     char* trimmed_line = trim(line);
     if(trimmed_line != NULL && trimmed_line[0] != '\0') {
-        fhttp.last_response = (char*)line;
+        // if the line is not [GET/END] or [POST/END] or [PUT/END] or [DELETE/END]
+        if(strstr(trimmed_line, "[GET/END]") == NULL &&
+           strstr(trimmed_line, "[POST/END]") == NULL &&
+           strstr(trimmed_line, "[PUT/END]") == NULL &&
+           strstr(trimmed_line, "[DELETE/END]") == NULL) {
+            strncpy(fhttp.last_response, trimmed_line, RX_BUF_SIZE);
+        }
     }
     free(trimmed_line); // Free the allocated memory for trimmed_line
 
@@ -871,7 +991,7 @@ void flipper_http_rx_callback(const char* line, void* context) {
     }
 
     // Uncomment below line to log the data received over UART
-    FURI_LOG_I(HTTP_TAG, "Received UART line: %s", line);
+    // FURI_LOG_I(HTTP_TAG, "Received UART line: %s", line);
 
     // Check if we've started receiving data from a GET request
     if(fhttp.started_receiving_get) {
@@ -882,44 +1002,24 @@ void flipper_http_rx_callback(const char* line, void* context) {
             FURI_LOG_I(HTTP_TAG, "GET request completed.");
             // Stop the timer since we've completed the GET request
             furi_timer_stop(fhttp.get_timeout_timer);
-
-            if(fhttp.received_data) {
-                // uncomment if you want to save the received data to the external storage
-                flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
-                fhttp.started_receiving_get = false;
-                fhttp.just_started_get = false;
-                fhttp.state = IDLE;
-                return;
-            } else {
-                FURI_LOG_E(HTTP_TAG, "No data received.");
-                fhttp.started_receiving_get = false;
-                fhttp.just_started_get = false;
-                fhttp.state = IDLE;
-                return;
-            }
+            fhttp.started_receiving_get = false;
+            fhttp.just_started_get = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.is_bytes_request = false;
+            fhttp.save_received_data = false;
+            return;
         }
 
         // Append the new line to the existing data
-        if(fhttp.received_data == NULL) {
-            fhttp.received_data =
-                (char*)malloc(strlen(line) + 2); // +2 for newline and null terminator
-            if(fhttp.received_data) {
-                strcpy(fhttp.received_data, line);
-                fhttp.received_data[strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[strlen(line) + 1] = '\0'; // Null terminator
-            }
-        } else {
-            size_t current_len = strlen(fhttp.received_data);
-            size_t new_size = current_len + strlen(line) + 2; // +2 for newline and null terminator
-            fhttp.received_data = (char*)realloc(fhttp.received_data, new_size);
-            if(fhttp.received_data) {
-                memcpy(
-                    fhttp.received_data + current_len,
-                    line,
-                    strlen(line)); // Copy line at the end of the current data
-                fhttp.received_data[current_len + strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[current_len + strlen(line) + 1] = '\0'; // Null terminator
-            }
+        if(fhttp.save_received_data &&
+           !flipper_http_append_to_file(
+               line, strlen(line), !fhttp.just_started_get, fhttp.file_path)) {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_get = false;
+            fhttp.just_started_get = false;
+            fhttp.state = IDLE;
+            return;
         }
 
         if(!fhttp.just_started_get) {
@@ -935,47 +1035,26 @@ void flipper_http_rx_callback(const char* line, void* context) {
 
         if(strstr(line, "[POST/END]") != NULL) {
             FURI_LOG_I(HTTP_TAG, "POST request completed.");
-            fhttp.save_data = false;
             // Stop the timer since we've completed the POST request
             furi_timer_stop(fhttp.get_timeout_timer);
-
-            if(fhttp.received_data) {
-                // uncomment if you want to save the received data to the external storage
-                // flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
-                fhttp.started_receiving_post = false;
-                fhttp.just_started_post = false;
-                fhttp.state = IDLE;
-                return;
-            } else {
-                FURI_LOG_E(HTTP_TAG, "No data received.");
-                fhttp.started_receiving_post = false;
-                fhttp.just_started_post = false;
-                fhttp.state = IDLE;
-                return;
-            }
+            fhttp.started_receiving_post = false;
+            fhttp.just_started_post = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.is_bytes_request = false;
+            fhttp.save_received_data = false;
+            return;
         }
 
         // Append the new line to the existing data
-        if(fhttp.received_data == NULL) {
-            fhttp.received_data =
-                (char*)malloc(strlen(line) + 2); // +2 for newline and null terminator
-            if(fhttp.received_data) {
-                strcpy(fhttp.received_data, line);
-                fhttp.received_data[strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[strlen(line) + 1] = '\0'; // Null terminator
-            }
-        } else {
-            size_t current_len = strlen(fhttp.received_data);
-            size_t new_size = current_len + strlen(line) + 2; // +2 for newline and null terminator
-            fhttp.received_data = (char*)realloc(fhttp.received_data, new_size);
-            if(fhttp.received_data) {
-                memcpy(
-                    fhttp.received_data + current_len,
-                    line,
-                    strlen(line)); // Copy line at the end of the current data
-                fhttp.received_data[current_len + strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[current_len + strlen(line) + 1] = '\0'; // Null terminator
-            }
+        if(fhttp.save_received_data &&
+           !flipper_http_append_to_file(
+               line, strlen(line), !fhttp.just_started_post, fhttp.file_path)) {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_post = false;
+            fhttp.just_started_post = false;
+            fhttp.state = IDLE;
+            return;
         }
 
         if(!fhttp.just_started_post) {
@@ -993,44 +1072,24 @@ void flipper_http_rx_callback(const char* line, void* context) {
             FURI_LOG_I(HTTP_TAG, "PUT request completed.");
             // Stop the timer since we've completed the PUT request
             furi_timer_stop(fhttp.get_timeout_timer);
-
-            if(fhttp.received_data) {
-                // uncomment if you want to save the received data to the external storage
-                // flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
-                fhttp.started_receiving_put = false;
-                fhttp.just_started_put = false;
-                fhttp.state = IDLE;
-                return;
-            } else {
-                FURI_LOG_E(HTTP_TAG, "No data received.");
-                fhttp.started_receiving_put = false;
-                fhttp.just_started_put = false;
-                fhttp.state = IDLE;
-                return;
-            }
+            fhttp.started_receiving_put = false;
+            fhttp.just_started_put = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.is_bytes_request = false;
+            fhttp.save_received_data = false;
+            return;
         }
 
         // Append the new line to the existing data
-        if(fhttp.received_data == NULL) {
-            fhttp.received_data =
-                (char*)malloc(strlen(line) + 2); // +2 for newline and null terminator
-            if(fhttp.received_data) {
-                strcpy(fhttp.received_data, line);
-                fhttp.received_data[strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[strlen(line) + 1] = '\0'; // Null terminator
-            }
-        } else {
-            size_t current_len = strlen(fhttp.received_data);
-            size_t new_size = current_len + strlen(line) + 2; // +2 for newline and null terminator
-            fhttp.received_data = (char*)realloc(fhttp.received_data, new_size);
-            if(fhttp.received_data) {
-                memcpy(
-                    fhttp.received_data + current_len,
-                    line,
-                    strlen(line)); // Copy line at the end of the current data
-                fhttp.received_data[current_len + strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[current_len + strlen(line) + 1] = '\0'; // Null terminator
-            }
+        if(fhttp.save_received_data &&
+           !flipper_http_append_to_file(
+               line, strlen(line), !fhttp.just_started_put, fhttp.file_path)) {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_put = false;
+            fhttp.just_started_put = false;
+            fhttp.state = IDLE;
+            return;
         }
 
         if(!fhttp.just_started_put) {
@@ -1048,44 +1107,24 @@ void flipper_http_rx_callback(const char* line, void* context) {
             FURI_LOG_I(HTTP_TAG, "DELETE request completed.");
             // Stop the timer since we've completed the DELETE request
             furi_timer_stop(fhttp.get_timeout_timer);
-
-            if(fhttp.received_data) {
-                // uncomment if you want to save the received data to the external storage
-                // flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
-                fhttp.started_receiving_delete = false;
-                fhttp.just_started_delete = false;
-                fhttp.state = IDLE;
-                return;
-            } else {
-                FURI_LOG_E(HTTP_TAG, "No data received.");
-                fhttp.started_receiving_delete = false;
-                fhttp.just_started_delete = false;
-                fhttp.state = IDLE;
-                return;
-            }
+            fhttp.started_receiving_delete = false;
+            fhttp.just_started_delete = false;
+            fhttp.state = IDLE;
+            fhttp.save_bytes = false;
+            fhttp.is_bytes_request = false;
+            fhttp.save_received_data = false;
+            return;
         }
 
         // Append the new line to the existing data
-        if(fhttp.received_data == NULL) {
-            fhttp.received_data =
-                (char*)malloc(strlen(line) + 2); // +2 for newline and null terminator
-            if(fhttp.received_data) {
-                strcpy(fhttp.received_data, line);
-                fhttp.received_data[strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[strlen(line) + 1] = '\0'; // Null terminator
-            }
-        } else {
-            size_t current_len = strlen(fhttp.received_data);
-            size_t new_size = current_len + strlen(line) + 2; // +2 for newline and null terminator
-            fhttp.received_data = (char*)realloc(fhttp.received_data, new_size);
-            if(fhttp.received_data) {
-                memcpy(
-                    fhttp.received_data + current_len,
-                    line,
-                    strlen(line)); // Copy line at the end of the current data
-                fhttp.received_data[current_len + strlen(line)] = '\n'; // Add newline
-                fhttp.received_data[current_len + strlen(line) + 1] = '\0'; // Null terminator
-            }
+        if(fhttp.save_received_data &&
+           !flipper_http_append_to_file(
+               line, strlen(line), !fhttp.just_started_delete, fhttp.file_path)) {
+            FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+            fhttp.started_receiving_delete = false;
+            fhttp.just_started_delete = false;
+            fhttp.state = IDLE;
+            return;
         }
 
         if(!fhttp.just_started_delete) {
@@ -1108,34 +1147,28 @@ void flipper_http_rx_callback(const char* line, void* context) {
         fhttp.started_receiving_get = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        fhttp.received_data = NULL;
-        if(is_compile_app_request) {
-            fhttp.save_data = true;
-        }
+        // for GET request, save data only if it's a bytes request
+        fhttp.save_bytes = fhttp.is_bytes_request;
         return;
     } else if(strstr(line, "[POST/SUCCESS]") != NULL) {
         FURI_LOG_I(HTTP_TAG, "POST request succeeded.");
         fhttp.started_receiving_post = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        fhttp.received_data = NULL;
-        if(is_compile_app_request) {
-            fhttp.save_data = true;
-        }
+        // for POST request, save data only if it's a bytes request
+        fhttp.save_bytes = fhttp.is_bytes_request;
         return;
     } else if(strstr(line, "[PUT/SUCCESS]") != NULL) {
         FURI_LOG_I(HTTP_TAG, "PUT request succeeded.");
         fhttp.started_receiving_put = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        fhttp.received_data = NULL;
         return;
     } else if(strstr(line, "[DELETE/SUCCESS]") != NULL) {
         FURI_LOG_I(HTTP_TAG, "DELETE request succeeded.");
         fhttp.started_receiving_delete = true;
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
-        fhttp.received_data = NULL;
         return;
     } else if(strstr(line, "[DISCONNECTED]") != NULL) {
         FURI_LOG_I(HTTP_TAG, "WiFi disconnected successfully.");
@@ -1161,60 +1194,7 @@ void flipper_http_rx_callback(const char* line, void* context) {
         fhttp.state = IDLE;
     }
 }
-// Function to save received data to a file
-/**
- * @brief      Save the received data to a file.
- * @return     true if the data was saved successfully, false otherwise.
- * @param      bytes_received  The number of bytes received.
- * @param      line_buffer     The buffer containing the received data.
- * @note       The data will be saved to a file in the STORAGE_EXT_PATH_PREFIX "/apps_data/" http_tag "/received_data.txt" directory.
- */
-bool flipper_http_save_received_data(size_t bytes_received, const char line_buffer[]) {
-    const char* output_file_path = STORAGE_EXT_PATH_PREFIX "/apps_data/" http_tag
-                                                           "/received_data.txt";
-
-    // Ensure the directory exists
-    char directory_path[128];
-    snprintf(
-        directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/" http_tag);
-
-    Storage* _storage = NULL;
-    File* _file = NULL;
-    // Open the storage if not opened already
-    // Initialize storage and create the directory if it doesn't exist
-    _storage = furi_record_open(RECORD_STORAGE);
-    storage_common_mkdir(_storage, directory_path); // Create directory if it doesn't exist
-    _file = storage_file_alloc(_storage);
-
-    // Open file for writing and append data line by line
-    if(!storage_file_open(_file, output_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
-        FURI_LOG_E(HTTP_TAG, "Failed to open output file for writing.");
-        storage_file_free(_file);
-        furi_record_close(RECORD_STORAGE);
-        return false;
-    }
-
-    // Write each line received from the UART to the file
-    if(bytes_received > 0 && _file) {
-        storage_file_write(_file, line_buffer, bytes_received);
-        storage_file_write(_file, "\n", 1); // Add a newline after each line
-    } else {
-        FURI_LOG_E(HTTP_TAG, "No data received.");
-        return false;
-    }
 
-    if(_file) {
-        storage_file_close(_file);
-        storage_file_free(_file);
-        _file = NULL;
-    }
-    if(_storage) {
-        furi_record_close(RECORD_STORAGE);
-        _storage = NULL;
-    }
-
-    return true;
-}
 // Function to trim leading and trailing spaces and newlines from a constant string
 char* trim(const char* str) {
     const char* end;
@@ -1249,4 +1229,30 @@ char* trim(const char* str) {
     return trimmed_str;
 }
 
-#endif // FLIPPER_HTTP_H
+/**
+ * @brief Process requests and parse JSON data asynchronously
+ * @param http_request The function to send the request
+ * @param parse_json The function to parse the JSON
+ * @return true if successful, false otherwise
+ */
+bool flipper_http_process_response_async(bool (*http_request)(void), bool (*parse_json)(void)) {
+    if(http_request()) // start the async request
+    {
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
+        fhttp.state = RECEIVING;
+    } else {
+        FURI_LOG_E(HTTP_TAG, "Failed to send request");
+        return false;
+    }
+    while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
+        // Wait for the request to be received
+        furi_delay_ms(100);
+    }
+    furi_timer_stop(fhttp.get_timeout_timer);
+    if(!parse_json()) // parse the JSON before switching to the view (synchonous)
+    {
+        FURI_LOG_E(HTTP_TAG, "Failed to parse the JSON...");
+        return false;
+    }
+    return true;
+}

+ 360 - 0
flip_store/flipper_http/flipper_http.h

@@ -0,0 +1,360 @@
+// flipper_http.h
+#ifndef FLIPPER_HTTP_H
+#define FLIPPER_HTTP_H
+
+#include <furi.h>
+#include <furi_hal.h>
+#include <furi_hal_gpio.h>
+#include <furi_hal_serial.h>
+#include <storage/storage.h>
+
+// STORAGE_EXT_PATH_PREFIX is defined in the Furi SDK as /ext
+
+#define HTTP_TAG               "FlipStore" // change this to your app name
+#define http_tag               "flip_store" // change this to your app id
+#define UART_CH                (FuriHalSerialIdUsart) // UART channel
+#define TIMEOUT_DURATION_TICKS (5 * 1000) // 5 seconds
+#define BAUDRATE               (115200) // UART baudrate
+#define RX_BUF_SIZE            1024 // UART RX buffer size
+#define RX_LINE_BUFFER_SIZE    8192 // UART RX line buffer size (increase for large responses)
+#define MAX_FILE_SHOW          8192 // Maximum data from file to show
+#define FILE_BUFFER_SIZE       512 // File buffer size
+
+// Forward declaration for callback
+typedef void (*FlipperHTTP_Callback)(const char* line, void* context);
+
+// State variable to track the UART state
+typedef enum {
+    INACTIVE, // Inactive state
+    IDLE, // Default state
+    RECEIVING, // Receiving data
+    SENDING, // Sending data
+    ISSUE, // Issue with connection
+} SerialState;
+
+// Event Flags for UART Worker Thread
+typedef enum {
+    WorkerEvtStop = (1 << 0),
+    WorkerEvtRxDone = (1 << 1),
+} WorkerEvtFlags;
+
+// FlipperHTTP Structure
+typedef struct {
+    FuriStreamBuffer* flipper_http_stream; // Stream buffer for UART communication
+    FuriHalSerialHandle* serial_handle; // Serial handle for UART communication
+    FuriThread* rx_thread; // Worker thread for UART
+    FuriThreadId rx_thread_id; // Worker thread ID
+    FlipperHTTP_Callback handle_rx_line_cb; // Callback for received lines
+    void* callback_context; // Context for the callback
+    SerialState state; // State of the UART
+
+    // variable to store the last received data from the UART
+    char* last_response;
+    char file_path[256]; // Path to save the received data
+
+    // Timer-related members
+    FuriTimer* get_timeout_timer; // Timer for HTTP request timeout
+
+    bool started_receiving_get; // Indicates if a GET request has started
+    bool just_started_get; // Indicates if GET data reception has just started
+
+    bool started_receiving_post; // Indicates if a POST request has started
+    bool just_started_post; // Indicates if POST data reception has just started
+
+    bool started_receiving_put; // Indicates if a PUT request has started
+    bool just_started_put; // Indicates if PUT data reception has just started
+
+    bool started_receiving_delete; // Indicates if a DELETE request has started
+    bool just_started_delete; // Indicates if DELETE data reception has just started
+
+    // Buffer to hold the raw bytes received from the UART
+    uint8_t* received_bytes;
+    size_t received_bytes_len; // Length of the received bytes
+    bool is_bytes_request; // Flag to indicate if the request is for bytes
+    bool save_bytes; // Flag to save the received data to a file
+    bool save_received_data; // Flag to save the received data to a file
+} FlipperHTTP;
+
+extern FlipperHTTP fhttp;
+// Global static array for the line buffer
+extern char rx_line_buffer[RX_LINE_BUFFER_SIZE];
+extern uint8_t file_buffer[FILE_BUFFER_SIZE];
+
+// fhttp.last_response holds the last received data from the UART
+
+// Function to append received data to file
+// make sure to initialize the file path before calling this function
+bool flipper_http_append_to_file(
+    const void* data,
+    size_t data_size,
+    bool start_new_file,
+    char* file_path);
+
+FuriString* flipper_http_load_from_file(char* file_path);
+
+// UART worker thread
+/**
+ * @brief      Worker thread to handle UART data asynchronously.
+ * @return     0
+ * @param      context   The context to pass to the callback.
+ * @note       This function will handle received data asynchronously via the callback.
+ */
+// UART worker thread
+int32_t flipper_http_worker(void* context);
+
+// Timer callback function
+/**
+ * @brief      Callback function for the GET timeout timer.
+ * @return     0
+ * @param      context   The context to pass to the callback.
+ * @note       This function will be called when the GET request times out.
+ */
+void get_timeout_timer_callback(void* context);
+
+// UART RX Handler Callback (Interrupt Context)
+/**
+ * @brief      A private callback function to handle received data asynchronously.
+ * @return     void
+ * @param      handle    The UART handle.
+ * @param      event     The event type.
+ * @param      context   The context to pass to the callback.
+ * @note       This function will handle received data asynchronously via the callback.
+ */
+void _flipper_http_rx_callback(
+    FuriHalSerialHandle* handle,
+    FuriHalSerialRxEvent event,
+    void* context);
+
+// UART initialization function
+/**
+ * @brief      Initialize UART.
+ * @return     true if the UART was initialized successfully, false otherwise.
+ * @param      callback  The callback function to handle received data (ex. flipper_http_rx_callback).
+ * @param      context   The context to pass to the callback.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_init(FlipperHTTP_Callback callback, void* context);
+
+// Deinitialize UART
+/**
+ * @brief      Deinitialize UART.
+ * @return     void
+ * @note       This function will stop the asynchronous RX, release the serial handle, and free the resources.
+ */
+void flipper_http_deinit();
+
+// Function to send data over UART with newline termination
+/**
+ * @brief      Send data over UART with newline termination.
+ * @return     true if the data was sent successfully, false otherwise.
+ * @param      data  The data to send over UART.
+ * @note       The data will be sent over UART with a newline character appended.
+ */
+bool flipper_http_send_data(const char* data);
+
+// Function to send a PING request
+/**
+ * @brief      Send a PING request to check if the Wifi Dev Board is connected.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ * @note       This is best used to check if the Wifi Dev Board is connected.
+ * @note       The state will remain INACTIVE until a PONG is received.
+ */
+bool flipper_http_ping();
+
+// Function to list available commands
+/**
+ * @brief      Send a command to list available commands.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_list_commands();
+
+// Function to turn on the LED
+/**
+ * @brief      Allow the LED to display while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_on();
+
+// Function to turn off the LED
+/**
+ * @brief      Disable the LED from displaying while processing.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_led_off();
+
+// Function to parse JSON data
+/**
+ * @brief      Parse JSON data.
+ * @return     true if the JSON data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON data.
+ * @param      json_data The JSON data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json(const char* key, const char* json_data);
+
+// Function to parse JSON array data
+/**
+ * @brief      Parse JSON array data.
+ * @return     true if the JSON array data was parsed successfully, false otherwise.
+ * @param      key       The key to parse from the JSON array data.
+ * @param      index     The index to parse from the JSON array data.
+ * @param      json_data The JSON array data to parse.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_parse_json_array(const char* key, int index, const char* json_data);
+
+// Function to scan for WiFi networks
+/**
+ * @brief      Send a command to scan for WiFi networks.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_scan_wifi();
+
+// Function to save WiFi settings (returns true if successful)
+/**
+ * @brief      Send a command to save WiFi settings.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_save_wifi(const char* ssid, const char* password);
+
+// Function to get IP address of WiFi Devboard
+/**
+ * @brief      Send a command to get the IP address of the WiFi Devboard
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_address();
+
+// Function to get IP address of the connected WiFi network
+/**
+ * @brief      Send a command to get the IP address of the connected WiFi network.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_ip_wifi();
+
+// Function to disconnect from WiFi (returns true if successful)
+/**
+ * @brief      Send a command to disconnect from WiFi.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_disconnect_wifi();
+
+// Function to connect to WiFi (returns true if successful)
+/**
+ * @brief      Send a command to connect to WiFi.
+ * @return     true if the request was successful, false otherwise.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_connect_wifi();
+
+// Function to send a GET request
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request(const char* url);
+
+// Function to send a GET request with headers
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @param      headers  The headers to send with the GET request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request_with_headers(const char* url, const char* headers);
+
+// Function to send a GET request with headers and return bytes
+/**
+ * @brief      Send a GET request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the GET request to.
+ * @param      headers  The headers to send with the GET request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_get_request_bytes(const char* url, const char* headers);
+
+// Function to send a POST request with headers
+/**
+ * @brief      Send a POST request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the POST request to.
+ * @param      headers  The headers to send with the POST request.
+ * @param      data  The data to send with the POST request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_post_request_with_headers(
+    const char* url,
+    const char* headers,
+    const char* payload);
+
+// Function to send a POST request with headers and return bytes
+/**
+ * @brief      Send a POST request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the POST request to.
+ * @param      headers  The headers to send with the POST request.
+ * @param      payload  The data to send with the POST request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_post_request_bytes(const char* url, const char* headers, const char* payload);
+
+// Function to send a PUT request with headers
+/**
+ * @brief      Send a PUT request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the PUT request to.
+ * @param      headers  The headers to send with the PUT request.
+ * @param      data  The data to send with the PUT request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_put_request_with_headers(
+    const char* url,
+    const char* headers,
+    const char* payload);
+
+// Function to send a DELETE request with headers
+/**
+ * @brief      Send a DELETE request to the specified URL.
+ * @return     true if the request was successful, false otherwise.
+ * @param      url  The URL to send the DELETE request to.
+ * @param      headers  The headers to send with the DELETE request.
+ * @param      data  The data to send with the DELETE request.
+ * @note       The received data will be handled asynchronously via the callback.
+ */
+bool flipper_http_delete_request_with_headers(
+    const char* url,
+    const char* headers,
+    const char* payload);
+
+// Function to handle received data asynchronously
+/**
+ * @brief      Callback function to handle received data asynchronously.
+ * @return     void
+ * @param      line     The received line.
+ * @param      context  The context passed to the callback.
+ * @note       The received data will be handled asynchronously via the callback and handles the state of the UART.
+ */
+void flipper_http_rx_callback(const char* line, void* context);
+
+// Function to trim leading and trailing spaces and newlines from a constant string
+char* trim(const char* str);
+/**
+ * @brief Process requests and parse JSON data asynchronously
+ * @param http_request The function to send the request
+ * @param parse_json The function to parse the JSON
+ * @return true if successful, false otherwise
+ */
+bool flipper_http_process_response_async(bool (*http_request)(void), bool (*parse_json)(void));
+
+#endif // FLIPPER_HTTP_H

+ 26 - 140
flip_store/jsmn.h → flip_store/jsmn/jsmn.c

@@ -3,113 +3,20 @@
  *
  * Copyright (c) 2010 Serge Zaitsev
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * [License text continues...]
  */
-#ifndef JSMN_H
-#define JSMN_H
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef JSMN_STATIC
-#define JSMN_API static
-#else
-#define JSMN_API extern
-#endif
-
-/**
-   * JSON type identifier. Basic types are:
-   * 	o Object
-   * 	o Array
-   * 	o String
-   * 	o Other primitive: number, boolean (true/false) or null
-   */
-typedef enum {
-    JSMN_UNDEFINED = 0,
-    JSMN_OBJECT = 1 << 0,
-    JSMN_ARRAY = 1 << 1,
-    JSMN_STRING = 1 << 2,
-    JSMN_PRIMITIVE = 1 << 3
-} jsmntype_t;
-
-enum jsmnerr {
-    /* Not enough tokens were provided */
-    JSMN_ERROR_NOMEM = -1,
-    /* Invalid character inside JSON string */
-    JSMN_ERROR_INVAL = -2,
-    /* The string is not a full JSON packet, more bytes expected */
-    JSMN_ERROR_PART = -3
-};
-
-/**
-   * JSON token description.
-   * type		type (object, array, string etc.)
-   * start	start position in JSON data string
-   * end		end position in JSON data string
-   */
-typedef struct jsmntok {
-    jsmntype_t type;
-    int start;
-    int end;
-    int size;
-#ifdef JSMN_PARENT_LINKS
-    int parent;
-#endif
-} jsmntok_t;
-
-/**
-   * JSON parser. Contains an array of token blocks available. Also stores
-   * the string being parsed now and current position in that string.
-   */
-typedef struct jsmn_parser {
-    unsigned int pos; /* offset in the JSON string */
-    unsigned int toknext; /* next token to allocate */
-    int toksuper; /* superior token node, e.g. parent object or array */
-} jsmn_parser;
 
-/**
-   * Create JSON parser over an array of tokens
-   */
-JSMN_API void jsmn_init(jsmn_parser* parser);
-
-/**
-   * Run JSON parser. It parses a JSON data string into and array of tokens, each
-   * describing
-   * a single JSON object.
-   */
-JSMN_API int jsmn_parse(
-    jsmn_parser* parser,
-    const char* js,
-    const size_t len,
-    jsmntok_t* tokens,
-    const unsigned int num_tokens);
+#include <jsmn/jsmn.h>
+#include <stdlib.h>
+#include <string.h>
 
-#ifndef JSMN_HEADER
 /**
-   * Allocates a fresh unused token from the token pool.
-   */
+ * Allocates a fresh unused token from the token pool.
+ */
 static jsmntok_t*
     jsmn_alloc_token(jsmn_parser* parser, jsmntok_t* tokens, const size_t num_tokens) {
     jsmntok_t* tok;
+
     if(parser->toknext >= num_tokens) {
         return NULL;
     }
@@ -123,8 +30,8 @@ static jsmntok_t*
 }
 
 /**
-   * Fills token type and boundaries.
-   */
+ * Fills token type and boundaries.
+ */
 static void
     jsmn_fill_token(jsmntok_t* token, const jsmntype_t type, const int start, const int end) {
     token->type = type;
@@ -134,8 +41,8 @@ static void
 }
 
 /**
-   * Fills next available token with JSON primitive.
-   */
+ * Fills next available token with JSON primitive.
+ */
 static int jsmn_parse_primitive(
     jsmn_parser* parser,
     const char* js,
@@ -195,8 +102,8 @@ found:
 }
 
 /**
-   * Fills next token with JSON string.
-   */
+ * Fills next token with JSON string.
+ */
 static int jsmn_parse_string(
     jsmn_parser* parser,
     const char* js,
@@ -272,9 +179,18 @@ static int jsmn_parse_string(
 }
 
 /**
-   * Parse JSON string and fill tokens.
-   */
-JSMN_API int jsmn_parse(
+ * Create JSON parser over an array of tokens
+ */
+void jsmn_init(jsmn_parser* parser) {
+    parser->pos = 0;
+    parser->toknext = 0;
+    parser->toksuper = -1;
+}
+
+/**
+ * Parse JSON string and fill tokens.
+ */
+int jsmn_parse(
     jsmn_parser* parser,
     const char* js,
     const size_t len,
@@ -464,34 +380,6 @@ JSMN_API int jsmn_parse(
     return count;
 }
 
-/**
-   * Creates a new parser based over a given buffer with an array of tokens
-   * available.
-   */
-JSMN_API void jsmn_init(jsmn_parser* parser) {
-    parser->pos = 0;
-    parser->toknext = 0;
-    parser->toksuper = -1;
-}
-
-#endif /* JSMN_HEADER */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* JSMN_H */
-
-#ifndef JB_JSMN_EDIT
-#define JB_JSMN_EDIT
-/* Added in by JBlanked on 2024-10-16 for use in Flipper Zero SDK*/
-
-#include <string.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <furi.h>
-
 // Helper function to create a JSON object
 char* jsmn(const char* key, const char* value) {
     int length = strlen(key) + strlen(value) + 8; // Calculate required length
@@ -512,7 +400,7 @@ int jsoneq(const char* json, jsmntok_t* tok, const char* s) {
     return -1;
 }
 
-// return the value of the key in the JSON data
+// Return the value of the key in the JSON data
 char* get_json_value(char* key, char* json_data, uint32_t max_tokens) {
     // Parse the JSON feed
     if(json_data != NULL) {
@@ -776,5 +664,3 @@ char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, in
     free(array_str);
     return values;
 }
-
-#endif /* JB_JSMN_EDIT */

+ 131 - 0
flip_store/jsmn/jsmn.h

@@ -0,0 +1,131 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2010 Serge Zaitsev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * [License text continues...]
+ */
+
+#ifndef JSMN_H
+#define JSMN_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef JSMN_STATIC
+#define JSMN_API static
+#else
+#define JSMN_API extern
+#endif
+
+/**
+     * JSON type identifier. Basic types are:
+     * 	o Object
+     * 	o Array
+     * 	o String
+     * 	o Other primitive: number, boolean (true/false) or null
+     */
+typedef enum {
+    JSMN_UNDEFINED = 0,
+    JSMN_OBJECT = 1 << 0,
+    JSMN_ARRAY = 1 << 1,
+    JSMN_STRING = 1 << 2,
+    JSMN_PRIMITIVE = 1 << 3
+} jsmntype_t;
+
+enum jsmnerr {
+    /* Not enough tokens were provided */
+    JSMN_ERROR_NOMEM = -1,
+    /* Invalid character inside JSON string */
+    JSMN_ERROR_INVAL = -2,
+    /* The string is not a full JSON packet, more bytes expected */
+    JSMN_ERROR_PART = -3
+};
+
+/**
+     * JSON token description.
+     * type		type (object, array, string etc.)
+     * start	start position in JSON data string
+     * end		end position in JSON data string
+     */
+typedef struct {
+    jsmntype_t type;
+    int start;
+    int end;
+    int size;
+#ifdef JSMN_PARENT_LINKS
+    int parent;
+#endif
+} jsmntok_t;
+
+/**
+     * JSON parser. Contains an array of token blocks available. Also stores
+     * the string being parsed now and current position in that string.
+     */
+typedef struct {
+    unsigned int pos; /* offset in the JSON string */
+    unsigned int toknext; /* next token to allocate */
+    int toksuper; /* superior token node, e.g. parent object or array */
+} jsmn_parser;
+
+/**
+     * Create JSON parser over an array of tokens
+     */
+JSMN_API void jsmn_init(jsmn_parser* parser);
+
+/**
+     * Run JSON parser. It parses a JSON data string into and array of tokens, each
+     * describing a single JSON object.
+     */
+JSMN_API int jsmn_parse(
+    jsmn_parser* parser,
+    const char* js,
+    const size_t len,
+    jsmntok_t* tokens,
+    const unsigned int num_tokens);
+
+#ifndef JSMN_HEADER
+/* Implementation has been moved to jsmn.c */
+#endif /* JSMN_HEADER */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSMN_H */
+
+/* Custom Helper Functions */
+#ifndef JB_JSMN_EDIT
+#define JB_JSMN_EDIT
+/* Added in by JBlanked on 2024-10-16 for use in Flipper Zero SDK*/
+
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <furi.h>
+
+// Helper function to create a JSON object
+char* jsmn(const char* key, const char* value);
+// Helper function to compare JSON keys
+int jsoneq(const char* json, jsmntok_t* tok, const char* s);
+
+// Return the value of the key in the JSON data
+char* get_json_value(char* key, char* json_data, uint32_t max_tokens);
+
+// Revised get_json_array_value function
+char* get_json_array_value(char* key, uint32_t index, char* json_data, uint32_t max_tokens);
+
+// Revised get_json_array_values function with correct token skipping
+char** get_json_array_values(char* key, char* json_data, uint32_t max_tokens, int* num_values);
+#endif /* JB_JSMN_EDIT */