#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "cJSON.h"
#include "esp_log.h"
static const char *TAG = "example";
void create_get_db_response(cJSON *root)
{
cJSON_AddStringToObject(root, "response_type", "Sup");
cJSON *tags = cJSON_CreateArray();
for (size_t i = 0; i < 3; i++)
{
cJSON *tag = cJSON_CreateObject();
cJSON_AddNumberToObject(tag, "serial_number", i);
cJSON_AddStringToObject(tag, "tag_id", "0");
cJSON_AddStringToObject(tag, "tag_name", "test");
cJSON_AddItemToArray(tags, tag);
}
cJSON_AddItemToObject(root, "tags", tags);
char *json_str = cJSON_Print(root);
cJSON_Delete(root);
printf("Sending JSON: %s", json_str);
}
void app_main() {
printf("Hello, Wokwi!\n");
cJSON *root = cJSON_CreateObject();
create_get_db_response(root);
while (true) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1