thermferm/server.c

changeset 51
a03b6dac5398
parent 49
92a9ca143677
child 52
4387a6b11eb3
--- a/thermferm/server.c	Sun May 25 16:39:54 2014 +0200
+++ b/thermferm/server.c	Sun May 25 22:06:56 2014 +0200
@@ -20,9 +20,6 @@
  * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  *****************************************************************************/
 
-
-#include "../lib/mbselib.h"
-#include "server.h"
 #include "thermferm.h"
 
 extern bool		my_shutdown;
@@ -138,10 +135,10 @@
 	hostname = hp->h_name;
     }
 
-    if (debug) {
-    	syslog(LOG_NOTICE, "Start new client connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port));
-	fprintf(stdout, "Start new client connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port));
-    }
+//    if (debug) {
+//    	syslog(LOG_NOTICE, "Start new client connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port));
+//	fprintf(stdout, "Start new client connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port));
+//    }
 
     memset((char *)&buf, 0, SS_BUFSIZE);
     fromlen = sizeof(peeraddr_in);
@@ -201,10 +198,17 @@
 		if (debug)
 		    fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc);
 		if (rc == 1) {
-		    srv_send("ack");
-		    cs_mode = 'b';
-		    cs_beerSet = newtemp;
+		    if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) {
+		    	syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp);
+		    	srv_send("ack");
+		    	cs_mode = 'b';
+		    	cs_beerSet = newtemp;
+		    } else {
+			syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax);
+			srv_send("err");
+		    }
 		} else {
+		    syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp);
 		    srv_send("err");
 		}
 		free(inp);
@@ -214,18 +218,45 @@
 		if (debug)
 		    fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc);
 		if (rc == 1) {
-		    srv_send("ack");
-		    cs_mode = 'f';
-		    cs_fridgeSet = newtemp;
+		    if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) {
+			syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp);
+		    	srv_send("ack");
+		    	cs_mode = 'f';
+		    	cs_fridgeSet = newtemp;
+		    } else {
+			syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax);
+			srv_send("err");
+		    }
 		} else {
+		    syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp);
 		    srv_send("err");
 		}
 		free(inp);
 	    } else if (strncmp(buf, "setOff", 6) == 0) {
 		if (debug)
 		    fprintf(stdout, "temperature control disabled\n");
+		syslog(LOG_NOTICE, "Notification: Temperature control disabled");
 		cs_mode = 'o';
 		srv_send("ack");
+	    } else if (strncmp(buf, "setParameters", 13) == 0) {
+		if (debug)
+		    fprintf(stdout, "FIXME:\n");
+		srv_send("ack");
+	// stopScript
+	// quit
+	// eraseLogs
+	// interval
+	// startNewBrew
+	// pauseLogging
+	// stopLogging
+	// resumeLogging
+	// dateTimeFormatDisplay
+	    } else if (strncmp(buf, "setActiveProfile", 16) == 0) {
+		syslog(LOG_NOTICE, "Setting profile '%s' as active profile", "undefined");
+	// programArduino
+	// refreshDeviceList
+	// getDeviceList
+	// applyDevice
 	    } else {
 		if (debug)
 		    fprintf(stdout, "unknown command \"%s\"\n", buf);
@@ -234,10 +265,10 @@
 	}
     }
 
-    if (debug) {
-    	syslog(LOG_NOTICE, "End connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port));
-	fprintf(stdout, "End connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port));
-    }
+//    if (debug) {
+//    	syslog(LOG_NOTICE, "End connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port));
+//	fprintf(stdout, "End connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port));
+//    }
 
     close(s);
 }

mercurial