Sun, 14 Apr 2024 12:46:02 +0200
Add stylesheet, about page. Add menu for fermenters. Add websocket port setup to the config server.
thermferm/server.c | file | annotate | diff | comparison | revisions | |
thermferm/websocket.c | file | annotate | diff | comparison | revisions | |
www/css/style.css | file | annotate | diff | comparison | revisions | |
www/gen_about.php | file | annotate | diff | comparison | revisions | |
www/images/fridge.png | file | annotate | diff | comparison | revisions | |
www/includes/global.inc.php | file | annotate | diff | comparison | revisions |
--- a/thermferm/server.c Sat Apr 13 16:50:26 2024 +0200 +++ b/thermferm/server.c Sun Apr 14 12:46:02 2024 +0200 @@ -613,6 +613,7 @@ srv_send(s, (char *)"MQTT_PORT,%d", Config.mqtt_port); srv_send(s, (char *)"MQTT_USER,%s", Config.mqtt_username); srv_send(s, (char *)"MQTT_PASS,%s", Config.mqtt_password); + srv_send(s, (char *)"WEBSOCKET_PORT,%d", Config.websocket_port); srv_send(s, (char *)"."); return 0; } @@ -751,6 +752,14 @@ else Config.mqtt_password = NULL; + } else if (val && (strcmp(kwd, (char *)"WEBSOCKET_PORT") == 0)) { + if (sscanf(val, "%d", &ival) == 1) { + if (Config.websocket_port != ival) { + syslog(LOG_NOTICE, "Global Websocket port %d to %d", Config.websocket_port, ival); + Config.websocket_port = ival; + } + } + } } }
--- a/thermferm/websocket.c Sat Apr 13 16:50:26 2024 +0200 +++ b/thermferm/websocket.c Sun Apr 14 12:46:02 2024 +0200 @@ -75,6 +75,7 @@ ws_clients++; pss->ringbuffer_tail = ringbuffer_head; pss->wsi = wsi; + syslog(LOG_NOTICE, "Websocket: new client, now %d", ws_clients); break; } @@ -115,7 +116,7 @@ memcpy(buf, in, len); buf[len] = '\0'; - // syslog(LOG_NOTICE, "ws: reveived %ld bytes %s", len, buf); + syslog(LOG_NOTICE, "ws: reveived %ld bytes %s", len, buf); /* * These are send by bmsapp to bmsd. Then bmsd resends these via MQTT. * Do we want to change that? Or use it for the new web pages. @@ -136,6 +137,7 @@ case LWS_CALLBACK_CLOSED: ws_clients--; + syslog(LOG_NOTICE, "Websocket: del client, now %d", ws_clients); break; default:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/css/style.css Sun Apr 14 12:46:02 2024 +0200 @@ -0,0 +1,31 @@ +/* local style for thermferm web + */ + +body { + background: #ccc; + font-family: Verdana, Arial, sans-serif; + margin: 0px; +} + + +#MainPanel, +#fermenter { + width: 1278px; + height: 628px; + border: 2px solid #4297d7; + background: #252526; + float: left; + color: #eeeeee; +} + + +#about_table { + width: 960px; + background: #353536; + margin: 150px; + border: 2px solid; + border-color: #59b4d4; + border-radius: 5px 5px 5px 5px; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/gen_about.php Sun Apr 14 12:46:02 2024 +0200 @@ -0,0 +1,21 @@ +<?php +require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); +page_header('About ThermFerm', NULL); +?> + + <div id="MainPanel"> + <div id="ContentPanel"></div> + <div id='about_table'> + <table style='width: 100%; padding: 10px;'> + <tr><th colspan=2>About ThermFerm</th></tr> + <tr><td> </td><td> </td></tr> + <tr><td>Version:</td><td><?php echo $my_version;?> </td></tr> + <tr><td>Written by:</td><td>M. Broek</td></tr> + <tr><td>Widgets and style:</td><td><a style="color:white; text-decoration:none;" href="https://www.jqwidgets.com/">jQWidgets</a></td></tr> + </table> + </div> + </div> + +<?php +page_footer(); +?>
--- a/www/includes/global.inc.php Sat Apr 13 16:50:26 2024 +0200 +++ b/www/includes/global.inc.php Sun Apr 14 12:46:02 2024 +0200 @@ -24,25 +24,72 @@ /* * Look for the style names in the jqwidgets/styles directory. */ -$my_style = 'ui-redmond'; -//$my_style = 'ui-mbse'; +//$my_style = 'ui-redmond'; +$my_style = 'ui-mbse'; require_once($_SERVER['DOCUMENT_ROOT'].'/version.php'); +function open_socket() +{ + $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + + if (!($sock === false)) { + if (socket_connect($sock, "localhost", 6554)) { + socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0)); + } else { + socket_close($sock); + } + } + return $sock; +} + + +/** + * @param string $command to send to the server. + * @return string with the complete reply from the + * server. This can be a multiline reply. + */ +function send_cmd($command) +{ + $sock = open_socket(); + if ($sock == false) { + return ""; + } + socket_write($sock, $command . "\r\n", 4096); + + $answer = ""; + while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; + } + socket_close($sock); + + return $answer; +} + + +function startsWith($haystack, $needle) +{ + return !strncmp($haystack, $needle, strlen($needle)); +} + + function page_header($title, $loadjs) { global $my_style; global $my_version; ?> <!DOCTYPE html> -<html lang=en-US> +<html> <head> - <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <meta charset="utf-8"> <title>ThermFerm v<?php echo $my_version;?> - <?php echo $title;?></title> -<!-- <link type="text/css" href="css/style.css" rel="stylesheet" media="all" /> --> + <link type="text/css" href="css/style.css" rel="stylesheet" media="all" /> <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" /> <link type="text/css" href="jqwidgets/styles/jqx.<?php echo $my_style; ?>.css" rel="stylesheet" /> - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> <script> var theme = "<?php echo $my_style; ?>"; </script> @@ -72,6 +119,28 @@ <div id="jqxMenu" style='float: left;'> <ul> <li style='width: 80px;'><a href="index.php">Home</a></li> + <li style='width: 80px;'>Fermenters + <ul style='width: 200px;'> +<?php + $answer = send_cmd("LIST"); + if (strlen($answer)) { + $arr = explode("\r\n", $answer); + + if (startsWith($arr[0], "212")) { + $i = 1; + while (1) { + if (strcmp($arr[$i], ".") == 0) + break; + $parts = explode(",", $arr[$i]); + echo ' <li><img style="float: left; margin-right: 5px;" src="images/fridge.png" />'; + echo '<a href="fermenter.php?uuid='.$parts[0].'">'.$parts[1].'</a></li>'.PHP_EOL; + $i++; + } + } + } +?> + </ul> + </li> <li style='width: 80px;'>Setup <ul style='width: 200px;'> <li><img style='float: left; margin-right: 5px;' src='images/preferences.png' /><a href="set_global.php">Global</a></li> @@ -79,6 +148,7 @@ <li><img style='float: left; margin-right: 5px;' src='images/fermenter.png' /><a href="set_fermenters.php">Fermenters</a></li> <li><img style='float: left; margin-right: 5px;' src='images/computer.png' /><a href="set_simulators.php">Simulators</a></li> </ul> + </li> <li style='width: 80px;'><a href="gen_about.php">Over</a></li> </ul> </div> <!-- End menu -->