diff --git a/src/lora/lorawan.c b/src/lora/lorawan.c index 95322e9..e2b50c3 100644 --- a/src/lora/lorawan.c +++ b/src/lora/lorawan.c @@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(lorawan_class_a); extern bool relais_state; -extern bool relais_manual_override; +extern bool heating_logic_enabled; extern uint8_t temperature_threshold; extern uint8_t floor_temp_threshold; 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) { /* Disable heating control logic completely */ - relais_manual_override = true; + heating_logic_enabled = false; set_relais_state(0); LOG_INF("Heating control logic DISABLED, relais forced OFF"); } else if (heating_enable == 1) { /* Enable automatic heating control logic */ - relais_manual_override = false; + heating_logic_enabled = true; LOG_INF("Heating control logic ENABLED"); } else diff --git a/src/main.c b/src/main.c index 7733c66..dbe3796 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ LOG_MODULE_REGISTER(g2h_heat_main); 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 floor_temp_threshold = 24; volatile uint32_t send_interval_minutes = 10; @@ -40,12 +40,24 @@ int main(void) { /* Get stable values from sensors */ 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); - printk("temp: %d.%02d °C\n", (int)temp, (int)(temp * 100) % 100); - /* Try MLX sensor with stable measurement (10 samples) */ + + /* Try MLX sensor first for both room and floor temperature */ floor_temp = get_stable_value_mlx90614(MLX90614_IR_TEMP_ADDR); 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); } @@ -58,8 +70,8 @@ int main(void) (int)floor_temp, (int)(floor_temp * 100) % 100, mlx90614_sensor_available ? "YES" : "NO"); - /* Set relais based on temperature if not manually overridden */ - if (!relais_manual_override) + /* Set relais based on temperature if heating logic is enabled */ + if (heating_logic_enabled) { bool temp_condition = temp < temperature_threshold; bool floor_condition = true; // Default: ignore floor temp if sensor not available @@ -80,8 +92,8 @@ int main(void) } set_relais_state(relais_state); } - printk("relais: %d (manual: %d, temp_th: %d°C, floor_th: %d°C)\n", - relais_state, relais_manual_override, temperature_threshold, floor_temp_threshold); + printk("relais: %d (heating_enabled: %d, temp_th: %d°C, floor_th: %d°C)\n", + relais_state, heating_logic_enabled, temperature_threshold, floor_temp_threshold); /* Pack and send values */ char data[7];