1600 * Accept writable data. The client can sent just one line, |
1600 * Accept writable data. The client can sent just one line, |
1601 * but may also sent everything. Simply ignore things we |
1601 * but may also sent everything. Simply ignore things we |
1602 * don't understand. |
1602 * don't understand. |
1603 */ |
1603 */ |
1604 if (val && (strcmp(kwd, (char *)"NAME") == 0)) { |
1604 if (val && (strcmp(kwd, (char *)"NAME") == 0)) { |
1605 if (unit->name) |
1605 if (unit->name) { |
|
1606 if (strcmp(unit->name, val)) |
|
1607 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); |
1606 free(unit->name); |
1608 free(unit->name); |
|
1609 } |
1607 unit->name = xstrcpy(val); |
1610 unit->name = xstrcpy(val); |
1608 |
1611 |
1609 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { |
1612 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { |
1610 if (sscanf(val, "%f", &fval) == 1) |
1613 if (sscanf(val, "%f", &fval) == 1) { |
|
1614 if (unit->volume != fval) |
|
1615 syslog(LOG_NOTICE, "Fermenter unit %s volume %.3f to %.3f", unit->uuid, unit->volume, fval); |
1611 unit->volume = fval; |
1616 unit->volume = fval; |
|
1617 } |
1612 |
1618 |
1613 } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) { |
1619 } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) { |
|
1620 if (val && unit->air_address && (strcmp(val, unit->air_address))) |
|
1621 syslog(LOG_NOTICE, "Fermenter unit %s air address `%s' to `%s'", unit->uuid, unit->air_address, val); |
1614 if (unit->air_address) { |
1622 if (unit->air_address) { |
1615 device_count(FALSE, unit->air_address); |
1623 device_count(FALSE, unit->air_address); |
1616 free(unit->air_address); |
1624 free(unit->air_address); |
1617 } |
1625 } |
1618 if (val) { |
1626 if (val) { |
1642 device_count(TRUE, unit->heater_address); |
1654 device_count(TRUE, unit->heater_address); |
1643 } else |
1655 } else |
1644 unit->heater_address = NULL; |
1656 unit->heater_address = NULL; |
1645 |
1657 |
1646 } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) { |
1658 } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) { |
1647 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) |
1659 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
|
1660 if (unit->heater_state != ival) |
|
1661 syslog(LOG_NOTICE, "Fermenter unit %s heater state %d to %d", unit->uuid, unit->heater_state, ival); |
1648 unit->heater_state = ival; |
1662 unit->heater_state = ival; |
|
1663 } |
1649 |
1664 |
1650 } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) { |
1665 } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) { |
1651 if (sscanf(val, "%d", &ival) == 1) |
1666 if (sscanf(val, "%d", &ival) == 1) { |
|
1667 if (unit->heater_delay != ival) |
|
1668 syslog(LOG_NOTICE, "Fermenter unit %s heater delay %d to %d", unit->uuid, unit->heater_delay, ival); |
1652 unit->heater_delay = ival; |
1669 unit->heater_delay = ival; |
|
1670 } |
1653 |
1671 |
1654 } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { |
1672 } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { |
|
1673 if (val && unit->cooler_address && (strcmp(val, unit->cooler_address))) |
|
1674 syslog(LOG_NOTICE, "Fermenter unit %s cooler address `%s' to `%s'", unit->uuid, unit->cooler_address, val); |
1655 if (unit->cooler_address) { |
1675 if (unit->cooler_address) { |
1656 device_count(FALSE, unit->cooler_address); |
1676 device_count(FALSE, unit->cooler_address); |
1657 free(unit->cooler_address); |
1677 free(unit->cooler_address); |
1658 } |
1678 } |
1659 if (val) { |
1679 if (val) { |
1661 device_count(TRUE, unit->cooler_address); |
1681 device_count(TRUE, unit->cooler_address); |
1662 } else |
1682 } else |
1663 unit->cooler_address = NULL; |
1683 unit->cooler_address = NULL; |
1664 |
1684 |
1665 } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) { |
1685 } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) { |
1666 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) |
1686 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
|
1687 if (unit->cooler_state != ival) |
|
1688 syslog(LOG_NOTICE, "Fermenter unit %s cooler state %d to %d", unit->uuid, unit->cooler_state, ival); |
1667 unit->cooler_state = ival; |
1689 unit->cooler_state = ival; |
|
1690 } |
1668 |
1691 |
1669 } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) { |
1692 } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) { |
1670 if (sscanf(val, "%d", &ival) == 1) |
1693 if (sscanf(val, "%d", &ival) == 1) { |
|
1694 if (unit->cooler_delay != ival) |
|
1695 syslog(LOG_NOTICE, "Fermenter unit %s cooler delay %d to %d", unit->uuid, unit->cooler_delay, ival); |
1671 unit->cooler_delay = ival; |
1696 unit->cooler_delay = ival; |
|
1697 } |
1672 |
1698 |
1673 } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { |
1699 } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { |
|
1700 if (val && unit->fan_address && (strcmp(val, unit->fan_address))) |
|
1701 syslog(LOG_NOTICE, "Fermenter unit %s fan address `%s' to `%s'", unit->uuid, unit->fan_address, val); |
1674 if (unit->fan_address) { |
1702 if (unit->fan_address) { |
1675 device_count(FALSE, unit->fan_address); |
1703 device_count(FALSE, unit->fan_address); |
1676 free(unit->fan_address); |
1704 free(unit->fan_address); |
1677 } |
1705 } |
1678 if (val) { |
1706 if (val) { |
1680 device_count(TRUE, unit->fan_address); |
1708 device_count(TRUE, unit->fan_address); |
1681 } else |
1709 } else |
1682 unit->fan_address = NULL; |
1710 unit->fan_address = NULL; |
1683 |
1711 |
1684 } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) { |
1712 } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) { |
1685 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) |
1713 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
|
1714 if (unit->fan_state != ival) |
|
1715 syslog(LOG_NOTICE, "Fermenter unit %s fan state %d to %d", unit->uuid, unit->fan_state, ival); |
1686 unit->fan_state = ival; |
1716 unit->fan_state = ival; |
|
1717 } |
1687 |
1718 |
1688 } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) { |
1719 } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) { |
1689 if (sscanf(val, "%d", &ival) == 1) |
1720 if (sscanf(val, "%d", &ival) == 1) { |
|
1721 if (unit->fan_delay != ival) |
|
1722 syslog(LOG_NOTICE, "Fermenter unit %s fan delay %d to %d", unit->uuid, unit->fan_delay, ival); |
1690 unit->fan_delay = ival; |
1723 unit->fan_delay = ival; |
|
1724 } |
1691 |
1725 |
1692 } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { |
1726 } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { |
|
1727 if (val && unit->door_address && (strcmp(val, unit->door_address))) |
|
1728 syslog(LOG_NOTICE, "Fermenter unit %s door address `%s' to `%s'", unit->uuid, unit->door_address, val); |
1693 if (unit->door_address) { |
1729 if (unit->door_address) { |
1694 device_count(FALSE, unit->door_address); |
1730 device_count(FALSE, unit->door_address); |
1695 free(unit->door_address); |
1731 free(unit->door_address); |
1696 } |
1732 } |
1697 if (val) { |
1733 if (val) { |
1704 for (i = 0; i < 5; i++) { |
1740 for (i = 0; i < 5; i++) { |
1705 if (strcmp(val, UNITMODE[i]) == 0) { |
1741 if (strcmp(val, UNITMODE[i]) == 0) { |
1706 /* Initialize log if the unit is turned on */ |
1742 /* Initialize log if the unit is turned on */ |
1707 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) |
1743 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) |
1708 initlog(unit->name); |
1744 initlog(unit->name); |
1709 syslog(LOG_NOTICE, "Mode from %s to %s via web interface", UNITMODE[unit->mode], UNITMODE[i]); |
1745 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); |
1710 unit->mode = i; |
1746 unit->mode = i; |
1711 /* Allways turn everything off after a mode change */ |
1747 /* Allways turn everything off after a mode change */ |
1712 unit->PID_I_err = unit->PID_err_old = 0.0; |
1748 unit->PID_I_err = unit->PID_err_old = 0.0; |
1713 unit->heater_state = unit->cooler_state = unit->fan_state = 0; |
1749 unit->heater_state = unit->cooler_state = unit->fan_state = 0; |
1714 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; |
1750 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; |
1726 } |
1762 } |
1727 } |
1763 } |
1728 |
1764 |
1729 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { |
1765 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { |
1730 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
1766 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
1731 syslog(LOG_NOTICE, "Fridge temperature from %.1f to %.1f via web interface", unit->fridge_set, fval); |
1767 if (unit->fridge_set != fval) |
|
1768 syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval); |
1732 unit->fridge_set = fval; |
1769 unit->fridge_set = fval; |
1733 } |
1770 } |
1734 |
1771 |
1735 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { |
1772 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { |
1736 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
1773 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
1737 syslog(LOG_NOTICE, "Beer temperature from %.1f to %.1f via web interface", unit->beer_set, fval); |
1774 if (unit->fridge_set != fval) |
|
1775 syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval); |
1738 unit->beer_set = fval; |
1776 unit->beer_set = fval; |
1739 } |
1777 } |
1740 |
1778 |
1741 } else if (strcmp(kwd, (char *)"PROFILE") == 0) { |
1779 } else if (strcmp(kwd, (char *)"PROFILE") == 0) { |
1742 if (unit->prof_state == PROFILE_OFF) { |
1780 if (unit->prof_state == PROFILE_OFF) { |
1743 /* |
1781 /* |
1744 * Only change profile if it is not active, else drop this one. |
1782 * Only change profile if it is not active, else drop this one. |
1745 */ |
1783 */ |
|
1784 if (unit->profile && val && strcmp(unit->profile, val)) |
|
1785 syslog(LOG_NOTICE, "Fermenter unit %s profile name `%s' to `%s'", unit->uuid, unit->profile, val); |
1746 if (unit->profile) |
1786 if (unit->profile) |
1747 free(unit->profile); |
1787 free(unit->profile); |
|
1788 |
1748 if (val) |
1789 if (val) |
1749 unit->profile = xstrcpy(val); |
1790 unit->profile = xstrcpy(val); |
1750 else |
1791 else |
1751 unit->profile = NULL; |
1792 unit->profile = NULL; |
1752 /* |
1793 /* |
1764 for (i = 0; i < 5; i++) { |
1805 for (i = 0; i < 5; i++) { |
1765 if (strcmp(val, PROFSTATE[i]) == 0) { |
1806 if (strcmp(val, PROFSTATE[i]) == 0) { |
1766 switch (i) { |
1807 switch (i) { |
1767 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { |
1808 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { |
1768 unit->prof_state = PROFILE_OFF; |
1809 unit->prof_state = PROFILE_OFF; |
1769 syslog(LOG_NOTICE, "Profile to OFF via web interface"); |
1810 syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid); |
1770 } |
1811 } |
1771 break; |
1812 break; |
1772 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { |
1813 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { |
1773 unit->prof_state = PROFILE_PAUSE; |
1814 unit->prof_state = PROFILE_PAUSE; |
1774 syslog(LOG_NOTICE, "Profile PAUSE via web interface"); |
1815 syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid); |
1775 } else if (unit->prof_state == PROFILE_PAUSE) { |
1816 } else if (unit->prof_state == PROFILE_PAUSE) { |
1776 unit->prof_state = PROFILE_RUN; |
1817 unit->prof_state = PROFILE_RUN; |
1777 syslog(LOG_NOTICE, "Profile RESUME via web interface"); |
1818 syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid); |
1778 } |
1819 } |
1779 break; |
1820 break; |
1780 case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { |
1821 case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { |
1781 unit->prof_state = PROFILE_RUN; |
1822 unit->prof_state = PROFILE_RUN; |
1782 unit->prof_started = time(NULL); |
1823 unit->prof_started = time(NULL); |
1783 unit->prof_paused = 0; |
1824 unit->prof_paused = 0; |
1784 syslog(LOG_NOTICE, "Profile to RUN via web interface"); |
1825 syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid); |
1785 } |
1826 } |
1786 break; |
1827 break; |
1787 case PROFILE_DONE: break; /* Command is illegal */ |
1828 case PROFILE_DONE: break; /* Command is illegal */ |
1788 case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { |
1829 case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { |
1789 unit->prof_state = PROFILE_OFF; |
1830 unit->prof_state = PROFILE_OFF; |
1790 unit->prof_started = 0; |
1831 unit->prof_started = 0; |
1791 syslog(LOG_NOTICE, "Profile ABORT via web interface"); |
1832 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); |
1792 } |
1833 } |
1793 break; |
1834 break; |
1794 } |
1835 } |
1795 break; |
1836 break; |
1796 } |
1837 } |
1797 } |
1838 } |
1798 |
1839 |
1799 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) { |
1840 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) { |
1800 if (sscanf(val, "%f", &fval) == 1) |
1841 if (sscanf(val, "%f", &fval) == 1) { |
|
1842 if (unit->temp_set_min != fval) |
|
1843 syslog(LOG_NOTICE, "Fermenter unit %s temperature set minimum %.1f to %.1f", unit->uuid, unit->temp_set_min, fval); |
1801 unit->temp_set_min = fval; |
1844 unit->temp_set_min = fval; |
|
1845 } |
1802 |
1846 |
1803 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MAX") == 0)) { |
1847 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MAX") == 0)) { |
1804 if (sscanf(val, "%f", &fval) == 1) |
1848 if (sscanf(val, "%f", &fval) == 1) { |
|
1849 if (unit->temp_set_max != fval) |
|
1850 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); |
1805 unit->temp_set_max = fval; |
1851 unit->temp_set_max = fval; |
|
1852 } |
1806 |
1853 |
1807 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_L") == 0)) { |
1854 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_L") == 0)) { |
1808 if (sscanf(val, "%f", &fval) == 1) |
1855 if (sscanf(val, "%f", &fval) == 1) { |
|
1856 if (unit->idle_rangeL != fval) |
|
1857 syslog(LOG_NOTICE, "Fermenter unit %s idle range low %.1f to %.1f", unit->uuid, unit->idle_rangeL, fval); |
1809 unit->idle_rangeL = fval; |
1858 unit->idle_rangeL = fval; |
|
1859 } |
1810 |
1860 |
1811 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_H") == 0)) { |
1861 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_H") == 0)) { |
1812 if (sscanf(val, "%f", &fval) == 1) |
1862 if (sscanf(val, "%f", &fval) == 1) { |
|
1863 if (unit->idle_rangeH != fval) |
|
1864 syslog(LOG_NOTICE, "Fermenter unit %s idle range high %.1f to %.1f", unit->uuid, unit->idle_rangeH, fval); |
1813 unit->idle_rangeH = fval; |
1865 unit->idle_rangeH = fval; |
|
1866 } |
1814 |
1867 |
1815 } |
1868 } |
1816 } |
1869 } |
1817 } |
1870 } |
1818 } |
1871 } |