mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-08-08 10:30:54 +00:00
170 lines
4.9 KiB
C
170 lines
4.9 KiB
C
// SPDX-FileCopyrightText: 2024 Cesanta Software Limited
|
|
// SPDX-License-Identifier: GPL-2.0-only or commercial
|
|
// Generated by Mongoose Wizard, https://mongoose.ws/wizard/
|
|
|
|
#ifndef MONGOOSE_GLUE_H
|
|
#define MONGOOSE_GLUE_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "mongoose.h"
|
|
|
|
#define WIZARD_ENABLE_HTTP 1
|
|
#define WIZARD_ENABLE_HTTPS 1
|
|
#define WIZARD_ENABLE_HTTP_UI 1
|
|
#define WIZARD_ENABLE_HTTP_UI_LOGIN 1
|
|
|
|
#define WIZARD_ENABLE_WEBSOCKET 1
|
|
|
|
#define WIZARD_ENABLE_MQTT 1
|
|
#define WIZARD_MQTT_URL "mqtt://techquadbit.ddns.net"
|
|
|
|
#define WIZARD_ENABLE_SNTP 1 // Enable time sync.
|
|
#define WIZARD_SNTP_TYPE 0 // 0: default Google, 1: DHCP, 2: custom
|
|
#define WIZARD_SNTP_URL "udp://time.google.com:123" // Custom SNTP server URL
|
|
#define WIZARD_SNTP_INTERVAL_SECONDS 3600 // Frequency of SNTP syncs
|
|
|
|
#define WIZARD_DNS_TYPE 0 // 0: default Google, 1: DHCP, 2: custom
|
|
#define WIZARD_DNS_URL "udp://8.8.8.8:53" // Custom DNS server URL
|
|
#define WIZARD_CAPTIVE_PORTAL 0
|
|
|
|
#define WIZARD_ENABLE_MODBUS 0
|
|
#define WIZARD_MODBUS_PORT 502
|
|
|
|
#ifndef WIZARD_REBOOT_TIMEOUT_MS
|
|
#define WIZARD_REBOOT_TIMEOUT_MS 500
|
|
#endif
|
|
|
|
void mongoose_init(void); // Initialise Mongoose
|
|
void mongoose_poll(void); // Poll Mongoose
|
|
extern struct mg_mgr g_mgr; // Mongoose event manager
|
|
|
|
void mongoose_set_http_handlers(const char *name, ...);
|
|
void mongoose_add_ws_handler(unsigned ms, void (*)(struct mg_connection *));
|
|
|
|
struct mongoose_mqtt_handlers {
|
|
struct mg_connection *(*connect_fn)(mg_event_handler_t);
|
|
void (*tls_init_fn)(struct mg_connection *);
|
|
void (*on_connect_fn)(struct mg_connection *, int);
|
|
void (*on_message_fn)(struct mg_connection *, struct mg_str, struct mg_str);
|
|
void (*on_cmd_fn)(struct mg_connection *, struct mg_mqtt_message *);
|
|
};
|
|
void mongoose_set_mqtt_handlers(struct mongoose_mqtt_handlers *);
|
|
|
|
struct mongoose_modbus_handlers {
|
|
bool (*read_reg_fn)(uint16_t address, uint16_t *value);
|
|
bool (*write_reg_fn)(uint16_t address, uint16_t value);
|
|
};
|
|
void mongoose_set_modbus_handlers(struct mongoose_modbus_handlers *);
|
|
|
|
#define run_mongoose() \
|
|
do { \
|
|
mongoose_init(); \
|
|
for (;;) { \
|
|
mongoose_poll(); \
|
|
} \
|
|
} while (0)
|
|
|
|
#if WIZARD_ENABLE_MQTT
|
|
void glue_lock_init(void); // Initialise global Mongoose mutex
|
|
void glue_lock(void); // Lock global Mongoose mutex
|
|
void glue_unlock(void); // Unlock global Mongoose mutex
|
|
#else
|
|
#define glue_lock_init()
|
|
#define glue_lock()
|
|
#define glue_unlock()
|
|
#endif
|
|
|
|
// Increment device change state counter - trigger UI refresh
|
|
void glue_update_state(void);
|
|
|
|
// Firmware Glue
|
|
|
|
|
|
|
|
extern struct mg_connection *g_mqtt_conn; // MQTT client connection
|
|
|
|
void glue_mqtt_tls_init(struct mg_connection *);
|
|
struct mg_connection *glue_mqtt_connect(mg_event_handler_t ev_hanler_fn);
|
|
void glue_mqtt_on_connect(struct mg_connection *c, int code);
|
|
void glue_mqtt_on_message(struct mg_connection *c, struct mg_str topic,
|
|
struct mg_str data);
|
|
void glue_mqtt_on_cmd(struct mg_connection *c, struct mg_mqtt_message *mm);
|
|
|
|
|
|
void glue_sntp_on_time(uint64_t utc_time_in_milliseconds);
|
|
|
|
|
|
int glue_authenticate(const char *user, const char *pass);
|
|
|
|
void glue_start_reboot(struct mg_str); // Start an action
|
|
bool glue_check_reboot(void); // Check if action is still in progress
|
|
|
|
void glue_start_reformat(struct mg_str); // Start an action
|
|
bool glue_check_reformat(void); // Check if action is still in progress
|
|
|
|
void *glue_ota_begin_firmware_update(char *file_name, size_t total_size);
|
|
bool glue_ota_end_firmware_update(void *context);
|
|
bool glue_ota_write_firmware_update(void *context, void *buf, size_t len);
|
|
|
|
void *glue_file_open_file_upload(char *file_name, size_t total_size);
|
|
bool glue_file_close_file_upload(void *context);
|
|
bool glue_file_write_file_upload(void *context, void *buf, size_t len);
|
|
|
|
void glue_reply_graph_data(struct mg_connection *, struct mg_http_message *);
|
|
struct state {
|
|
int speed;
|
|
int temperature;
|
|
int humidity;
|
|
int uptime;
|
|
char version[20];
|
|
bool online;
|
|
bool lights;
|
|
int level;
|
|
};
|
|
void glue_get_state(struct state *);
|
|
|
|
struct leds {
|
|
bool led1;
|
|
bool led2;
|
|
bool led3;
|
|
};
|
|
void glue_get_leds(struct leds *);
|
|
void glue_set_leds(struct leds *);
|
|
|
|
struct network_settings {
|
|
char ip_address[20];
|
|
char gw_address[20];
|
|
char netmask[20];
|
|
bool dhcp;
|
|
};
|
|
void glue_get_network_settings(struct network_settings *);
|
|
void glue_set_network_settings(struct network_settings *);
|
|
|
|
struct settings {
|
|
char string_val[40];
|
|
char log_level[10];
|
|
double double_val;
|
|
int int_val;
|
|
bool bool_val;
|
|
};
|
|
void glue_get_settings(struct settings *);
|
|
void glue_set_settings(struct settings *);
|
|
|
|
struct security {
|
|
char admin_password[40];
|
|
char user_password[40];
|
|
};
|
|
void glue_get_security(struct security *);
|
|
void glue_set_security(struct security *);
|
|
|
|
void glue_reply_loglevels(struct mg_connection *, struct mg_http_message *);
|
|
void glue_reply_events(struct mg_connection *, struct mg_http_message *);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif // MONGOOSE_GLUE_H
|