Wed, 30 Jul 2014 22:57:48 +0200
Unit mode can switch between OFF and NONE.
--- a/thermferm/Makefile Wed Jul 30 19:39:50 2014 +0200 +++ b/thermferm/Makefile Wed Jul 30 22:57:48 2014 +0200 @@ -62,7 +62,7 @@ logger.o: logger.h thermferm.h futil.h xutil.h lcd-pcf8574.o: thermferm.h lcd-pcf8574.h xutil.o: thermferm.h xutil.h -server.o: rdconfig.h thermferm.h server.h xutil.h +server.o: rdconfig.h thermferm.h logger.h server.h xutil.h rdconfig.o: rdconfig.h thermferm.h futil.h xutil.h units.o: thermferm.h units.h xutil.h # End of generated dependencies
--- a/thermferm/logger.c Wed Jul 30 19:39:50 2014 +0200 +++ b/thermferm/logger.c Wed Jul 30 22:57:48 2014 +0200 @@ -26,6 +26,20 @@ #include "xutil.h" +void initlog(char *unit) +{ + char buf[128], *filename; + + snprintf(buf, 127, "Mode,Air,Beer,Target,Heater,Cooler,Fan,Door"); + filename = xstrcpy(unit); + filename = xstrcat(filename, (char *)".log"); + logger(filename, buf); + free(filename); + filename = NULL; +} + + + void logger(char *filename, char *data) { struct timeval now;
--- a/thermferm/logger.h Wed Jul 30 19:39:50 2014 +0200 +++ b/thermferm/logger.h Wed Jul 30 22:57:48 2014 +0200 @@ -3,5 +3,7 @@ void logger(char *, char *); +void initlog(char *); + #endif
--- a/thermferm/server.c Wed Jul 30 19:39:50 2014 +0200 +++ b/thermferm/server.c Wed Jul 30 22:57:48 2014 +0200 @@ -22,6 +22,7 @@ #include "rdconfig.h" #include "thermferm.h" +#include "logger.h" #include "server.h" #include "xutil.h" @@ -491,6 +492,52 @@ */ int cmd_mode(char *buf) { + char *opt; + units_list *unit; + + opt = strtok(buf, " \0"); + opt = strtok(NULL, "\0"); + + if (opt == NULL) { + srv_send((char *)"502 Missing command option"); + return 1; + } + + if (current_unit == NULL) { + srv_send((char *)"401 No fermenter unit selected"); + return 1; + } + for (unit = Config.units; unit; unit = unit->next) { + if (strcmp(current_unit, unit->uuid) == 0) + break; + } + + if (strcmp(opt, (char *)"OFF") == 0) { + if (unit->mode != UNITMODE_OFF) { + unit->mode = UNITMODE_OFF; + syslog(LOG_NOTICE, "Unit %s mode set to OFF", unit->name); + } + srv_send((char *)"218 Unit mode to OFF"); + return 0; + + } else if (strcmp(opt, (char *)"NONE") == 0) { + if (unit->mode != UNITMODE_NONE) { + unit->mode = UNITMODE_NONE; + syslog(LOG_NOTICE, "Unit %s mode set to NONE", unit->name); + initlog(unit->name); + } + srv_send((char *)"218 Unit mode to NONE"); + return 0; + + } else if (strcmp(opt, (char *)"FRIDGE") == 0) { + + } else if (strcmp(opt, (char *)"BEER") == 0) { + + } else if (strcmp(opt, (char *)"PROFILE") == 0) { + + } + + srv_send((char *)"502 Unknown command option"); return 1; }
--- a/thermferm/thermferm.c Wed Jul 30 19:39:50 2014 +0200 +++ b/thermferm/thermferm.c Wed Jul 30 22:57:48 2014 +0200 @@ -294,12 +294,7 @@ for (unit = Config.units; unit; unit = unit->next) { if (unit->mode != UNITMODE_OFF) { - snprintf(buf, 1023, "Mode,Air,Beer,Target,Heater,Cooler,Fan,Door"); - filename = xstrcpy(unit->name); - filename = xstrcat(filename, (char *)".log"); - logger(filename, buf); - free(filename); - filename = NULL; + initlog(unit->name); } }
--- a/www-thermferm/index.php Wed Jul 30 19:39:50 2014 +0200 +++ b/www-thermferm/index.php Wed Jul 30 22:57:48 2014 +0200 @@ -26,9 +26,21 @@ */ $my_style = 'ui-redmond'; +require_once('utilities.php'); require_once('liveview.php'); + +/* + * Handle the post events + */ +if (isset($_POST['mode']) && isset($_POST['UUID'])) { + send_cmd('UNIT '.$_POST['UUID']); + send_cmd('MODE '.$_POST['mode']); +} + + + $outstr = '<!DOCTYPE html>'.PHP_EOL; $outstr .= '<html>'.PHP_EOL; $outstr .= ' <head>'.PHP_EOL; @@ -66,3 +78,8 @@ echo $outstr; +echo "_GET "; +print_r ($_GET); +echo "<br> _POST "; +print_r ($_POST); +
--- a/www-thermferm/liveview.php Wed Jul 30 19:39:50 2014 +0200 +++ b/www-thermferm/liveview.php Wed Jul 30 22:57:48 2014 +0200 @@ -160,18 +160,6 @@ $outstr .= ' }]'.PHP_EOL; $outstr .= ' };'.PHP_EOL; $outstr .= ' $("#fermentor_chart_'.$unit.'").jqxChart(settings'.$unr.');'.PHP_EOL; - strcmp($mode, "OFF") ? $se = "" : $se = ", checked: true"; - $outstr .= ' $("#selButton1_'.$unit.'").jqxRadioButton({ groupName: "'.$unit.'", theme: "'.$my_style.'", width: 150, height: 18'.$se.'});'.PHP_EOL; - strcmp($mode, "NONE") ? $se = "" : $se = ", checked: true"; - $outstr .= ' $("#selButton2_'.$unit.'").jqxRadioButton({ groupName: "'.$unit.'", theme: "'.$my_style.'", width: 150, height: 18'.$se.'});'.PHP_EOL; - strcmp($mode, "FRIDGE") ? $se = "" : $se = ", checked: true"; - (strcmp($heater, "no") || strcmp($cooler, "no")) ? $dis = "" : $dis = ", disabled: true"; - $outstr .= ' $("#selButton3_'.$unit.'").jqxRadioButton({ groupName: "'.$unit.'", theme: "'.$my_style.'", width: 150, height: 18'.$se.$dis.'});'.PHP_EOL; - strcmp($mode, "BEER") ? $se = "" : $se = ", checked: true"; - $outstr .= ' $("#selButton4_'.$unit.'").jqxRadioButton({ groupName: "'.$unit.'", theme: "'.$my_style.'", width: 150, height: 18'.$se.$dis.'});'.PHP_EOL; - strcmp($mode, "PROFILE") ? $se = "" : $se = ", checked: true"; - $outstr .= ' $("#selButton5_'.$unit.'").jqxRadioButton({ groupName: "'.$unit.'", theme: "'.$my_style.'", width: 150, height: 18'.$se.$dis.'});'.PHP_EOL; - $outstr .= ' });'.PHP_EOL; $outstr .= ' </script>'.PHP_EOL; $outstr .= ' <div id="fermentor">'.PHP_EOL; @@ -179,11 +167,20 @@ $outstr .= ' <div id="fermentor_panel_top">'.PHP_EOL; $outstr .= ' <div id="fermentor_selector">'.PHP_EOL; - $outstr .= ' <div style="margin-top: 10px;" id="selButton1_'.$unit.'">Off</div>'.PHP_EOL; - $outstr .= ' <div style="margin-top: 10px;" id="selButton2_'.$unit.'">None</div>'.PHP_EOL; - $outstr .= ' <div style="margin-top: 10px;" id="selButton3_'.$unit.'">Fridge</div>'.PHP_EOL; - $outstr .= ' <div style="margin-top: 10px;" id="selButton4_'.$unit.'">Beer</div>'.PHP_EOL; - $outstr .= ' <div style="margin-top: 10px;" id="selButton5_'.$unit.'">Profile</div>'.PHP_EOL; + $outstr .= ' <form id="select_'.$unr.'" action="index.php" method="post">'.PHP_EOL; + strcmp($mode, "OFF") ? $se = "" : $se = " checked"; + $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="OFF"'.$se.'>Off<br>'.PHP_EOL; + strcmp($mode, "NONE") ? $se = "" : $se = " checked"; + $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="NONE"'.$se.'>None<br>'.PHP_EOL; + (strcmp($heater, "no") || strcmp($cooler, "no")) ? $dis = "" : $dis = " disabled"; + strcmp($mode, "FRIDGE") ? $se = "" : $se = " checked"; + $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="FRIDGE"'.$se.$dis.'>Fridge<br>'.PHP_EOL; + strcmp($mode, "BEER") ? $se = "" : $se = " checked"; + $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="BEER"'.$se.$dis.'>Beer<br>'.PHP_EOL; + strcmp($mode, "PROFILE") ? $se = "" : $se = " checked"; + $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="PROFILE"'.$se.$dis.'>Profile'.PHP_EOL; + $outstr .= ' <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL; + $outstr .= ' </form>'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_powerled">'.PHP_EOL; $outstr .= ' <img src="images/led_green_'.$power_led.'.png"><br>Pwr'.PHP_EOL; @@ -213,25 +210,29 @@ $outstr .= ' <img src="images/led_green_'.$fan_led.'.png"><br>Fan'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_toggle1">'.PHP_EOL; - $outstr .= ' <form>'.PHP_EOL; - strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; + $outstr .= ' <form action="index.php" method="post">'.PHP_EOL; + strcmp($mode, "NONE") ? $dis = " disabled" : $dis = ""; $ch = " checked"; - $outstr .= ' <input type="radio" name="cooler'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; - $outstr .= ' <input type="radio" name="cooler'.$unr.'" value="ON"'.$se.'>On'.PHP_EOL; + + $outstr .= ' <input type="radio" name="cooler" onchange="this.form.submit()" value="OFF"'.$dis.$ch.'>Off<br>'.PHP_EOL; + $outstr .= ' <input type="radio" name="cooler" onchange="this.form.submit()" value="ON"'.$dis.'>On'.PHP_EOL; + $outstr .= ' <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL; $outstr .= ' </form>'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_toggle2">'.PHP_EOL; - $outstr .= ' <form>'.PHP_EOL; - strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; - $outstr .= ' <input type="radio" name="heater'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; - $outstr .= ' <input type="radio" name="heater'.$unr.'" value="ON"'.$se.'>On'.PHP_EOL; + $outstr .= ' <form action="index.php" method="post">'.PHP_EOL; + strcmp($mode, "NONE") ? $dis = " disabled" : $dis = ""; + $outstr .= ' <input type="radio" name="heater" onchange="this.form.submit()" value="OFF"'.$dis.$ch.'>Off<br>'.PHP_EOL; + $outstr .= ' <input type="radio" name="heater" onchange="this.form.submit()" value="ON"'.$dis.'>On'.PHP_EOL; + $outstr .= ' <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL; $outstr .= ' </form>'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_toggle3">'.PHP_EOL; - $outstr .= ' <form>'.PHP_EOL; - strcmp($mode, "NONE") ? $se = " disabled" : $se = ""; - $outstr .= ' <input type="radio" name="fan'.$unr.'" value="OFF"'.$se.$ch.'>Off<br>'.PHP_EOL; - $outstr .= ' <input type="radio" name="fan'.$unr.'" value="ON"'.$se.'>On'.PHP_EOL; + $outstr .= ' <form action="index.php" method="post">'.PHP_EOL; + strcmp($mode, "NONE") ? $dis = " disabled" : $dis = ""; + $outstr .= ' <input type="radio" name="fan" onchange="this.form.submit()" value="OFF"'.$dis.$ch.'>Off<br>'.PHP_EOL; + $outstr .= ' <input type="radio" name="fan" onchange="this.form.submit()" value="ON"'.$dis.'>On'.PHP_EOL; + $outstr .= ' <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL; $outstr .= ' </form>'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' </div> <!-- fermentor_panel_control -->'.PHP_EOL;
--- a/www-thermferm/utilities.php Wed Jul 30 19:39:50 2014 +0200 +++ b/www-thermferm/utilities.php Wed Jul 30 22:57:48 2014 +0200 @@ -94,3 +94,24 @@ </script>'; } + +/* + * Send command + */ +function send_cmd($cmd) { + $sock = open_socket(); + if ($sock != false) { + /* + * Send command and absorb the result. + */ + socket_write($sock, $cmd, 4096); + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } +} + +