new buzzer component
This commit is contained in:
@@ -9,6 +9,6 @@ idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "include" "lib/cAT/src"
|
||||
PRIV_INCLUDE_DIRS "src"
|
||||
PRIV_REQUIRES nvs_flash app_update json driver esp_http_client esp_netif esp_wifi esp_timer esp_hw_support
|
||||
REQUIRES network config evse peripherals protocols ocpp)
|
||||
REQUIRES network config evse peripherals protocols ocpp auth)
|
||||
|
||||
set_source_files_properties(lib/cAT/src/cat.c PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized)
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
#include "json.h"
|
||||
#include "mqtt.h"
|
||||
#include "wifi.h"
|
||||
#include "network.h"
|
||||
#include "timeout_utils.h"
|
||||
#include "evse_error.h"
|
||||
#include "evse_api.h"
|
||||
#include "auth.h"
|
||||
#include "evse_limits.h"
|
||||
#include "evse_state.h"
|
||||
#include "evse_config.h"
|
||||
@@ -44,9 +45,9 @@ cJSON *json_get_evse_config(void)
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddNumberToObject(root, "maxChargingCurrent", evse_get_max_charging_current());
|
||||
cJSON_AddNumberToObject(root, "chargingCurrent", evse_get_charging_current() / 10.0);
|
||||
cJSON_AddNumberToObject(root, "defaultChargingCurrent", evse_get_default_charging_current() / 10.0);
|
||||
cJSON_AddBoolToObject(root, "requireAuth", evse_is_require_auth());
|
||||
cJSON_AddNumberToObject(root, "chargingCurrent", evse_get_charging_current());
|
||||
cJSON_AddNumberToObject(root, "defaultChargingCurrent", evse_get_default_charging_current());
|
||||
cJSON_AddBoolToObject(root, "requireAuth", auth_is_enabled());
|
||||
cJSON_AddBoolToObject(root, "socketOutlet", evse_get_socket_outlet());
|
||||
cJSON_AddBoolToObject(root, "rcm", evse_is_rcm());
|
||||
cJSON_AddNumberToObject(root, "temperatureThreshold", evse_get_temp_threshold());
|
||||
@@ -84,15 +85,15 @@ esp_err_t json_set_evse_config(cJSON *root)
|
||||
}
|
||||
if (cJSON_IsNumber(cJSON_GetObjectItem(root, "chargingCurrent")))
|
||||
{
|
||||
RETURN_ON_ERROR(evse_set_charging_current(cJSON_GetObjectItem(root, "chargingCurrent")->valuedouble * 10));
|
||||
RETURN_ON_ERROR(evse_set_charging_current(cJSON_GetObjectItem(root, "chargingCurrent")->valuedouble));
|
||||
}
|
||||
if (cJSON_IsNumber(cJSON_GetObjectItem(root, "defaultChargingCurrent")))
|
||||
{
|
||||
RETURN_ON_ERROR(evse_set_default_charging_current(cJSON_GetObjectItem(root, "defaultChargingCurrent")->valuedouble * 10));
|
||||
RETURN_ON_ERROR(evse_set_default_charging_current(cJSON_GetObjectItem(root, "defaultChargingCurrent")->valuedouble));
|
||||
}
|
||||
if (cJSON_IsBool(cJSON_GetObjectItem(root, "requireAuth")))
|
||||
{
|
||||
evse_set_require_auth(cJSON_IsTrue(cJSON_GetObjectItem(root, "requireAuth")));
|
||||
auth_set_enabled(cJSON_IsTrue(cJSON_GetObjectItem(root, "requireAuth")));
|
||||
}
|
||||
if (cJSON_IsBool(cJSON_GetObjectItem(root, "socketOutlet")))
|
||||
{
|
||||
@@ -342,7 +343,7 @@ cJSON *json_get_state(void)
|
||||
cJSON_AddStringToObject(root, "state", evse_state_to_str(evse_get_state()));
|
||||
cJSON_AddBoolToObject(root, "available", evse_config_is_available());
|
||||
cJSON_AddBoolToObject(root, "enabled", evse_config_is_enabled());
|
||||
cJSON_AddBoolToObject(root, "pendingAuth", evse_is_require_auth());
|
||||
cJSON_AddBoolToObject(root, "pendingAuth", auth_is_enabled());
|
||||
cJSON_AddBoolToObject(root, "limitReached", evse_is_limit_reached());
|
||||
|
||||
uint32_t error = evse_error_get_bits();
|
||||
@@ -389,14 +390,24 @@ cJSON *json_get_state(void)
|
||||
}
|
||||
|
||||
|
||||
cJSON_AddNumberToObject(root, "sessionTime", evse_get_session_start());
|
||||
cJSON_AddNumberToObject(root, "chargingTime", 0);
|
||||
cJSON_AddNumberToObject(root, "consumption", 0);
|
||||
// dentro da sua função de gerar JSON:
|
||||
evse_session_t sess;
|
||||
if (evse_get_session(&sess)) {
|
||||
// Há sessão atual ou última disponível
|
||||
cJSON_AddNumberToObject(root, "sessionTime", (double)sess.start_tick);
|
||||
cJSON_AddNumberToObject(root, "chargingTime", (double)sess.duration_s);
|
||||
cJSON_AddNumberToObject(root, "consumption", (double)sess.energy_wh);
|
||||
} else {
|
||||
// Nenhuma sessão disponível
|
||||
cJSON_AddNullToObject(root, "sessionTime");
|
||||
cJSON_AddNumberToObject(root, "chargingTime", 0);
|
||||
cJSON_AddNumberToObject(root, "consumption", 0);
|
||||
}
|
||||
|
||||
// 1) Arrays temporários para ler dados do medidor
|
||||
float voltage_f[EVSE_METER_PHASE_COUNT];
|
||||
float current_f[EVSE_METER_PHASE_COUNT];
|
||||
uint32_t power_w[ EVSE_METER_PHASE_COUNT];
|
||||
int power_w[ EVSE_METER_PHASE_COUNT];
|
||||
|
||||
// 2) Leitura dos valores via API pública
|
||||
evse_meter_get_voltage(voltage_f); // já em volts
|
||||
@@ -408,7 +419,7 @@ cJSON *json_get_state(void)
|
||||
|
||||
// 6) Arrays de tensão e corrente
|
||||
cJSON_AddItemToObject(root, "power",
|
||||
cJSON_CreateFloatArray(power_w, EVSE_METER_PHASE_COUNT));
|
||||
cJSON_CreateIntArray(power_w, EVSE_METER_PHASE_COUNT));
|
||||
cJSON_AddItemToObject(root, "voltage",
|
||||
cJSON_CreateFloatArray(voltage_f, EVSE_METER_PHASE_COUNT));
|
||||
cJSON_AddItemToObject(root, "current",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "timeout_utils.h"
|
||||
#include "wifi.h"
|
||||
#include "network.h"
|
||||
//#include "rest.h"
|
||||
|
||||
static void restart_func(void* arg)
|
||||
|
||||
Reference in New Issue
Block a user