# HG changeset patch # User Michiel Broek # Date 1407680223 -7200 # Node ID 8d2ba41265199d9c76f0cefc508a566199dbf89f # Parent 78fb6f99e47374bc536fc0a369e0dc726296b4e1 Added global setup diff -r 78fb6f99e473 -r 8d2ba4126519 thermferm/thermferm.c --- a/thermferm/thermferm.c Sun Aug 10 14:45:11 2014 +0200 +++ b/thermferm/thermferm.c Sun Aug 10 16:17:03 2014 +0200 @@ -103,7 +103,7 @@ -int read_w1_28(char *address, int *val) +int read_sensor(char *address, int *val) { devices_list *device; int tmp; @@ -364,6 +364,36 @@ lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); #endif + if (Config.temp_address) { + rc = read_sensor(Config.temp_address, &temp); + if (rc == DEVPRESENT_YES) { + Config.temp_value = temp; + Config.temp_state = 0; +#ifdef HAVE_WIRINGPI_H + lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf); +#endif + } else if (rc == DEVPRESENT_ERROR) { + Config.temp_state = 1; + } else { + Config.temp_state = 2; + } + } + + if (Config.hum_address) { + rc = read_sensor(Config.hum_address, &temp); + if (rc == DEVPRESENT_YES) { + Config.hum_value = temp; + Config.hum_state = 0; +#ifdef HAVE_WIRINGPI_H + lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf); +#endif + } else if (rc == DEVPRESENT_ERROR) { + Config.hum_state = 1; + } else { + Config.hum_state = 2; + } + } + for (unit = Config.units; unit; unit = unit->next) { #ifdef HAVE_WIRINGPI_H lcd_buf_write(row++, "Unit %s ", unit->name); @@ -371,7 +401,7 @@ #endif if (unit->air_address) { - rc = read_w1_28(unit->air_address, &temp); + rc = read_sensor(unit->air_address, &temp); if (rc == DEVPRESENT_YES) { /* * It is possible to have read errors or extreme values. @@ -403,7 +433,7 @@ } if (unit->beer_address) { - rc = read_w1_28(unit->beer_address, &temp); + rc = read_sensor(unit->beer_address, &temp); if (rc == DEVPRESENT_YES) { deviation = 40000; if ((unit->beer_temperature == 0) || diff -r 78fb6f99e473 -r 8d2ba4126519 www-thermferm/getroom.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www-thermferm/getroom.php Sun Aug 10 16:17:03 2014 +0200 @@ -0,0 +1,62 @@ + + * + * This file is part of ThermFerm + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * ThermFerm is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ThermFerm; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + +require_once('utilities.php'); + + +$answer = send_cmd('GLOBAL GET'); +$arr = explode("\r\n", $answer); + +$temp_value = "NA"; +$temp_state = "NA"; +$hum_value = "NA"; +$hum_state = "NA"; + +if (startsWith($arr[0], "213")) { + $j = 1; + while (1) { + if (strcmp($arr[$j], ".") == 0) + break; + $f = explode(",", $arr[$j]); + + if ($f[0] == "TEMP_STATE") + $temp_state = $f[1]; + if (($f[0] == "TEMP_VALUE") && ($temp_state == "OK")) + $temp_value = $f[1]; + if ($f[0] == "HUM_STATE") + $hum_state = $f[1]; + if (($f[0] == "HUM_VALUE") && ($hum_state == "OK")) + $hum_value = $f[1]; + $j++; + } +} + + +$reply = array ( + 'temperature' => $temp_value, + 'humidity' => $hum_value +); + + +echo json_encode($reply); +?> diff -r 78fb6f99e473 -r 8d2ba4126519 www-thermferm/global.php --- a/www-thermferm/global.php Sun Aug 10 14:45:11 2014 +0200 +++ b/www-thermferm/global.php Sun Aug 10 16:17:03 2014 +0200 @@ -23,13 +23,233 @@ require_once('utilities.php'); -$outstr = build_header("ThermFerm - Global Setup"); -$outstr .= '
'.PHP_EOL; -$outstr .= '
'.PHP_EOL; -$outstr .= '
'.PHP_EOL; + +if (isset($_POST['action'])) { + if ($_POST['action'] == "testdata") + testdata(); +} else { + edit_screen(""); +} + + +exit; + + +/***************************************************************************** + * + */ + + +function global_update() { + + if ($_POST['key'] == 'Save') { + $sock = open_socket(); + if ($sock != false) { + /* + * Send command and absorb the result. + */ + socket_write($sock, "GLOBAL PUT", 4096); + usleep(20000); + socket_write($sock, "NAME,".$_POST['Name'], 4096); + usleep(20000); + socket_write($sock, "PORT,".$_POST['Port'], 4096); + usleep(20000); + socket_write($sock, "TEMP_ADDRESS,".$_POST['TempAddress'], 4096); + usleep(20000); + socket_write($sock, "HUM_ADDRESS,".$_POST['HumAddress'], 4096); + usleep(20000); + if (isset($_POST['LCDcols'])) { + socket_write($sock, "LCD_COLS,".$_POST['LCDcols'], 4096); + usleep(20000); + } + if (isset($_POST['LCDrows'])) { + socket_write($sock, "LCD_ROWS,".$_POST['LCDrows'], 4096); + usleep(20000); + } + socket_write($sock, ".", 4096); + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + } + socket_close($sock); + } + } + + unset($_POST['Name']); + unset($_POST['Port']); + unset($_POST['TempAddress']); + unset($_POST['HumAddress']); + unset($_POST['LCDcols']); + unset($_POST['LCDrows']); + unset($_POST['key']); + load('global.php'); +} + + + +function test_thedata() { + + if (isset($_POST['Name']) && isset($_POST['Port']) && + isset($_POST['TempAddress']) && isset($_POST['HumAddress']) && + isset($_POST['key'])) { + + if ($_POST['key'] == 'Cancel') + return 99; + + if (isset($_POST['LCDcols']) && (($_POST['LCDcols'] != 16) && ($_POST['LCDcols'] != 20))) + return 2; + + if (isset($_POST['LCDrows']) && (($_POST['LCDrows'] != 2) && ($_POST['LCDrows'] != 4))) + return 3; + + } else { + return 1; + } + + return 0; +} + + + +function testdata() +{ + $result = test_thedata(); + $error = ''; + + switch ($result) { + case 0: global_update(); + return; + break; + case 1: $error = 'Missing data'; + break; + case 2: $error = 'LCD columns must be 16 or 20'; + break; + case 3: $error = 'LCD rows must be 2 or 4'; + break; + case 99: + load('global.php'); + break; + } + + edit_screen($error); +} + + -$outstr .= '
'.PHP_EOL; -$outstr .= build_footer(); +function edit_screen($error_message) +{ + /* + * Get list of devices, we need it later + */ + $answer = send_cmd("DEVICE LIST"); + $devices = explode("\r\n", $answer); + + /* + * Get current global data + */ + $answer = send_cmd("GLOBAL GET"); + $reply = explode("\r\n", $answer); + + $outstr = build_header("ThermFerm - Global Setup"); + $outstr .= '
'.PHP_EOL; + $outstr .= ' '.$error_message.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + + if (startsWith($reply[0], "213")) { + $i = 1; + while (1) { + if (strcmp($reply[$i], ".") == 0) + break; + $f = explode(",", $reply[$i]); -echo $outstr; + if ($f[0] == "NAME") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "PORT") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "TEMP_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "HUM_ADDRESS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "LCD_COLS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "LCD_ROWS") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + $i++; + } + } + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; + $outstr .= '
Global Setup
System Name
Telnet port
Room temperature sensor
Room humidity sensor
LCD columns
LCD rows
'; + $outstr .= ''; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= '
'.PHP_EOL; + $outstr .= build_footer(); + + echo $outstr; +} + +