1400 * drops we assume the primary fermentation is done. |
1400 * drops we assume the primary fermentation is done. |
1401 */ |
1401 */ |
1402 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) < (unit->prof_peak_rel - 0.5)) { |
1402 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) < (unit->prof_peak_rel - 0.5)) { |
1403 unit->prof_primary_done = time(NULL); |
1403 unit->prof_primary_done = time(NULL); |
1404 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (cooler mode)", unit->profile_name); |
1404 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (cooler mode)", unit->profile_name); |
|
1405 if (! unit->event_msg) |
|
1406 unit->event_msg = xstrcpy((char *)"Primary peak"); |
1405 } |
1407 } |
1406 } else { |
1408 } else { |
1407 /* |
1409 /* |
1408 * This method works if the unit has no cooling or if the profile allowed the |
1410 * This method works if the unit has no cooling or if the profile allowed the |
1409 * beer temperature to rise freely. |
1411 * beer temperature to rise freely. |
1410 */ |
1412 */ |
1411 if ((unit->beer_temperature / 1000.0) < (unit->prof_peak_abs - 0.5)) { |
1413 if ((unit->beer_temperature / 1000.0) < (unit->prof_peak_abs - 0.5)) { |
1412 unit->prof_primary_done = time(NULL); |
1414 unit->prof_primary_done = time(NULL); |
1413 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (free rise mode)", unit->profile_name); |
1415 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (free rise mode)", unit->profile_name); |
|
1416 if (! unit->event_msg) |
|
1417 unit->event_msg = xstrcpy((char *)"Primary peak"); |
1414 } |
1418 } |
1415 } |
1419 } |
1416 } |
1420 } |
1417 |
1421 |
1418 /* |
1422 /* |
1495 */ |
1499 */ |
1496 unit->prof_state = PROFILE_DONE; |
1500 unit->prof_state = PROFILE_DONE; |
1497 unit->prof_percent = 100; |
1501 unit->prof_percent = 100; |
1498 syslog(LOG_NOTICE, "Profile `%s' is done", unit->profile_name); |
1502 syslog(LOG_NOTICE, "Profile `%s' is done", unit->profile_name); |
1499 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1503 unit->mqtt_flag |= MQTT_FLAG_DATA; |
|
1504 if (! unit->event_msg) |
|
1505 unit->event_msg = xstrcpy((char *)"Profile finished"); |
1500 } |
1506 } |
1501 break; |
1507 break; |
1502 |
1508 |
1503 case PROFILE_DONE: |
1509 case PROFILE_DONE: |
1504 /* |
1510 /* |
1683 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->alias, unit->heater_state, power); |
1689 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->alias, unit->heater_state, power); |
1684 unit->heater_state = power; |
1690 unit->heater_state = power; |
1685 pub_domoticz_output(unit->heater_idx, unit->heater_state); |
1691 pub_domoticz_output(unit->heater_idx, unit->heater_state); |
1686 if (unit->heater_address) { |
1692 if (unit->heater_address) { |
1687 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1693 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1688 unit->mqtt_flag |= MQTT_FLAG_DLOG; |
|
1689 } |
1694 } |
1690 } |
1695 } |
1691 } |
1696 } |
1692 } else { |
1697 } else { |
1693 if (unit->heater_wait > 0) { |
1698 if (unit->heater_wait > 0) { |
1697 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->alias); |
1702 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->alias); |
1698 unit->heater_state = 0; |
1703 unit->heater_state = 0; |
1699 pub_domoticz_output(unit->heater_idx, unit->heater_state); |
1704 pub_domoticz_output(unit->heater_idx, unit->heater_state); |
1700 if (unit->heater_address) { |
1705 if (unit->heater_address) { |
1701 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1706 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1702 unit->mqtt_flag |= MQTT_FLAG_DLOG; |
|
1703 } |
1707 } |
1704 } |
1708 } |
1705 } |
1709 } |
1706 } |
1710 } |
1707 if (unit->door_state) { |
1711 if (unit->door_state) { |
1721 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->alias, unit->cooler_state, power); |
1725 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->alias, unit->cooler_state, power); |
1722 unit->cooler_state = power; |
1726 unit->cooler_state = power; |
1723 pub_domoticz_output(unit->cooler_idx, unit->cooler_state); |
1727 pub_domoticz_output(unit->cooler_idx, unit->cooler_state); |
1724 if (unit->cooler_address) { |
1728 if (unit->cooler_address) { |
1725 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1729 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1726 unit->mqtt_flag |= MQTT_FLAG_DLOG; |
|
1727 } |
1730 } |
1728 } |
1731 } |
1729 } |
1732 } |
1730 } else { |
1733 } else { |
1731 if (unit->cooler_wait > 0) { |
1734 if (unit->cooler_wait > 0) { |
1735 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->alias); |
1738 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->alias); |
1736 unit->cooler_state = 0; |
1739 unit->cooler_state = 0; |
1737 pub_domoticz_output(unit->cooler_idx, unit->cooler_state); |
1740 pub_domoticz_output(unit->cooler_idx, unit->cooler_state); |
1738 if (unit->cooler_address) { |
1741 if (unit->cooler_address) { |
1739 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1742 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1740 unit->mqtt_flag |= MQTT_FLAG_DLOG; |
|
1741 } |
1743 } |
1742 } |
1744 } |
1743 } |
1745 } |
1744 } |
1746 } |
1745 if (unit->door_state) { |
1747 if (unit->door_state) { |
1763 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->alias); |
1765 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->alias); |
1764 unit->fan_state = 100; |
1766 unit->fan_state = 100; |
1765 pub_domoticz_output(unit->fan_idx, unit->fan_state); |
1767 pub_domoticz_output(unit->fan_idx, unit->fan_state); |
1766 if (unit->fan_address) { |
1768 if (unit->fan_address) { |
1767 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1769 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1768 unit->mqtt_flag |= MQTT_FLAG_DLOG; |
|
1769 } |
1770 } |
1770 } |
1771 } |
1771 } |
1772 } |
1772 } else { |
1773 } else { |
1773 if (unit->fan_wait > 0) { |
1774 if (unit->fan_wait > 0) { |
1777 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->alias); |
1778 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->alias); |
1778 unit->fan_state = 0; |
1779 unit->fan_state = 0; |
1779 pub_domoticz_output(unit->fan_idx, unit->fan_state); |
1780 pub_domoticz_output(unit->fan_idx, unit->fan_state); |
1780 if (unit->fan_address) { |
1781 if (unit->fan_address) { |
1781 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1782 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1782 unit->mqtt_flag |= MQTT_FLAG_DLOG; |
|
1783 } |
1783 } |
1784 } |
1784 } |
1785 } |
1785 } |
1786 } |
1786 } |
1787 device_out(unit->fan_address, unit->fan_state); |
1787 device_out(unit->fan_address, unit->fan_state); |
1852 } |
1852 } |
1853 if (unit->mqtt_flag & MQTT_FLAG_DEATH) { |
1853 if (unit->mqtt_flag & MQTT_FLAG_DEATH) { |
1854 publishDDeath(unit); |
1854 publishDDeath(unit); |
1855 unit->mqtt_flag &= ~MQTT_FLAG_DEATH; |
1855 unit->mqtt_flag &= ~MQTT_FLAG_DEATH; |
1856 } |
1856 } |
1857 if (unit->mqtt_flag & MQTT_FLAG_DLOG) { |
|
1858 publishDLog(unit); |
|
1859 if (unit->event_msg) |
|
1860 free(unit->event_msg); |
|
1861 unit->event_msg = NULL; |
|
1862 unit->mqtt_flag &= ~MQTT_FLAG_DLOG; |
|
1863 } |
|
1864 } |
1857 } |
1865 |
1858 |
1866 /* |
1859 /* |
1867 * Handle changed alarms |
1860 * Handle changed alarms |
1868 */ |
1861 */ |
1906 snprintf(use_heater, 39, "NA"); |
1899 snprintf(use_heater, 39, "NA"); |
1907 snprintf(use_cooler, 39, "NA"); |
1900 snprintf(use_cooler, 39, "NA"); |
1908 snprintf(use_fan, 39, "NA"); |
1901 snprintf(use_fan, 39, "NA"); |
1909 snprintf(room_temp, 39, "NA"); |
1902 snprintf(room_temp, 39, "NA"); |
1910 |
1903 |
1911 if (unit->mode == UNITMODE_BEER) { |
1904 if ((unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_PROFILE)) { |
1912 snprintf(target_lo, 39, "%.1f", unit->beer_set); |
1905 snprintf(target_lo, 39, "%.1f", unit->PID_heat->SetP); |
1913 snprintf(target_hi, 39, "%.1f", unit->beer_set); |
1906 snprintf(target_hi, 39, "%.1f", unit->PID_cool->SetP); |
1914 } else if (unit->mode == UNITMODE_FRIDGE) { |
|
1915 snprintf(target_lo, 39, "%.1f", unit->fridge_set); |
|
1916 snprintf(target_hi, 39, "%.1f", unit->fridge_set); |
|
1917 } else if (unit->mode == UNITMODE_PROFILE) { |
|
1918 snprintf(target_lo, 39, "%.1f", unit->prof_target_lo); |
|
1919 snprintf(target_hi, 39, "%.1f", unit->prof_target_hi); |
|
1920 } |
1907 } |
1921 |
1908 |
1922 if (unit->heater_address) { |
1909 if (unit->heater_address) { |
1923 snprintf(heater, 39, "%d", unit->heater_state); |
1910 snprintf(heater, 39, "%d", unit->heater_state); |
1924 snprintf(use_heater, 39, "%d", unit->heater_usage); |
1911 snprintf(use_heater, 39, "%d", unit->heater_usage); |
1948 filename = xstrcat(filename, unit->product_name); |
1935 filename = xstrcat(filename, unit->product_name); |
1949 filename = xstrcat(filename, (char *)".log"); |
1936 filename = xstrcat(filename, (char *)".log"); |
1950 logger(filename, buf); |
1937 logger(filename, buf); |
1951 free(filename); |
1938 free(filename); |
1952 filename = NULL; |
1939 filename = NULL; |
|
1940 |
|
1941 publishDLog(unit); |
|
1942 if (unit->event_msg) |
|
1943 free(unit->event_msg); |
|
1944 unit->event_msg = NULL; |
1953 } |
1945 } |
1954 } |
1946 } |
1955 |
1947 |
1956 minutes++; |
1948 minutes++; |
1957 if ((minutes % 5) == 0) { |
|
1958 for (unit = Config.units; unit; unit = unit->next) { |
|
1959 if (unit->mode != UNITMODE_OFF) { |
|
1960 unit->mqtt_flag |= MQTT_FLAG_DLOG; |
|
1961 } |
|
1962 } |
|
1963 } |
|
1964 if (minutes == 60) { |
1949 if (minutes == 60) { |
1965 minutes = 0; |
1950 minutes = 0; |
1966 /* |
1951 /* |
1967 * Log usage counters every hour |
1952 * Log usage counters every hour |
1968 */ |
1953 */ |
2004 device_out(unit->fan_address, unit->fan_state); |
1989 device_out(unit->fan_address, unit->fan_state); |
2005 pub_domoticz_output(unit->fan_idx, unit->fan_state); |
1990 pub_domoticz_output(unit->fan_idx, unit->fan_state); |
2006 device_out(unit->light_address, unit->light_state); |
1991 device_out(unit->light_address, unit->light_state); |
2007 if (unit->mode != UNITMODE_OFF) { |
1992 if (unit->mode != UNITMODE_OFF) { |
2008 /* |
1993 /* |
2009 * If unit ia active, publish we are dying. |
1994 * If unit is active, publish we are dying. |
2010 */ |
1995 */ |
2011 unit->mqtt_flag = MQTT_FLAG_DATA; |
1996 unit->mqtt_flag = MQTT_FLAG_DATA; |
2012 publishDData(unit); |
1997 publishDData(unit); |
2013 publishDDeath(unit); |
1998 publishDDeath(unit); |
2014 unit->event_msg = xstrcpy((char *)"Shutdown"); |
1999 unit->event_msg = xstrcpy((char *)"Shutdown"); |