update project
This commit is contained in:
32
esp32/main/protocol_test.cpp
Normal file
32
esp32/main/protocol_test.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user