From 54eaadf551f9241d23df5f030ebcd9fd75be2d78 Mon Sep 17 00:00:00 2001 From: Bogdan Pilyugin Date: Thu, 17 Aug 2023 10:49:22 +0200 Subject: [PATCH] implemented example of using user defined variables --- components/webguiapp | 2 +- main/include/AppConfiguration.h | 1 + main/include/Application.h | 7 ++--- main/main.c | 2 ++ main/src/AppConfiguration.c | 2 +- main/src/RestApiHandlersApp.c | 49 +++++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 main/src/RestApiHandlersApp.c diff --git a/components/webguiapp b/components/webguiapp index e815020..4ec665e 160000 --- a/components/webguiapp +++ b/components/webguiapp @@ -1 +1 @@ -Subproject commit e8150202106520873416794e0bce0f505b8d79d2 +Subproject commit 4ec665e5d97a3762a403291ea6978210554c5bad diff --git a/main/include/AppConfiguration.h b/main/include/AppConfiguration.h index 3951517..c245633 100644 --- a/main/include/AppConfiguration.h +++ b/main/include/AppConfiguration.h @@ -60,5 +60,6 @@ esp_err_t ResetInitAppConfig(void); void LoadDefaultReset(void); void DelayedRestart(void); +void RegAppVariables(void); #endif /* MAIN_INCLUDE_APPCONFIGURATION_H_ */ diff --git a/main/include/Application.h b/main/include/Application.h index f076af1..9e215b5 100644 --- a/main/include/Application.h +++ b/main/include/Application.h @@ -24,11 +24,8 @@ #include "webguiapp.h" #include "esp_err.h" -#include "jRead.h" -#include "jWrite.h" #include "AppConfiguration.h" - -#define EXPECTED_MAX_DATA_RESPONSE_SIZE (2048) +#include "SystemApplication.h" typedef enum { @@ -71,6 +68,7 @@ int key2; #define DATA_MESSAGE_TYPE_REQUEST (2) #define DATA_MESSAGE_TYPE_RESPONSE (3) +/* typedef struct { char *inputDataBuffer; @@ -89,6 +87,7 @@ typedef struct } parsedData; int err_code; } data_message_t; +*/ typedef struct { diff --git a/main/main.c b/main/main.c index 163c5f7..4b4666b 100644 --- a/main/main.c +++ b/main/main.c @@ -22,6 +22,8 @@ void app_main(void) regUserEventHandler(&UserMQTTEventHndlr, (void*)my_context_data); regTimeSyncCallback(&TimeObtainHandler); + RegAppVariables(); + WebGuiAppInit(); if (GetUserAppNeedReset()) { diff --git a/main/src/AppConfiguration.c b/main/src/AppConfiguration.c index 5348f29..ece54cb 100644 --- a/main/src/AppConfiguration.c +++ b/main/src/AppConfiguration.c @@ -35,7 +35,7 @@ #define STORAGE_NAMESPACE "storage" #define TAG "AppConfiguration" -static APP_CONFIG AppConfig; +APP_CONFIG AppConfig; void UserAppInit(void) { diff --git a/main/src/RestApiHandlersApp.c b/main/src/RestApiHandlersApp.c new file mode 100644 index 0000000..090c180 --- /dev/null +++ b/main/src/RestApiHandlersApp.c @@ -0,0 +1,49 @@ + /*! Copyright 2023 Bogdan Pilyugin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * \file RestApiHandlersApp.c + * \version 1.0 + * \date 2023-08-17 + * \author Bogdan Pilyugin + * \brief + * \details + * \copyright Apache License, Version 2.0 + */ + +#include "Application.h" +#include "SystemApplication.h" + +extern APP_CONFIG AppConfig; + +static void funct_time(char *argres, int rw) +{ + time_t now; + time(&now); + snprintf(argres, MAX_DYNVAR_LENGTH, "%d", (int) now); +} + +const rest_var_t ApplicationVariables[] = + { + /*FUNCTIONS*/ + { 0, "mytime", &funct_time, VAR_FUNCT, R, 0, 0 }, + { 0, "myvar", &AppConfig.test, VAR_INT, R, 0, 0 } + + }; + + + +void RegAppVariables(void) +{ + SetAppVars((rest_var_t*)ApplicationVariables, sizeof(ApplicationVariables) / sizeof(rest_var_t)); +}