Fixed missing light_state commands for the webcam.

Wed, 03 Jun 2020 21:02:57 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 03 Jun 2020 21:02:57 +0200
changeset 698
c7b4cb53b37c
parent 697
367ae7ff52f0
child 699
4d5f3e9f7744

Fixed missing light_state commands for the webcam.

bmsd/fermenters.c file | annotate | diff | comparison | revisions
www/js/mon_fermenter.js file | annotate | diff | comparison | revisions
--- a/bmsd/fermenters.c	Sun May 31 12:23:01 2020 +0200
+++ b/bmsd/fermenters.c	Wed Jun 03 21:02:57 2020 +0200
@@ -185,7 +185,7 @@
     char		*mode = NULL, *stage = NULL, *profile = NULL, *profile_uuid = NULL, *profile_name = NULL, *profile_steps = NULL;
     char		*topic = NULL, *pay = NULL, buf[75], *profile_command = NULL;
     float		setpoint_low = 0, setpoint_high = 0, yeast_lo = 0, yeast_hi = 0, inittemp_lo = 0, inittemp_hi = 0;
-    int			heater_state = -1, cooler_state = -1, fan_state = -1, profile_fridgemode = -1;
+    int			heater_state = -1, cooler_state = -1, fan_state = -1, light_state = -1, profile_fridgemode = -1;
 
     syslog(LOG_NOTICE, "fermenter_ws_receive(%s)", payload);
 
@@ -221,6 +221,8 @@
         cooler_state = json_object_get_int(val);
     if (json_object_object_get_ex(jobj, "fan_state", &val))
         fan_state = json_object_get_int(val);
+    if (json_object_object_get_ex(jobj, "light_state", &val))
+	light_state = json_object_get_int(val);
     if (json_object_object_get_ex(jobj, "profile", &pobj)) {
 	profile = xstrcpy((char *)json_object_get_string(pobj));
 	if (profile == NULL) { // clear profile request
@@ -332,6 +334,18 @@
             pay = NULL;
         }
 
+	if (light_state >= 0) {
+	    syslog(LOG_NOTICE, "Set fermenter %s/%s light %d", node, alias, light_state);
+	    pay = fermenter_paybase();
+	    pay = xstrcat(pay, (char *)"{\"light\":{\"state\":");
+	    snprintf(buf, 64, "%d", light_state);
+	    pay = xstrcat(pay, buf);
+	    pay = xstrcat(pay, (char *)"}}}");
+	    mqtt_publish(topic, pay);
+	    free(pay);
+	    pay = NULL;
+	}
+
 	if (beeruuid && beercode && beername && (yeast_hi > yeast_lo) && (yeast_lo > 0)) {
 	    syslog(LOG_NOTICE, "Set fermenter %s/%s beer %s %s", node, alias, beercode, beername);
             pay = fermenter_paybase();
--- a/www/js/mon_fermenter.js	Sun May 31 12:23:01 2020 +0200
+++ b/www/js/mon_fermenter.js	Wed Jun 03 21:02:57 2020 +0200
@@ -602,7 +602,8 @@
  });
  $('#Camera').jqxButton({ template: 'primary', width: '150px', theme: theme });
  $('#Camera').click(function() {
-  record.light_state = 100;
+//  record.light_state = 100;
+  websocket.send('{"device":"fermenters","node":"' + record.node + '","unit":"' + record.alias + '","light_state":100}');
   window.open(record.webcam_url);
  });
  createAbortElements();

mercurial