0
0
Fork 0

feat(wifi) add cmd and module_id to response packet

This commit is contained in:
kerms 2024-03-20 10:37:12 +08:00
parent 070abcfeee
commit 2ac6d894b8
5 changed files with 21 additions and 10 deletions

View File

@ -348,6 +348,8 @@ static void send_heartbeat(void *arg)
int err;
err = httpd_ws_send_frame_async(client_info->hd, client_info->fd, &ws_pkt);
if (err) {
ws_rm_fd(client_info->fd);
httpd_sess_trigger_close(client_info->hd, client_info->fd);
ESP_LOGE(TAG, "hb send err: %s", esp_err_to_name(err));
}
}

View File

@ -3,6 +3,16 @@
#include <lwip/ip4_addr.h>
#define WIFI_API_MODULE_ID 1
typedef enum wifi_api_json_cmd_t {
UNKNOWN = 0,
WIFI_API_JSON_GET_AP_INFO,
WIFI_API_JSON_CONNECT,
WIFI_API_JSON_GET_SCAN,
WIFI_API_JSON_DISCONNECT,
} wifi_api_json_cmd_t;
typedef struct wifi_api_ap_info_t {
ip4_addr_t ip;
ip4_addr_t gateway;

View File

@ -107,7 +107,7 @@ int wifi_api_json_disconnect(api_json_req_t *req)
static int wifi_api_json_init(api_json_module_cfg_t *cfg)
{
cfg->on_req = on_json_req;
cfg->module_id = 1;
cfg->module_id = WIFI_API_MODULE_ID;
return 0;
}

View File

@ -1,13 +1,4 @@
#ifndef WIFI_API_JSON_H_GUARD
#define WIFI_API_JSON_H_GUARD
typedef enum wifi_api_json_cmd_t {
UNKNOWN = 0,
WIFI_API_JSON_GET_AP_INFO,
WIFI_API_JSON_CONNECT,
WIFI_API_JSON_GET_SCAN,
WIFI_API_JSON_DISCONNECT,
} wifi_api_json_cmd_t;
#endif //WIFI_API_JSON_H_GUARD

View File

@ -3,12 +3,19 @@
#include "wifi_json_utils.h"
#include "wifi_api.h"
static void wifi_api_json_set_header(cJSON *root, uint16_t cmd)
{
cJSON_AddNumberToObject(root, "cmd", cmd);
cJSON_AddNumberToObject(root, "module", WIFI_API_MODULE_ID);
}
cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info)
{
cJSON *root;
root = cJSON_CreateObject();
wifi_api_json_set_header(root, WIFI_API_JSON_GET_AP_INFO);
cJSON_AddStringToObject(root, "ip", ip4addr_ntoa(&ap_info->ip));
cJSON_AddStringToObject(root, "gateway", ip4addr_ntoa(&ap_info->gateway));
cJSON_AddStringToObject(root, "netmask", ip4addr_ntoa(&ap_info->netmask));
@ -30,6 +37,7 @@ cJSON *wifi_api_json_serialize_scan_list(wifi_api_ap_info_t *aps_info, uint16_t
char mac_str[18];
root = cJSON_CreateObject();
wifi_api_json_set_header(root, WIFI_API_JSON_GET_SCAN);
cJSON *scan_list = cJSON_AddArrayToObject(root, "scan_list");
for (int i = 0; i < count; ++i) {