Enable logs reporting
This commit is contained in:
@ -196,6 +196,77 @@ char *secure_api_get_dev_certificate()
|
||||
return res;
|
||||
}
|
||||
|
||||
void secure_api_report_log_message(enum LogMessageSeverity severity, const char *msg)
|
||||
{
|
||||
// Prepare signed payload
|
||||
cJSON *obj = cJSON_CreateObject();
|
||||
if (!obj)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed allocate memory to store JSON object!");
|
||||
return;
|
||||
}
|
||||
|
||||
char *severity_s;
|
||||
switch (severity)
|
||||
{
|
||||
case Info:
|
||||
severity_s = "Info";
|
||||
break;
|
||||
case Warn:
|
||||
severity_s = "Warn";
|
||||
break;
|
||||
case Error:
|
||||
severity_s = "Error";
|
||||
break;
|
||||
default:
|
||||
severity_s = "Debug";
|
||||
break;
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject(obj, "severity", severity_s);
|
||||
cJSON_AddStringToObject(obj, "message", msg);
|
||||
char *payload = jwt_gen(obj);
|
||||
cJSON_Delete(obj);
|
||||
|
||||
if (!payload)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to build log report request!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare request body
|
||||
cJSON *json_body = cJSON_CreateObject();
|
||||
if (!json_body)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to allocated memory to store log report request body!");
|
||||
free(payload);
|
||||
return;
|
||||
}
|
||||
cJSON_AddStringToObject(json_body, "payload", payload);
|
||||
free(payload);
|
||||
|
||||
char *body = cJSON_PrintUnformatted(json_body);
|
||||
cJSON_Delete(json_body);
|
||||
|
||||
if (!body)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to allocated memory to store encoded log report request body!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Send request
|
||||
char *res = process_secure_request("/devices_api/logging/record", body);
|
||||
|
||||
free(body);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
ESP_LOGE(TAG, "Log reporting failed!");
|
||||
}
|
||||
|
||||
free(res);
|
||||
}
|
||||
|
||||
sync_response *secure_api_sync_device()
|
||||
{
|
||||
cJSON *obj = cJSON_CreateObject();
|
||||
|
Reference in New Issue
Block a user