variable rename and bugfix

This commit is contained in:
xlemmingx 2025-11-05 17:09:20 +01:00
parent 143520822c
commit dc452ca494
2 changed files with 24 additions and 12 deletions

View File

@ -12,7 +12,7 @@
LOG_MODULE_REGISTER(lorawan_class_a); LOG_MODULE_REGISTER(lorawan_class_a);
extern bool relais_state; extern bool relais_state;
extern bool relais_manual_override; extern bool heating_logic_enabled;
extern uint8_t temperature_threshold; extern uint8_t temperature_threshold;
extern uint8_t floor_temp_threshold; extern uint8_t floor_temp_threshold;
extern uint32_t send_interval_minutes; extern uint32_t send_interval_minutes;
@ -59,14 +59,14 @@ static void dl_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, u
if (heating_enable == 0) if (heating_enable == 0)
{ {
/* Disable heating control logic completely */ /* Disable heating control logic completely */
relais_manual_override = true; heating_logic_enabled = false;
set_relais_state(0); set_relais_state(0);
LOG_INF("Heating control logic DISABLED, relais forced OFF"); LOG_INF("Heating control logic DISABLED, relais forced OFF");
} }
else if (heating_enable == 1) else if (heating_enable == 1)
{ {
/* Enable automatic heating control logic */ /* Enable automatic heating control logic */
relais_manual_override = false; heating_logic_enabled = true;
LOG_INF("Heating control logic ENABLED"); LOG_INF("Heating control logic ENABLED");
} }
else else

View File

@ -15,7 +15,7 @@
LOG_MODULE_REGISTER(g2h_heat_main); LOG_MODULE_REGISTER(g2h_heat_main);
volatile bool relais_state = false; volatile bool relais_state = false;
volatile bool relais_manual_override = false; volatile bool heating_logic_enabled = true;
volatile uint8_t temperature_threshold = 21; volatile uint8_t temperature_threshold = 21;
volatile uint8_t floor_temp_threshold = 24; volatile uint8_t floor_temp_threshold = 24;
volatile uint32_t send_interval_minutes = 10; volatile uint32_t send_interval_minutes = 10;
@ -40,12 +40,24 @@ int main(void)
{ {
/* Get stable values from sensors */ /* Get stable values from sensors */
humidity = get_stable_value_sht4x(SENSOR_CHAN_HUMIDITY); humidity = get_stable_value_sht4x(SENSOR_CHAN_HUMIDITY);
temp = get_stable_value_sht4x(SENSOR_CHAN_AMBIENT_TEMP);
printk("hum: %d.%02d%%\n", (int)humidity, (int)(humidity * 100) % 100); /* Try MLX sensor first for both room and floor temperature */
printk("temp: %d.%02d °C\n", (int)temp, (int)(temp * 100) % 100);
/* Try MLX sensor with stable measurement (10 samples) */
floor_temp = get_stable_value_mlx90614(MLX90614_IR_TEMP_ADDR); floor_temp = get_stable_value_mlx90614(MLX90614_IR_TEMP_ADDR);
if (mlx90614_sensor_available) if (mlx90614_sensor_available)
{
/* Use MLX90614 ambient temperature as room temperature */
temp = get_stable_value_mlx90614(MLX90614_INTERNAL_TEMP_ADDR);
printk("hum: %d.%02d%% (SHT4x)\n", (int)humidity, (int)(humidity * 100) % 100);
printk("temp: %d.%02d °C (MLX ambient)\n", (int)temp, (int)(temp * 100) % 100);
}
else
{
/* Fallback to SHT4x temperature if MLX not available */
temp = get_stable_value_sht4x(SENSOR_CHAN_AMBIENT_TEMP);
printk("hum: %d.%02d%% (SHT4x)\n", (int)humidity, (int)(humidity * 100) % 100);
printk("temp: %d.%02d °C (SHT4x fallback)\n", (int)temp, (int)(temp * 100) % 100);
}
if (mlx90614_sensor_available)
{ {
LOG_INF("MLX stable measurement: %d.%02d °C", (int)floor_temp, (int)(floor_temp * 100) % 100); LOG_INF("MLX stable measurement: %d.%02d °C", (int)floor_temp, (int)(floor_temp * 100) % 100);
} }
@ -58,8 +70,8 @@ int main(void)
(int)floor_temp, (int)(floor_temp * 100) % 100, (int)floor_temp, (int)(floor_temp * 100) % 100,
mlx90614_sensor_available ? "YES" : "NO"); mlx90614_sensor_available ? "YES" : "NO");
/* Set relais based on temperature if not manually overridden */ /* Set relais based on temperature if heating logic is enabled */
if (!relais_manual_override) if (heating_logic_enabled)
{ {
bool temp_condition = temp < temperature_threshold; bool temp_condition = temp < temperature_threshold;
bool floor_condition = true; // Default: ignore floor temp if sensor not available bool floor_condition = true; // Default: ignore floor temp if sensor not available
@ -80,8 +92,8 @@ int main(void)
} }
set_relais_state(relais_state); set_relais_state(relais_state);
} }
printk("relais: %d (manual: %d, temp_th: %d°C, floor_th: %d°C)\n", printk("relais: %d (heating_enabled: %d, temp_th: %d°C, floor_th: %d°C)\n",
relais_state, relais_manual_override, temperature_threshold, floor_temp_threshold); relais_state, heating_logic_enabled, temperature_threshold, floor_temp_threshold);
/* Pack and send values */ /* Pack and send values */
char data[7]; char data[7];