added user registered mqtt data handler, fixed routine register post and print
This commit is contained in:
parent
0ba0da77af
commit
cabc2904ea
|
|
@ -61,8 +61,8 @@ typedef struct
|
|||
void (*HandlerRoutine)(char *VarData, void *arg);
|
||||
} dyn_var_handler_t;
|
||||
|
||||
void regHTTPPrintCustom(int (*print_handler));
|
||||
void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler));
|
||||
void regHTTPPrintCustom(int (*print_handler)(httpd_req_t *req, char *buf, char *var));
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ typedef struct
|
|||
mqtt_client_t* GetMQTTHandlesPool(int idx);
|
||||
QueueHandle_t GetMQTTSendQueue(int idx);
|
||||
|
||||
void ControlDataHandler(char *data, uint32_t len, int idx);
|
||||
void regUserDataHandler(void (*data_handler)(char *data, uint32_t len, int idx));
|
||||
void SystemDataHandler(char *data, uint32_t len, int idx);
|
||||
|
||||
#endif /* MAIN_INCLUDE_MQTT_H_ */
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ static HTTP_IO_RESULT HTTPPostMemJson(httpd_req_t *req, char *PostData);
|
|||
|
||||
HTTP_IO_RESULT (*AfterPostHandlerCust)(httpd_req_t *req, const char *filename, char *PostData);
|
||||
|
||||
void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler))
|
||||
void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData))
|
||||
{
|
||||
AfterPostHandlerCust = post_handler;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ typedef enum
|
|||
//Pointer to extend user implemented print handler
|
||||
static int (*HTTPPrintCust)(httpd_req_t *req, char *buf, char *var);
|
||||
|
||||
void regHTTPPrintCustom(int (*print_handler))
|
||||
void regHTTPPrintCustom(int (*print_handler)(httpd_req_t *req, char *buf, char *var))
|
||||
{
|
||||
HTTPPrintCust = print_handler;
|
||||
}
|
||||
|
|
|
|||
13
src/MQTT.c
13
src/MQTT.c
|
|
@ -26,7 +26,6 @@
|
|||
#include "MQTT.h"
|
||||
|
||||
#define CH_MESSAGE_BUFER_LENTH 32 //size of mqtt queue
|
||||
|
||||
#define MQTT_RECONNECT_CHANGE_ADAPTER 3
|
||||
|
||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||
|
|
@ -44,6 +43,13 @@ mqtt_client_t mqtt[CONFIG_MQTT_CLIENTS_NUM] = { 0 };
|
|||
|
||||
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data);
|
||||
|
||||
void (*UserDataHandler)(char *data, uint32_t len, int idx);
|
||||
|
||||
void regUserDataHandler(void (*data_handler)(char *data, uint32_t len, int idx))
|
||||
{
|
||||
UserDataHandler = data_handler;
|
||||
}
|
||||
|
||||
mqtt_client_t* GetMQTTHandlesPool(int idx)
|
||||
{
|
||||
return &mqtt[idx];
|
||||
|
|
@ -152,7 +158,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||
"SYSTEM");
|
||||
if (!memcmp(topic, event->topic, event->topic_len))
|
||||
{
|
||||
ControlDataHandler(event->data, event->data_len, ctx->mqtt_index);
|
||||
SystemDataHandler(event->data, event->data_len, ctx->mqtt_index);
|
||||
ESP_LOGI(TAG, "Control data handler on client %d", ctx->mqtt_index);
|
||||
}
|
||||
//Check if topic is USER and pass data to handler
|
||||
|
|
@ -163,7 +169,8 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||
"USER");
|
||||
if (!memcmp(topic, event->topic, event->topic_len))
|
||||
{
|
||||
//Here TODO registered user define received data handler
|
||||
if (UserDataHandler != NULL)
|
||||
UserDataHandler(event->data, event->data_len, ctx->mqtt_index);
|
||||
ESP_LOGI(TAG, "Screen data handler on client %d", ctx->mqtt_index);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ file_send_err:
|
|||
return api_err;
|
||||
}
|
||||
|
||||
void ControlDataHandler(char *data, uint32_t len, int idx)
|
||||
void SystemDataHandler(char *data, uint32_t len, int idx)
|
||||
{
|
||||
struct jReadElement result;
|
||||
char URL[MAX_FILENAME_LENTH + 1];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user