diff --git a/include/HTTPServer.h b/include/HTTPServer.h index 41fd938..566d8c6 100644 --- a/include/HTTPServer.h +++ b/include/HTTPServer.h @@ -86,9 +86,6 @@ typedef struct void (*HandlerRoutine)(char *VarData, void *arg); } dyn_var_handler_t; -void regHTTPPrintCustom(int (*print_handler)(httpd_req_t *req, char *buf, char *var, int arg)); -void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData)); - esp_err_t start_file_server(void); HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData); int HTTPPrint(httpd_req_t *req, char* buf, char* var); diff --git a/include/MQTT.h b/include/MQTT.h index 4d36659..5258ea7 100644 --- a/include/MQTT.h +++ b/include/MQTT.h @@ -73,7 +73,6 @@ typedef struct mqtt_client_t* GetMQTTHandlesPool(int idx); QueueHandle_t GetMQTTSendQueue(int idx); void ComposeTopic(char *topic, int idx, char *service_name, char *direct); -void regUserEventHandler(void (*event_handler)(int idx, void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data), void* user_arg); void SystemDataHandler(char *data, uint32_t len, int idx); mqtt_app_err_t PublicTestMQTT(int idx); diff --git a/include/NetTransport.h b/include/NetTransport.h index 673b935..5980406 100644 --- a/include/NetTransport.h +++ b/include/NetTransport.h @@ -108,7 +108,6 @@ void GetRFC3339Time(char *t); void StartTimeGet(void); esp_err_t StartOTA(void); -void regHookBeforeUpdate(void (*before_update)(void)); char* GetAvailVersion(); char* GetUpdateStatus(); diff --git a/include/UserCallbacks.h b/include/UserCallbacks.h new file mode 100644 index 0000000..890e4a0 --- /dev/null +++ b/include/UserCallbacks.h @@ -0,0 +1,42 @@ + /* 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 name: UserCallbacks.h + * Project: webguiapp_ref_implement + * Created on: 2023-04-22 + * Author: bogdan + * Description: + */ + +#ifndef COMPONENTS_WEBGUIAPP_INCLUDE_USERCALLBACKS_H_ +#define COMPONENTS_WEBGUIAPP_INCLUDE_USERCALLBACKS_H_ +#include "HTTPServer.h" + +//Callback for current time obtain notification +void regTimeSyncCallback(void (*time_sync)(struct timeval *tv)); + +//Callback called just before OTA, aimed user can finish all job must finished on update and reboot +void regHookBeforeUpdate(void (*before_update)(void)); + +//MQTT incoming data callback +void regUserEventHandler(void (*event_handler)(int idx, void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data), void* user_arg); + +//User handler of output '~var~' styled dynamic variables. Calls on give out files in response to GET requests. +void regHTTPPrintCustom(int (*print_handler)(httpd_req_t *req, char *buf, char *var, int arg)); + +//User handler of variables 'var1=value1&var2=value2' styled in POST requests. +void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData)); + + +#endif /* COMPONENTS_WEBGUIAPP_INCLUDE_USERCALLBACKS_H_ */ diff --git a/include/webguiapp.h b/include/webguiapp.h index ab37254..05f2715 100644 --- a/include/webguiapp.h +++ b/include/webguiapp.h @@ -34,6 +34,8 @@ #include "esp_system.h" #include "driver/spi_master.h" +#include "UserCallbacks.h" + esp_err_t spi_device_polling_transmit_synchronized(spi_device_handle_t handle, spi_transaction_t *trans_desc); bool GetUserAppNeedReset(void); diff --git a/src/HTTPPostSystem.c b/src/HTTPPostSystem.c index 7258519..a129521 100644 --- a/src/HTTPPostSystem.c +++ b/src/HTTPPostSystem.c @@ -25,6 +25,7 @@ #include "LoRaWAN.h" #include "Helpers.h" #include "MQTT.h" +#include "UserCallbacks.h" static const char *TAG = "HTTPServerPost"; diff --git a/src/HTTPPrintSystem.c b/src/HTTPPrintSystem.c index fac817e..9b52fe4 100644 --- a/src/HTTPPrintSystem.c +++ b/src/HTTPPrintSystem.c @@ -30,6 +30,7 @@ #include "romfs.h" #include "esp_idf_version.h" #include "jWrite.h" +#include "UserCallbacks.h" static const char *TAG = "HTTPServerPrint"; diff --git a/src/MQTT.c b/src/MQTT.c index 9f7b647..d8e89fd 100644 --- a/src/MQTT.c +++ b/src/MQTT.c @@ -23,6 +23,7 @@ #include "Helpers.h" #include "NetTransport.h" #include "MQTT.h" +#include "UserCallbacks.h" #define MQTT_DEBUG_MODE 1 diff --git a/src/SNTP.c b/src/SNTP.c index 76ebf06..f619ee0 100644 --- a/src/SNTP.c +++ b/src/SNTP.c @@ -22,10 +22,19 @@ #include "esp_sntp.h" #include "esp_timer.h" #include "NetTransport.h" +#include "UserCallbacks.h" #define YEAR_BASE (1900) //tm structure base year static uint32_t UpTime = 0; +//Pointer to extend user on time got callback +static void (*time_sync_notif)(struct timeval *tv) = NULL; + +void regTimeSyncCallback(void (*time_sync)(struct timeval *tv)) +{ + time_sync_notif = time_sync; +} + static void initialize_sntp(void); @@ -52,7 +61,8 @@ static void obtain_time(void *pvParameter) static void time_sync_notification_cb(struct timeval *tv) { - + if(time_sync_notif) + time_sync_notif(tv); } static void initialize_sntp(void)