add: status for mqtt

fix: refactor connection handlers
This commit is contained in:
Tobias Reisinger 2020-06-26 01:01:46 +02:00
parent 2bc11ee829
commit 6c6e5023da
19 changed files with 534 additions and 183 deletions

View file

@ -30,8 +30,9 @@ typedef struct
char group[256];
log_level_t log_level;
run_type_t run_type;
char server_port[6];
uint16_t server_port;
uint16_t discovery_port;
uint16_t mqtt_port;
char not_found_file[256];
char not_found_file_type[256];
char not_found_content[256];

View file

@ -0,0 +1,10 @@
#ifndef CORE_ENDPOINTS_API_V1_WS_H
#define CORE_ENDPOINTS_API_V1_WS_H
#include <router.h>
void
api_v1_ws_relays(struct mg_connection *nc, struct http_message *hm, endpoint_args_t *args, endpoint_response_t *response);
#endif /* CORE_ENDPOINTS_API_V1_WS_H */

View file

@ -2,6 +2,9 @@
#define CORE_HANDLERS_H
void
handler_connection(struct mg_connection *c, int ev, void *p);
handler_http(struct mg_connection *nc, int ev, void *p);
void
handler_mqtt(struct mg_connection *nc, int ev, void *p);
#endif /* CORE_HANDLERS_H */

View file

@ -17,6 +17,7 @@ typedef struct
int number;
int controller_id;
int active_schedule_id;
int is_on;
schedule_t *active_schedule;
schedule_t *schedules[7];
} relay_t;
@ -24,14 +25,14 @@ typedef struct
int
relay_save();
int
relay_remove();
void
relay_reload_active_schedule(relay_t *relay);
cJSON*
relay_to_json();
relay_to_json(relay_t *relay);
cJSON*
relay_list_to_json(relay_t **relays);
void
relay_free(relay_t *relay);
@ -39,9 +40,6 @@ relay_free(relay_t *relay);
void
relay_free_list(relay_t **relays_list);
relay_t**
relay_get_by_simple(const char *key, const void *value, intptr_t bind_func, int bind_func_param);
relay_t*
relay_get_by_id(int id);

View file

@ -12,7 +12,9 @@ typedef enum
HTTP_METHOD_POST = (1 << 1),
HTTP_METHOD_PUT = (1 << 2),
HTTP_METHOD_DELETE = (1 << 3),
HTTP_METHOD_OPTIONS = (1 << 4)
HTTP_METHOD_OPTIONS = (1 << 4),
HTTP_METHOD_WEBSOCKET = (1 << 5)
} http_method_e;
endpoint_t*

26
include/status.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef CORE_STATUS_H
#define CORE_STATUS_H
#include <models/controller.h>
extern relay_t **global_relay_status_list;
void
status_init();
void
status_reload_entry(int relay_id);
void
status_update_entry(int relay_id, int is_on);
void
status_broadcast(struct mg_mgr *mgr);
void
status_send(struct mg_connection *c);
void
status_free();
#endif /* CORE_STATUS_H */