feat: Add chip temperature to STATUS reply
Use IDF 5.x temperature_sensor driver. Adds temp=XX.X field to STATUS response. Graceful fallback if sensor init fails.
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include "esp_https_ota.h"
|
||||
#include "esp_http_client.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/temperature_sensor.h"
|
||||
#include "mdns.h"
|
||||
|
||||
#include "lwip/inet.h"
|
||||
@@ -105,6 +106,9 @@ static uint32_t s_energy_idx = 0;
|
||||
static bool s_ble_enabled = false;
|
||||
static uint8_t s_ble_own_addr_type;
|
||||
|
||||
/* Chip temperature sensor */
|
||||
static temperature_sensor_handle_t s_temp_handle = NULL;
|
||||
|
||||
/* UDP socket for CSI data transmission */
|
||||
static int s_udp_socket = -1;
|
||||
static struct sockaddr_in s_dest_addr;
|
||||
@@ -716,6 +720,11 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
|
||||
const esp_app_desc_t *app_desc = esp_app_get_description();
|
||||
|
||||
float chip_temp = 0.0f;
|
||||
if (s_temp_handle) {
|
||||
temperature_sensor_get_celsius(s_temp_handle, &chip_temp);
|
||||
}
|
||||
|
||||
char uptime_str[32];
|
||||
if (days > 0) {
|
||||
snprintf(uptime_str, sizeof(uptime_str), "%dd%dh%dm", days, hours, mins);
|
||||
@@ -726,11 +735,12 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
}
|
||||
|
||||
snprintf(reply, reply_size,
|
||||
"OK STATUS uptime=%s heap=%lu rssi=%d tx_power=%d rate=%d hostname=%s version=%s adaptive=%s motion=%d ble=%s target=%s:%d",
|
||||
"OK STATUS uptime=%s heap=%lu rssi=%d tx_power=%d rate=%d hostname=%s version=%s adaptive=%s motion=%d ble=%s target=%s:%d temp=%.1f",
|
||||
uptime_str, (unsigned long)heap, rssi, (int)s_tx_power_dbm,
|
||||
s_send_frequency, CONFIG_CSI_HOSTNAME, app_desc->version,
|
||||
s_adaptive ? "on" : "off", s_motion_detected ? 1 : 0,
|
||||
s_ble_enabled ? "on" : "off", s_target_ip, s_target_port);
|
||||
s_ble_enabled ? "on" : "off", s_target_ip, s_target_port,
|
||||
chip_temp);
|
||||
return strlen(reply);
|
||||
}
|
||||
|
||||
@@ -1004,6 +1014,16 @@ void app_main()
|
||||
esp_wifi_set_max_tx_power(s_tx_power_dbm * 4);
|
||||
ESP_LOGI(TAG, "TX power set to %d dBm", (int)s_tx_power_dbm);
|
||||
|
||||
/* Chip temperature sensor */
|
||||
temperature_sensor_config_t temp_cfg = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80);
|
||||
if (temperature_sensor_install(&temp_cfg, &s_temp_handle) == ESP_OK) {
|
||||
temperature_sensor_enable(s_temp_handle);
|
||||
ESP_LOGI(TAG, "Temperature sensor initialized");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Temperature sensor init failed");
|
||||
s_temp_handle = NULL;
|
||||
}
|
||||
|
||||
/* mDNS: announce as <hostname>.local */
|
||||
ESP_ERROR_CHECK(mdns_init());
|
||||
mdns_hostname_set(CONFIG_CSI_HOSTNAME);
|
||||
|
||||
Reference in New Issue
Block a user