Files
iot_skeleton/esp32/main/protocol_test.cpp
2026-04-03 23:28:02 +03:00

33 lines
719 B
C++

#include "protocol_test.h"
#include "protocol.h"
#include "cJSON.h"
#include "esp_log.h"
#include "esp_timer.h"
static const char* TAG = "protocol_test";
void protocol_run_tests()
{
ESP_LOGI(TAG, "Running protocol test...");
ProtocolMessage msg;
msg.v = 1;
msg.id = "msg-001";
msg.type = "command";
msg.deviceId = "esp32-01";
msg.ts = esp_timer_get_time();
msg.payload = cJSON_CreateObject();
cJSON_AddStringToObject(msg.payload, "command", "ping");
cJSON* json = protocol_message_to_json(&msg);
char* json_str = cJSON_Print(json);
ESP_LOGI(TAG, "ProtocolMessage JSON:\n%s", json_str);
cJSON_Delete(json);
free(json_str);
cJSON_Delete(msg.payload);
}