HB, OTA etc
This commit is contained in:
@@ -3,19 +3,20 @@
|
||||
#include "esp_log.h"
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "fw_command.h"
|
||||
|
||||
static const char* TAG = "WS";
|
||||
|
||||
static esp_websocket_client_handle_t client = nullptr;
|
||||
static bool connected = false;
|
||||
|
||||
static void ws_event_handler(void *handler_args,
|
||||
static void ws_event_handler(void* handler_args,
|
||||
esp_event_base_t base,
|
||||
int32_t event_id,
|
||||
void *event_data)
|
||||
void* event_data)
|
||||
{
|
||||
switch (event_id) {
|
||||
|
||||
switch (event_id)
|
||||
{
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
connected = true;
|
||||
ESP_LOGI(TAG, "Connected");
|
||||
@@ -31,11 +32,36 @@ static void ws_event_handler(void *handler_args,
|
||||
ESP_LOGE(TAG, "Error");
|
||||
break;
|
||||
|
||||
case WEBSOCKET_EVENT_DATA: {
|
||||
auto *data = (esp_websocket_event_data_t *)event_data;
|
||||
case WEBSOCKET_EVENT_DATA:
|
||||
{
|
||||
auto* data = (esp_websocket_event_data_t*)event_data;
|
||||
|
||||
ESP_LOGI(TAG, "Recv: %.*s", data->data_len, (char*)data->data_ptr);
|
||||
|
||||
// ⚠️ делаем null-terminated копию
|
||||
char buf[512]; // подбери размер под свой максимум
|
||||
int len = data->data_len;
|
||||
|
||||
if (len >= sizeof(buf)) {
|
||||
ESP_LOGW(TAG, "Message too large");
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(buf, data->data_ptr, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
fw_cmd_t cmd {};
|
||||
|
||||
if (parse_fw_command(buf, &cmd)) {
|
||||
ESP_LOGI(TAG, "FW command received");
|
||||
ESP_LOGI(TAG, "URL: %s", cmd.url);
|
||||
ESP_LOGI(TAG, "SHA256: %s", cmd.sha256);
|
||||
|
||||
// пока просто лог, без OTA
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +78,8 @@ void ws_init(const char* uri)
|
||||
|
||||
void ws_start()
|
||||
{
|
||||
if (client) {
|
||||
if (client)
|
||||
{
|
||||
esp_websocket_client_start(client);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +91,8 @@ bool ws_is_connected()
|
||||
|
||||
void ws_send(const char* data)
|
||||
{
|
||||
if (connected && client) {
|
||||
if (connected && client)
|
||||
{
|
||||
esp_websocket_client_send_text(client, data, strlen(data), portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
@@ -79,4 +107,4 @@ void ws_go()
|
||||
CONFIG_SERVER_PORT);
|
||||
ws_init(uri);
|
||||
ws_start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user