# HG changeset patch # User Michiel Broek # Date 1407532064 -7200 # Node ID b34a1b2421fb788884e6dc7df7c5cc7de6d9532d # Parent 9eaaba49450f2d1da48097fa44df9f41bf610c84 Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen. diff -r 9eaaba49450f -r b34a1b2421fb thermferm/server.c --- a/thermferm/server.c Thu Aug 07 22:06:18 2014 +0200 +++ b/thermferm/server.c Fri Aug 08 23:07:44 2014 +0200 @@ -1116,8 +1116,10 @@ /* Initialize log if the unit is turned on */ if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) initlog(unit->name); + syslog(LOG_NOTICE, "Mode from %s to %s via web interface", UNITMODE[unit->mode], UNITMODE[i]); unit->mode = i; /* Allways turn everything off after a mode change */ + unit->PID_I_err = unit->PID_err_old = 0.0; unit->heater_state = unit->cooler_state = unit->fan_state = 0; device_out(unit->heater_address, unit->heater_state); device_out(unit->cooler_address, unit->cooler_state); @@ -1145,6 +1147,14 @@ unit->profile = xstrcpy(val); else unit->profile = NULL; + /* + * Reset all output devices + */ + unit->PID_I_err = unit->PID_err_old = 0.0; + unit->heater_state = unit->cooler_state = unit->fan_state = 0; + device_out(unit->heater_address, unit->heater_state); + device_out(unit->cooler_address, unit->cooler_state); + device_out(unit->fan_address, unit->fan_state); } } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { diff -r 9eaaba49450f -r b34a1b2421fb thermferm/thermferm.c --- a/thermferm/thermferm.c Thu Aug 07 22:06:18 2014 +0200 +++ b/thermferm/thermferm.c Fri Aug 08 23:07:44 2014 +0200 @@ -53,6 +53,7 @@ pthread_t threads[4]; #endif extern const char UNITMODE[5][8]; +extern const char PROFSTATE[4][6]; int server(void); @@ -309,8 +310,11 @@ * Safety, turn everything off */ unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; - if (unit->profile && (int)unit->prof_started && (unit->mode == UNITMODE_PROFILE)) { - syslog(LOG_NOTICE, "Starting unit %s profile %s", unit->name, unit->profile); + if (unit->mode == UNITMODE_PROFILE) { + if (unit->profile) + syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name); + else + syslog(LOG_NOTICE, "Starting unit %s in profile state %s. Target %.1f degrees", unit->name, PROFSTATE[unit->prof_state], unit->prof_target); } else if (unit->mode == UNITMODE_BEER) { syslog(LOG_NOTICE, "Starting unit %s beer cooler at %.1f degrees", unit->name, unit->beer_set); } else if (unit->mode == UNITMODE_FRIDGE) { @@ -531,6 +535,8 @@ if (debug) fprintf(stdout, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f\n", sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); + syslog(LOG_NOTICE, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f", + sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); if (unit->heater_address) { if (Out >= 2) unit->heater_state = 100; diff -r 9eaaba49450f -r b34a1b2421fb www-thermferm/css/style.css --- a/www-thermferm/css/style.css Thu Aug 07 22:06:18 2014 +0200 +++ b/www-thermferm/css/style.css Fri Aug 08 23:07:44 2014 +0200 @@ -146,11 +146,12 @@ /* * +-------------panel_top--------------+ - * |+----------------------++----------+| - * || || || - * || selector || powerled || - * || || || - * |+----------------------++----------+| + * |+----------------++----------------+| + * || || powerled || + * || selector |+----------------+| + * || |+----------------+| + * || || mode_control || + * |+----------------++----------------+| * +------------------------------------+ * +-----------panel_display------------+ * |+----------++----------++----------+| @@ -179,7 +180,7 @@ } #fermentor_selector { - width: 158px; + width: 88px; height: 156px; float: left; } @@ -190,11 +191,19 @@ } #fermentor_powerled { - width: 78px; - height: 56px; + width: 38px; + height: 36px; float: left; - text-align: center; margin-top: 10px; + margin-left: 110px; +} + +#fermentor_mode_control { + width: 148px; + height: 100px; + float: left; + margin-top: 10px; + background-color: #ddd; } diff -r 9eaaba49450f -r b34a1b2421fb www-thermferm/index.php --- a/www-thermferm/index.php Thu Aug 07 22:06:18 2014 +0200 +++ b/www-thermferm/index.php Fri Aug 08 23:07:44 2014 +0200 @@ -117,6 +117,80 @@ unset($_POST['FanState']); } +if (isset($_POST['Fridge']) && isset($_POST['key']) && isset($_POST['UUID'])) { + + if ($_POST['key'] == "Set") { + $sock = open_socket(); + if ($sock != false) { + socket_write($sock, 'UNIT PUT '.$_POST['UUID'], 4096); + usleep(20000); + socket_write($sock, 'FRIDGE_SET,'.$_POST['Fridge'], 4096); + usleep(20000); + socket_write($sock, '.', 4096); + /* Absorb response */ + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } + } + + unset($_POST['Fridge']); + unset($_POST['key']); + unset($_POST['UUID']); +} + + +if (isset($_POST['Beer']) && isset($_POST['key']) && isset($_POST['UUID'])) { + + if ($_POST['key'] == "Set") { + $sock = open_socket(); + if ($sock != false) { + socket_write($sock, 'UNIT PUT '.$_POST['UUID'], 4096); + usleep(20000); + socket_write($sock, 'BEER_SET,'.$_POST['Beer'], 4096); + usleep(20000); + socket_write($sock, '.', 4096); + /* Absorb response */ + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } + } + unset($_POST['Beer']); + unset($_POST['key']); + unset($_POST['UUID']); +} + + +if (isset($_POST['SetProfile']) && isset($_POST['key']) && isset($_POST['UUID'])) { + + if ($_POST['key'] == "Set") { + $sock = open_socket(); + if ($sock != false) { + socket_write($sock, 'UNIT PUT '.$_POST['UUID'], 4096); + usleep(20000); + socket_write($sock, 'PROFILE,'.$_POST['SetProfile'], 4096); + usleep(20000); + socket_write($sock, '.', 4096); + /* Absorb response */ + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } + } + unset($_POST['SetProfile']); + unset($_POST['key']); + unset($_POST['UUID']); +} $outstr = ''.PHP_EOL; diff -r 9eaaba49450f -r b34a1b2421fb www-thermferm/liveview.php --- a/www-thermferm/liveview.php Thu Aug 07 22:06:18 2014 +0200 +++ b/www-thermferm/liveview.php Fri Aug 08 23:07:44 2014 +0200 @@ -54,6 +54,8 @@ $set_temperature = "NA"; $air_temperature = "NA"; $beer_temperature = "NA"; + $profile = ""; + $prof_state = "OFF"; $power_led = $cooler_led = $heater_led = $fan_led = "off"; $heater = $cooler = $fan = "no"; $heater_state = $cooler_state = $fan_state = 0; @@ -95,6 +97,12 @@ if (strcmp($vals[0], "FAN_STATE") == 0) { $fan_state = $vals[1]; } + if (strcmp($vals[0], "PROFILE") == 0) { + $profile = $vals[1]; + } + if (strcmp($vals[0], "PROF_STATE") == 0) { + $prof_state = $vals[1]; + } if (($vals[0] == "BEER_SET") && ($mode == "BEER")) { $set_temperature = $vals[1]; } @@ -203,9 +211,97 @@ $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; + $outstr .= '
'.PHP_EOL; $outstr .= '
Pwr'.PHP_EOL; $outstr .= '
'.PHP_EOL; + + $outstr .= '
'.PHP_EOL; + if ($mode == "FRIDGE") { + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= '
'.PHP_EOL; + } + if ($mode == "BEER") { + $outstr .= '
'.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= '
'.PHP_EOL; + } + if ($mode == "PROFILE") { + /* + * First, load a list with available profiles. + */ + $sock = open_socket(); + if ($sock == true) { + socket_write($sock, "PROFILE LIST", 4096); + $answer = ""; + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; + } + socket_close($sock); + $reply = explode("\r\n", $answer); + } + + /* + * Show loaded profile. + */ + if ($profile == "(null)") { + $prof_name = "None"; + }else { + if (startsWith($reply[0], "212")) { + $i = 1; + while (1) { + if (strcmp($reply[$i], ".") == 0) + break; + $f = explode(",", $reply[$i]); + if ($f[0] == $profile) { + $prof_name = $f[1]; + break; + } + $i++; + } + } + } + $outstr .= '
Profile: '.$prof_name.'
'.PHP_EOL; + + $outstr .= '
'.PHP_EOL; + if ($prof_state == "OFF") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + if ($profile != "(null)") + $outstr .= ' '.PHP_EOL; + + } else if ($prof_state == "RUN") { + } else if ($prof_state == "PAUSE") { + } else if ($prof_state == "DONE") { + } + //$outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= '
'.PHP_EOL; + } + $outstr .= '
'.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= '
'.PHP_EOL;