thermferm/thermferm.c

changeset 533
49580ca85ab7
parent 532
34bf9f389749
child 536
e833bbd5e733
equal deleted inserted replaced
532:34bf9f389749 533:49580ca85ab7
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2014-2017 2 * Copyright (C) 2014-2018
3 * 3 *
4 * Michiel Broek <mbroek at mbse dot eu> 4 * Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * This file is part of the mbsePi-apps 6 * This file is part of the mbsePi-apps
7 * 7 *
389 /* 389 /*
390 * Change mode of current_unit 390 * Change mode of current_unit
391 */ 391 */
392 void change_mode(int mode) 392 void change_mode(int mode)
393 { 393 {
394 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) 394 current_unit->mqtt_flag |= MQTT_FLAG_DATA;
395 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) {
395 initlog(current_unit->name); 396 initlog(current_unit->name);
397 current_unit->mqtt_flag |= MQTT_FLAG_BIRTH;
398 } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) {
399 current_unit->mqtt_flag |= MQTT_FLAG_DEATH;
400 }
396 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); 401 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
397 current_unit->mode = mode; 402 current_unit->mode = mode;
398 current_unit->mqtt_flag |= MQTT_FLAG_DATA;
399 /* Allways turn everything off after a mode change */ 403 /* Allways turn everything off after a mode change */
400 current_unit->PID_cool->OutP = current_unit->PID_heat->OutP = 0.0; 404 current_unit->PID_cool->OutP = current_unit->PID_heat->OutP = 0.0;
401 current_unit->PID_cool->Mode = current_unit->PID_heat->Mode = PID_MODE_NONE; 405 current_unit->PID_cool->Mode = current_unit->PID_heat->Mode = PID_MODE_NONE;
402 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = current_unit->light_state = 0; 406 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = current_unit->light_state = 0;
403 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = current_unit->light_wait = 0; 407 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = current_unit->light_wait = 0;
1215 publishNData(false, 0); 1219 publishNData(false, 0);
1216 1220
1217 LCDunit = 0; 1221 LCDunit = 0;
1218 for (unit = Config.units; unit; unit = unit->next) { 1222 for (unit = Config.units; unit; unit = unit->next) {
1219 LCDunit++; 1223 LCDunit++;
1220 unit->mqtt_flag = unit->alarm_flag = 0; 1224 unit->mqtt_flag &= ~MQTT_FLAG_DATA;
1225 unit->alarm_flag = 0;
1221 1226
1222 if (unit->air_address) { 1227 if (unit->air_address) {
1223 rc = device_in(unit->air_address, &temp); 1228 rc = device_in(unit->air_address, &temp);
1224 if (rc == DEVPRESENT_YES) { 1229 if (rc == DEVPRESENT_YES) {
1225 /* 1230 /*
1848 1853
1849 /* 1854 /*
1850 * Publish MQTT messages set in flag 1855 * Publish MQTT messages set in flag
1851 */ 1856 */
1852 if (unit->mqtt_flag) { 1857 if (unit->mqtt_flag) {
1853 publishDData(unit); 1858 if (unit->mqtt_flag & MQTT_FLAG_BIRTH) {
1859 publishDBirth(unit);
1860 unit->mqtt_flag &= ~MQTT_FLAG_BIRTH;
1861 } else {
1862 publishDData(unit);
1863 unit->mqtt_flag &= ~MQTT_FLAG_DATA;
1864 }
1865 if (unit->mqtt_flag & MQTT_FLAG_DEATH) {
1866 publishDDeath(unit);
1867 unit->mqtt_flag &= ~MQTT_FLAG_DEATH;
1868 }
1854 } 1869 }
1855 1870
1856 /* 1871 /*
1857 * Handle changed alarms 1872 * Handle changed alarms
1858 */ 1873 */
1982 device_out(unit->cooler_address, unit->cooler_state); 1997 device_out(unit->cooler_address, unit->cooler_state);
1983 pub_domoticz_output(unit->cooler_idx, unit->cooler_state); 1998 pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
1984 device_out(unit->fan_address, unit->fan_state); 1999 device_out(unit->fan_address, unit->fan_state);
1985 pub_domoticz_output(unit->fan_idx, unit->fan_state); 2000 pub_domoticz_output(unit->fan_idx, unit->fan_state);
1986 device_out(unit->light_address, unit->light_state); 2001 device_out(unit->light_address, unit->light_state);
1987 unit->mqtt_flag = MQTT_FLAG_DATA; 2002 if (unit->mode != UNITMODE_OFF) {
1988 publishDData(unit); 2003 /*
2004 * If unit ia active, publish we are dying.
2005 */
2006 unit->mqtt_flag = MQTT_FLAG_DATA;
2007 publishDData(unit);
2008 publishDDeath(unit);
2009 }
1989 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]); 2010 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]);
1990 } 2011 }
1991 2012
1992 usleep(100000); 2013 usleep(100000);
1993 mqtt_disconnect(); 2014 mqtt_disconnect();

mercurial