thermferm/thermferm.c

changeset 554
ab9f22ab57b5
parent 550
04c942cded91
child 556
c2ee7f9a069e
equal deleted inserted replaced
553:4091d4fe217f 554:ab9f22ab57b5
186 lcdPosition(lcdHandle, 0, 1); 186 lcdPosition(lcdHandle, 0, 1);
187 lcdPuts(lcdHandle, current_unit->name); 187 lcdPuts(lcdHandle, current_unit->name);
188 #endif 188 #endif
189 slcdPuts(slcdHandle, "Choose unit:"); 189 slcdPuts(slcdHandle, "Choose unit:");
190 slcdPosition(slcdHandle, 0, 1); 190 slcdPosition(slcdHandle, 0, 1);
191 slcdPuts(slcdHandle, current_unit->name); 191 slcdPuts(slcdHandle, current_unit->alias);
192 break; 192 break;
193 193
194 case MENU_MODE_OFF: show_mode(); 194 case MENU_MODE_OFF: show_mode();
195 #ifdef HAVE_WIRINGPI_H 195 #ifdef HAVE_WIRINGPI_H
196 lcdPuts(lcdHandle, "New mode OFF"); 196 lcdPuts(lcdHandle, "New mode OFF");
392 */ 392 */
393 void change_mode(int mode) 393 void change_mode(int mode)
394 { 394 {
395 current_unit->mqtt_flag |= MQTT_FLAG_DATA; 395 current_unit->mqtt_flag |= MQTT_FLAG_DATA;
396 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) { 396 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) {
397 initlog(current_unit->name); 397 initlog(current_unit->product_code, current_unit->product_name);
398 current_unit->mqtt_flag |= MQTT_FLAG_BIRTH; 398 current_unit->mqtt_flag |= MQTT_FLAG_BIRTH;
399 } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) { 399 } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) {
400 current_unit->mqtt_flag |= MQTT_FLAG_DEATH; 400 current_unit->mqtt_flag |= MQTT_FLAG_DEATH;
401 } 401 }
402 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); 402 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
1080 unit->mqtt_flag = unit->alarm_flag = unit->alarm_last = 0; 1080 unit->mqtt_flag = unit->alarm_flag = unit->alarm_last = 0;
1081 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0; 1081 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
1082 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 1082 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
1083 if (unit->mode == UNITMODE_PROFILE) { 1083 if (unit->mode == UNITMODE_PROFILE) {
1084 if (!unit->profile) 1084 if (!unit->profile)
1085 syslog(LOG_NOTICE, "Starting unit `%s' in profile mode, no profile defined.", unit->name); 1085 syslog(LOG_NOTICE, "Starting unit `%s' in profile mode, no profile defined.", unit->alias);
1086 else { 1086 else {
1087 syslog(LOG_NOTICE, "Starting unit `%s' in profile state %s.", unit->name, PROFSTATE[unit->prof_state]); 1087 syslog(LOG_NOTICE, "Starting unit `%s' in profile state %s.", unit->alias, PROFSTATE[unit->prof_state]);
1088 } 1088 }
1089 } else if (unit->mode == UNITMODE_BEER) { 1089 } else if (unit->mode == UNITMODE_BEER) {
1090 syslog(LOG_NOTICE, "Starting unit `%s' beer cooler at %.1f degrees", unit->name, unit->beer_set); 1090 syslog(LOG_NOTICE, "Starting unit `%s' beer cooler at %.1f degrees", unit->alias, unit->beer_set);
1091 } else if (unit->mode == UNITMODE_FRIDGE) { 1091 } else if (unit->mode == UNITMODE_FRIDGE) {
1092 syslog(LOG_NOTICE, "Starting unit `%s' as refridgerator at %.1f degrees", unit->name, unit->fridge_set); 1092 syslog(LOG_NOTICE, "Starting unit `%s' as refridgerator at %.1f degrees", unit->alias, unit->fridge_set);
1093 } else if (unit->mode == UNITMODE_NONE) { 1093 } else if (unit->mode == UNITMODE_NONE) {
1094 syslog(LOG_NOTICE, "Starting unit `%s' in inactive state", unit->name); 1094 syslog(LOG_NOTICE, "Starting unit `%s' in inactive state", unit->alias);
1095 } else { 1095 } else {
1096 syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->name); 1096 syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->alias);
1097 } 1097 }
1098 1098
1099 /* 1099 /*
1100 * Initialize logfile 1100 * Initialize logfile
1101 */ 1101 */
1102 if (unit->mode != UNITMODE_OFF) { 1102 if (unit->mode != UNITMODE_OFF) {
1103 initlog(unit->name); 1103 initlog(unit->product_code, unit->product_name);
1104 } 1104 }
1105 } 1105 }
1106 printf("Units started\n");
1106 #ifdef HAVE_MOSQUITTO_H 1107 #ifdef HAVE_MOSQUITTO_H
1107 publishDBirthAll(); 1108 publishDBirthAll();
1109 printf("Birth all done\n");
1110
1111 for (unit = Config.units; unit; unit = unit->next) {
1112 if (unit->mode != UNITMODE_OFF) {
1113 unit->event_msg = xstrcpy((char *)"Startup");
1114 publishDLog(unit);
1115 free(unit->event_msg);
1116 unit->event_msg = NULL;
1117 }
1118 }
1108 #endif 1119 #endif
1109 1120
1110 #ifdef HAVE_WIRINGPI_H 1121 #ifdef HAVE_WIRINGPI_H
1111 piLock(LOCK_LCD); 1122 piLock(LOCK_LCD);
1112 #endif 1123 #endif
1329 if (unit->door_address) { 1340 if (unit->door_address) {
1330 rc = device_in(unit->door_address, &temp); 1341 rc = device_in(unit->door_address, &temp);
1331 if (rc == DEVPRESENT_YES) { 1342 if (rc == DEVPRESENT_YES) {
1332 if (temp) { 1343 if (temp) {
1333 if (unit->door_state == 0) { 1344 if (unit->door_state == 0) {
1334 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name); 1345 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->alias);
1335 unit->door_state = 1; 1346 unit->door_state = 1;
1336 #ifdef HAVE_MOSQUITTO_H 1347 #ifdef HAVE_MOSQUITTO_H
1337 pub_domoticz_output(unit->door_idx, unit->door_state); 1348 pub_domoticz_output(unit->door_idx, unit->door_state);
1338 unit->mqtt_flag |= MQTT_FLAG_DATA; 1349 unit->mqtt_flag |= MQTT_FLAG_DATA;
1339 #endif 1350 #endif
1340 } 1351 }
1341 } else { 1352 } else {
1342 if (unit->door_state) { 1353 if (unit->door_state) {
1343 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name); 1354 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->alias);
1344 unit->door_state = 0; 1355 unit->door_state = 0;
1345 #ifdef HAVE_MOSQUITTO_H 1356 #ifdef HAVE_MOSQUITTO_H
1346 pub_domoticz_output(unit->door_idx, unit->door_state); 1357 pub_domoticz_output(unit->door_idx, unit->door_state);
1347 unit->mqtt_flag |= MQTT_FLAG_DATA; 1358 unit->mqtt_flag |= MQTT_FLAG_DATA;
1348 #endif 1359 #endif
1367 if (unit->psu_address) { 1378 if (unit->psu_address) {
1368 rc = device_in(unit->psu_address, &temp); 1379 rc = device_in(unit->psu_address, &temp);
1369 if (rc == DEVPRESENT_YES) { 1380 if (rc == DEVPRESENT_YES) {
1370 if (temp) { 1381 if (temp) {
1371 if (unit->psu_state == 0) { 1382 if (unit->psu_state == 0) {
1372 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name); 1383 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->alias);
1373 unit->psu_state = 1; 1384 unit->psu_state = 1;
1374 #ifdef HAVE_MOSQUITTO_H 1385 #ifdef HAVE_MOSQUITTO_H
1375 pub_domoticz_output(unit->psu_idx, unit->psu_state); 1386 pub_domoticz_output(unit->psu_idx, unit->psu_state);
1376 unit->mqtt_flag |= MQTT_FLAG_DATA; 1387 unit->mqtt_flag |= MQTT_FLAG_DATA;
1377 #endif 1388 #endif
1378 } 1389 }
1379 } else { 1390 } else {
1380 if (unit->psu_state) { 1391 if (unit->psu_state) {
1381 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name); 1392 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->alias);
1382 unit->psu_state = 0; 1393 unit->psu_state = 0;
1383 #ifdef HAVE_MOSQUITTO_H 1394 #ifdef HAVE_MOSQUITTO_H
1384 pub_domoticz_output(unit->psu_idx, unit->psu_state); 1395 pub_domoticz_output(unit->psu_idx, unit->psu_state);
1385 unit->mqtt_flag |= MQTT_FLAG_DATA; 1396 unit->mqtt_flag |= MQTT_FLAG_DATA;
1386 #endif 1397 #endif
1613 if (unit->door_state && (unit->mode == UNITMODE_NONE) && unit->light_state) { 1624 if (unit->door_state && (unit->mode == UNITMODE_NONE) && unit->light_state) {
1614 if (unit->light_wait > 0) { 1625 if (unit->light_wait > 0) {
1615 unit->light_wait--; 1626 unit->light_wait--;
1616 } else { 1627 } else {
1617 unit->light_state = 0; 1628 unit->light_state = 0;
1618 syslog(LOG_NOTICE, "Unit `%s' lights On => Off", unit->name); 1629 syslog(LOG_NOTICE, "Unit `%s' lights On => Off", unit->alias);
1619 unit->mqtt_flag |= MQTT_FLAG_DATA; 1630 unit->mqtt_flag |= MQTT_FLAG_DATA;
1620 } 1631 }
1621 } 1632 }
1622 if ((!unit->door_state || (unit->mode != UNITMODE_NONE)) && !unit->light_state) { 1633 if ((!unit->door_state || (unit->mode != UNITMODE_NONE)) && !unit->light_state) {
1623 unit->light_wait = unit->light_delay; /* No delay to turn lights on */ 1634 unit->light_wait = unit->light_delay; /* No delay to turn lights on */
1624 unit->light_state = 1; 1635 unit->light_state = 1;
1625 unit->mqtt_flag |= MQTT_FLAG_DATA; 1636 unit->mqtt_flag |= MQTT_FLAG_DATA;
1626 syslog(LOG_NOTICE, "Unit `%s' lights Off => On", unit->name); 1637 syslog(LOG_NOTICE, "Unit `%s' lights Off => On", unit->alias);
1627 } 1638 }
1628 device_out(unit->light_address, unit->light_state); 1639 device_out(unit->light_address, unit->light_state);
1629 } 1640 }
1630 1641
1631 /* 1642 /*
1734 if (unit->heater_wait < unit->heater_delay) { 1745 if (unit->heater_wait < unit->heater_delay) {
1735 unit->heater_wait++; 1746 unit->heater_wait++;
1736 } else { 1747 } else {
1737 int power = round(unit->PID_heat->OutP); 1748 int power = round(unit->PID_heat->OutP);
1738 if (unit->heater_state != power) { 1749 if (unit->heater_state != power) {
1739 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power); 1750 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->alias, unit->heater_state, power);
1740 unit->heater_state = power; 1751 unit->heater_state = power;
1741 #ifdef HAVE_MOSQUITTO_H 1752 #ifdef HAVE_MOSQUITTO_H
1742 pub_domoticz_output(unit->heater_idx, unit->heater_state); 1753 pub_domoticz_output(unit->heater_idx, unit->heater_state);
1743 if (unit->heater_address) 1754 if (unit->heater_address) {
1744 unit->mqtt_flag |= MQTT_FLAG_DATA; 1755 unit->mqtt_flag |= MQTT_FLAG_DATA;
1756 unit->mqtt_flag |= MQTT_FLAG_DLOG;
1757 }
1745 #endif 1758 #endif
1746 } 1759 }
1747 } 1760 }
1748 } else { 1761 } else {
1749 if (unit->heater_wait > 0) { 1762 if (unit->heater_wait > 0) {
1750 unit->heater_wait--; 1763 unit->heater_wait--;
1751 } else { 1764 } else {
1752 if (unit->heater_state) { 1765 if (unit->heater_state) {
1753 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name); 1766 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->alias);
1754 unit->heater_state = 0; 1767 unit->heater_state = 0;
1755 #ifdef HAVE_MOSQUITTO_H 1768 #ifdef HAVE_MOSQUITTO_H
1756 pub_domoticz_output(unit->heater_idx, unit->heater_state); 1769 pub_domoticz_output(unit->heater_idx, unit->heater_state);
1757 if (unit->heater_address) 1770 if (unit->heater_address) {
1758 unit->mqtt_flag |= MQTT_FLAG_DATA; 1771 unit->mqtt_flag |= MQTT_FLAG_DATA;
1772 unit->mqtt_flag |= MQTT_FLAG_DLOG;
1773 }
1759 #endif 1774 #endif
1760 } 1775 }
1761 } 1776 }
1762 } 1777 }
1763 if (unit->door_state) { 1778 if (unit->door_state) {
1772 if (unit->cooler_wait < unit->cooler_delay) { 1787 if (unit->cooler_wait < unit->cooler_delay) {
1773 unit->cooler_wait++; 1788 unit->cooler_wait++;
1774 } else { 1789 } else {
1775 int power = round(unit->PID_cool->OutP); 1790 int power = round(unit->PID_cool->OutP);
1776 if (unit->cooler_state != power) { 1791 if (unit->cooler_state != power) {
1777 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power); 1792 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->alias, unit->cooler_state, power);
1778 unit->cooler_state = power; 1793 unit->cooler_state = power;
1779 #ifdef HAVE_MOSQUITTO_H 1794 #ifdef HAVE_MOSQUITTO_H
1780 pub_domoticz_output(unit->cooler_idx, unit->cooler_state); 1795 pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
1781 if (unit->cooler_address) 1796 if (unit->cooler_address) {
1782 unit->mqtt_flag |= MQTT_FLAG_DATA; 1797 unit->mqtt_flag |= MQTT_FLAG_DATA;
1798 unit->mqtt_flag |= MQTT_FLAG_DLOG;
1799 }
1783 #endif 1800 #endif
1784 } 1801 }
1785 } 1802 }
1786 } else { 1803 } else {
1787 if (unit->cooler_wait > 0) { 1804 if (unit->cooler_wait > 0) {
1788 unit->cooler_wait--; 1805 unit->cooler_wait--;
1789 } else { 1806 } else {
1790 if (unit->cooler_state) { 1807 if (unit->cooler_state) {
1791 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name); 1808 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->alias);
1792 unit->cooler_state = 0; 1809 unit->cooler_state = 0;
1793 #ifdef HAVE_MOSQUITTO_H 1810 #ifdef HAVE_MOSQUITTO_H
1794 pub_domoticz_output(unit->cooler_idx, unit->cooler_state); 1811 pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
1795 if (unit->cooler_address) 1812 if (unit->cooler_address) {
1796 unit->mqtt_flag |= MQTT_FLAG_DATA; 1813 unit->mqtt_flag |= MQTT_FLAG_DATA;
1814 unit->mqtt_flag |= MQTT_FLAG_DLOG;
1815 }
1797 #endif 1816 #endif
1798 } 1817 }
1799 } 1818 }
1800 } 1819 }
1801 if (unit->door_state) { 1820 if (unit->door_state) {
1817 if ((unit->door_state) && (unit->cooler_state == 0)) { 1836 if ((unit->door_state) && (unit->cooler_state == 0)) {
1818 if (unit->fan_wait < unit->fan_delay) { 1837 if (unit->fan_wait < unit->fan_delay) {
1819 unit->fan_wait++; 1838 unit->fan_wait++;
1820 } else { 1839 } else {
1821 if (! unit->fan_state) { 1840 if (! unit->fan_state) {
1822 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name); 1841 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->alias);
1823 unit->fan_state = 100; 1842 unit->fan_state = 100;
1824 #ifdef HAVE_MOSQUITTO_H 1843 #ifdef HAVE_MOSQUITTO_H
1825 pub_domoticz_output(unit->fan_idx, unit->fan_state); 1844 pub_domoticz_output(unit->fan_idx, unit->fan_state);
1826 if (unit->fan_address) 1845 if (unit->fan_address) {
1827 unit->mqtt_flag |= MQTT_FLAG_DATA; 1846 unit->mqtt_flag |= MQTT_FLAG_DATA;
1847 unit->mqtt_flag |= MQTT_FLAG_DLOG;
1848 }
1828 #endif 1849 #endif
1829 } 1850 }
1830 } 1851 }
1831 } else { 1852 } else {
1832 if (unit->fan_wait > 0) { 1853 if (unit->fan_wait > 0) {
1833 unit->fan_wait--; 1854 unit->fan_wait--;
1834 } else { 1855 } else {
1835 if (unit->fan_state) { 1856 if (unit->fan_state) {
1836 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name); 1857 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->alias);
1837 unit->fan_state = 0; 1858 unit->fan_state = 0;
1838 #ifdef HAVE_MOSQUITTO_H 1859 #ifdef HAVE_MOSQUITTO_H
1839 pub_domoticz_output(unit->fan_idx, unit->fan_state); 1860 pub_domoticz_output(unit->fan_idx, unit->fan_state);
1840 if (unit->fan_address) 1861 if (unit->fan_address) {
1841 unit->mqtt_flag |= MQTT_FLAG_DATA; 1862 unit->mqtt_flag |= MQTT_FLAG_DATA;
1863 unit->mqtt_flag |= MQTT_FLAG_DLOG;
1864 }
1842 #endif 1865 #endif
1843 } 1866 }
1844 } 1867 }
1845 } 1868 }
1846 device_out(unit->fan_address, unit->fan_state); 1869 device_out(unit->fan_address, unit->fan_state);
1887 #endif 1910 #endif
1888 /* 1911 /*
1889 * Write 4 rows to the LCD to display the unit state 1912 * Write 4 rows to the LCD to display the unit state
1890 */ 1913 */
1891 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]); 1914 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]);
1892 lcd_buf_write(row++, "%s ", unit->name); 1915 lcd_buf_write(row++, "%s ", unit->product_name);
1893 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair); 1916 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair);
1894 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer); 1917 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer);
1895 #ifdef HAVE_WIRINGPI_H 1918 #ifdef HAVE_WIRINGPI_H
1896 piUnlock(LOCK_LCD); 1919 piUnlock(LOCK_LCD);
1897 #endif 1920 #endif
1912 } 1935 }
1913 if (unit->mqtt_flag & MQTT_FLAG_DEATH) { 1936 if (unit->mqtt_flag & MQTT_FLAG_DEATH) {
1914 publishDDeath(unit); 1937 publishDDeath(unit);
1915 unit->mqtt_flag &= ~MQTT_FLAG_DEATH; 1938 unit->mqtt_flag &= ~MQTT_FLAG_DEATH;
1916 } 1939 }
1940 if (unit->mqtt_flag & MQTT_FLAG_DLOG) {
1941 publishDLog(unit);
1942 if (unit->event_msg)
1943 free(unit->event_msg);
1944 unit->event_msg = NULL;
1945 unit->mqtt_flag &= ~MQTT_FLAG_DLOG;
1946 }
1917 } 1947 }
1918 #endif 1948 #endif
1919 1949
1920 /* 1950 /*
1921 * Handle changed alarms 1951 * Handle changed alarms
1922 */ 1952 */
1923 if (unit->alarm_flag != unit->alarm_last) { 1953 if (unit->alarm_flag != unit->alarm_last) {
1924 syslog(LOG_NOTICE, "Unit `%s' Alarm %d => %d", unit->name, unit->alarm_last, unit->alarm_flag); 1954 syslog(LOG_NOTICE, "Unit `%s' Alarm %d => %d", unit->alias, unit->alarm_last, unit->alarm_flag);
1925 unit->alarm_last = unit->alarm_flag; 1955 unit->alarm_last = unit->alarm_flag;
1926 } 1956 }
1927 } /* for units */ 1957 } /* for units */
1928 1958
1929 #ifdef HAVE_WIRINGPI_H 1959 #ifdef HAVE_WIRINGPI_H
1995 snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.3f", 2025 snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.3f",
1996 UNITMODE[unit->mode], unit->air_temperature / 1000.0, 2026 UNITMODE[unit->mode], unit->air_temperature / 1000.0,
1997 unit->beer_temperature / 1000.0, 2027 unit->beer_temperature / 1000.0,
1998 target_lo, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp, target_hi, 2028 target_lo, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp, target_hi,
1999 unit->chiller_temperature / 1000.0); 2029 unit->chiller_temperature / 1000.0);
2000 filename = xstrcpy(unit->name); 2030 filename = xstrcpy(unit->product_code);
2031 filename = xstrcat(filename, (char *)" ");
2032 filename = xstrcat(filename, unit->product_name);
2001 filename = xstrcat(filename, (char *)".log"); 2033 filename = xstrcat(filename, (char *)".log");
2002 logger(filename, buf); 2034 logger(filename, buf);
2003 free(filename); 2035 free(filename);
2004 filename = NULL; 2036 filename = NULL;
2005 } 2037 }
2006 } 2038 }
2007 2039
2008 minutes++; 2040 minutes++;
2041 if ((minutes % 5) == 0) {
2042 for (unit = Config.units; unit; unit = unit->next) {
2043 if (unit->mode != UNITMODE_OFF) {
2044 unit->mqtt_flag |= MQTT_FLAG_DLOG;
2045 }
2046 }
2047 }
2009 if (minutes == 60) { 2048 if (minutes == 60) {
2010 minutes = 0; 2049 minutes = 0;
2011 /* 2050 /*
2012 * Log usage counters every hour 2051 * Log usage counters every hour
2013 */ 2052 */
2014 for (unit = Config.units; unit; unit = unit->next) { 2053 for (unit = Config.units; unit; unit = unit->next) {
2015 syslog(LOG_NOTICE, "Unit `%s' usage heater=%d cooler=%d fan=%d", unit->name, unit->heater_usage, unit->cooler_usage, unit->fan_usage); 2054 syslog(LOG_NOTICE, "Unit `%s' usage heater=%d cooler=%d fan=%d", unit->alias, unit->heater_usage, unit->cooler_usage, unit->fan_usage);
2016 } 2055 }
2017 } 2056 }
2018 2057
2019 /* 2058 /*
2020 * Save the configuration each half hour. 2059 * Save the configuration each half hour.
2061 * If unit ia active, publish we are dying. 2100 * If unit ia active, publish we are dying.
2062 */ 2101 */
2063 unit->mqtt_flag = MQTT_FLAG_DATA; 2102 unit->mqtt_flag = MQTT_FLAG_DATA;
2064 publishDData(unit); 2103 publishDData(unit);
2065 publishDDeath(unit); 2104 publishDDeath(unit);
2105 unit->event_msg = xstrcpy((char *)"Shutdown");
2106 publishDLog(unit);
2107 free(unit->event_msg);
2108 unit->event_msg = NULL;
2066 } 2109 }
2067 #endif 2110 #endif
2068 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]); 2111 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->alias, UNITMODE[unit->mode]);
2069 } 2112 }
2070 2113
2071 usleep(100000); 2114 usleep(100000);
2072 #ifdef HAVE_MOSQUITTO_H 2115 #ifdef HAVE_MOSQUITTO_H
2073 mqtt_disconnect(); 2116 mqtt_disconnect();

mercurial