Increased server buffersize from 1024 to 4096. Added DEVICE JSON <uuid> command. Added websocket response fermenter profile. The fermenter monitor screen is ready (maybe).

Tue, 16 Apr 2024 16:03:47 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 16 Apr 2024 16:03:47 +0200
changeset 680
8b3c86124a08
parent 679
ecfcb1104b54
child 681
1f81e52c5abf

Increased server buffersize from 1024 to 4096. Added DEVICE JSON <uuid> command. Added websocket response fermenter profile. The fermenter monitor screen is ready (maybe).

thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/websocket.c file | annotate | diff | comparison | revisions
www/js/fermenter.js file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Mon Apr 15 17:06:15 2024 +0200
+++ b/thermferm/server.c	Tue Apr 16 16:03:47 2024 +0200
@@ -53,7 +53,7 @@
 
 struct hostent		*hp;
 
-#define SS_BUFSIZE      1024
+#define SS_BUFSIZE      4096
 #define SS_TIMEOUT      300
 
 #define	MAX_INTERVALS	10
@@ -298,8 +298,10 @@
  * DEVICE ADD type
  * DEVICE DEL uuid
  * DEVICE LIST
+ * DEVICE JSON
  * DEVICE GET uuid
  * DEVICE PUT uuid
+ * DEVICE JSON uuid
  */
 int cmd_device(int s, char *buf)
 {
@@ -339,71 +341,162 @@
 	return 0;
     }
 
+    if (strcmp(opt, (char *)"JSON") == 0) {
+	char	*payload = NULL, vbuf[64];
+	bool	comma = false;
+
+	if (param == NULL) {
+	    srv_send(s, (char *)"212 Devices json list follows:");
+	    payload = xstrcpy((char *)"[");
+	    for (device = Config.devices; device; device = device->next) {
+		if (comma)
+		    payload = xstrcat(payload, (char *)",");
+		payload = xstrcat(payload, (char *)"{\"uuid\":\"");
+		payload = xstrcat(payload, device->uuid);
+		payload = xstrcat(payload, (char *)"\",\"address\":\"");
+		payload = xstrcat(payload, device->address);
+		payload = xstrcat(payload, (char *)"\",\"subdevice\":");
+		snprintf(vbuf, 63, "%d", device->subdevice);
+		payload = xstrcat(payload, vbuf);
+		payload = xstrcat(payload, (char *)",\"inuse\":");
+		snprintf(vbuf, 63, "%d", device->inuse);
+		payload = xstrcat(payload, vbuf);
+		payload = xstrcat(payload, (char *)",\"comment\":\"");
+		payload = xstrcat(payload, device->comment);
+		payload = xstrcat(payload, (char *)"\",\"direction\":\"");
+		payload = xstrcat(payload, (char *)DEVDIR[device->direction]);
+		payload = xstrcat(payload, (char *)"\",\"value\":");
+		snprintf(vbuf, 63, "%d", device->value + device->offset);
+		payload = xstrcat(payload, vbuf);
+		payload = xstrcat(payload, (char *)"}");
+		comma = true;
+	    }
+	    payload = xstrcat(payload, (char *)"]");
+	    srv_send(s, payload);
+	    srv_send(s, (char *)".");
+	    free(payload);
+	    payload = NULL;
+	    return 0;
+	} else {
+	    for (device = Config.devices; device; device = device->next) {
+            	if (strcmp(device->uuid, param) == 0) {
+	    	    payload = xstrcpy((char *)"{\"type\":\"device\",\"unit\":\"");
+	    	    snprintf(vbuf, 63, "%d", device->subdevice);
+		    payload = xstrcat(payload, device->address);
+		    payload = xstrcat(payload, (char *)"-");
+		    payload = xstrcat(payload, vbuf);
+		    payload = xstrcat(payload, (char *)"\",\"metric\":{\"uuid\":\"");
+		    payload = xstrcat(payload, device->uuid);
+		    payload = xstrcat(payload, (char *)"\",\"type\":\"");
+		    payload = xstrcat(payload, (char *)DEVTYPE[device->type]);
+		    payload = xstrcat(payload, (char *)"\",\"direction\":\"");
+		    payload = xstrcat(payload, (char *)DEVDIR[device->direction]);
+		    payload = xstrcat(payload, (char *)"\",\"address\":\"");
+		    payload = xstrcat(payload, device->address);
+		    payload = xstrcat(payload, (char *)"\",\"subdevice\":");
+		    snprintf(vbuf, 63, "%d", device->subdevice);
+		    payload = xstrcat(payload, vbuf);
+		    payload = xstrcat(payload, (char *)",\"value\":");
+		    snprintf(vbuf, 63, "%d", device->value);
+		    payload = xstrcat(payload, vbuf);
+		    payload = xstrcat(payload, (char *)",\"offset\":");
+		    snprintf(vbuf, 63, "%d", device->offset);
+		    payload = xstrcat(payload, vbuf);
+		    payload = xstrcat(payload, (char *)",\"present\":\"");
+		    payload = xstrcat(payload, (char *)DEVPRESENT[device->present]);
+		    payload = xstrcat(payload, (char *)"\",\"gpiopin\":");
+		    snprintf(vbuf, 63, "%d", device->gpiopin);
+		    payload = xstrcat(payload, vbuf);
+		    payload = xstrcat(payload, (char *)",\"inuse\":");
+		    snprintf(vbuf, 63, "%d", device->inuse);
+		    payload = xstrcat(payload, vbuf);
+		    payload = xstrcat(payload, (char *)",\"description\":\"");
+		    payload = xstrcat(payload, device->description);
+		    payload = xstrcat(payload, (char *)"\",\"comment\":\"");
+		    payload = xstrcat(payload, device->comment);
+		    payload = xstrcat(payload, (char *)"\",\"timestamp\":");
+		    snprintf(vbuf, 63, "%ld", (long)device->timestamp);
+		    payload = xstrcat(payload, vbuf);
+		    payload = xstrcat(payload, (char *)"}}");
+	    	    srv_send(s, (char *)"213 Device json record follows:");
+		    srv_send(s, payload);
+	    	    free(payload);
+	    	    payload = NULL;
+	    	    srv_send(s, (char *)".");
+		    return 0;
+		}
+	    }
+	    srv_send(s, (char *)"440 No such device");
+            return 0;
+	}
+    }
+
     if (param == NULL) {
-	srv_send(s, (char *)"502 Parameter missing");
-	return 1;
+        srv_send(s, (char *)"502 Parameter missing");
+        return 1;
     }
 
     if (strcmp(opt, (char *)"ADD") == 0) {
-	if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) ||
-	    (strcmp(param, (char *)"I2C") == 0) || (strcmp(param, (char *)"SPI") == 0)) {
+        if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) ||
+            (strcmp(param, (char *)"I2C") == 0) || (strcmp(param, (char *)"SPI") == 0)) {
 
-	    device = (devices_list *)malloc(sizeof(devices_list));
-	    device->next = NULL;
-	    device->uuid = malloc(37);
-	    uuid_generate(uu);
-	    uuid_unparse(uu, device->uuid);
-	    for (i = 0; i < 8; i++) {
-		if (strcmp(param, DEVTYPE[i]) == 0) {
-		    device->type = i;
-		    break;
-		}
-	    }
-	    device->direction = DEVDIR_UNDEF;
-	    device->value = device->offset = device->subdevice = device->inuse = 0;
-	    device->present = DEVPRESENT_UNDEF;
-	    device->address = xstrcpy((char *)"Enter address here");
-	    device->gpiopin = -1;
-	    device->description = xstrcpy((char *)"Describe me here");
-	    device->comment = xstrcpy((char *)"Comment here");
+            device = (devices_list *)malloc(sizeof(devices_list));
+            device->next = NULL;
+            device->uuid = malloc(37);
+            uuid_generate(uu);
+            uuid_unparse(uu, device->uuid);
+            for (i = 0; i < 8; i++) {
+                if (strcmp(param, DEVTYPE[i]) == 0) {
+                    device->type = i;
+                    break;
+                }
+            }
+            device->direction = DEVDIR_UNDEF;
+            device->value = device->offset = device->subdevice = device->inuse = 0;
+            device->present = DEVPRESENT_UNDEF;
+            device->address = xstrcpy((char *)"Enter address here");
+            device->gpiopin = -1;
+            device->description = xstrcpy((char *)"Describe me here");
+            device->comment = xstrcpy((char *)"Comment here");
 
-	    pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
-	    if (Config.devices == NULL) {
-		Config.devices = device;
-	    } else {
-	        for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) {
-	    	    if (tmpd->next == NULL) {
-	    		tmpd->next = device;
-    			break;
-		    }
-		}
-	    }
-	    pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
-	    syslog(LOG_NOTICE, "Device %s added", device->uuid);
-	    srv_send(s, (char *)"211 Device %s added", device->uuid);
-	    return 1;
+            pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
+            if (Config.devices == NULL) {
+                Config.devices = device;
+            } else {
+                for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) {
+                    if (tmpd->next == NULL) {
+                        tmpd->next = device;
+                        break;
+                    }
+                }
+            }
+            pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
+            syslog(LOG_NOTICE, "Device %s added", device->uuid);
+            srv_send(s, (char *)"211 Device %s added", device->uuid);
+            return 1;
 
-	} else {
-	    srv_send(s, (char *)"503 Parameter error");
-	    return 0;
-	}
+        } else {
+            srv_send(s, (char *)"503 Parameter error");
+            return 0;
+        }
     }
 
     if (strcmp(opt, (char *)"DEL") == 0) {
-	
-	pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
-	rc = delete_Device(param);
-	pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
-	if (rc) {
-	    syslog(LOG_NOTICE, "Device %s deleted", param);
-	    srv_send(s, (char *)"211 Device %s deleted", param);
-	    return 1;
-	} else {
-	    srv_send(s, (char *)"440 No such device");
-	    return 0;
-	}
+
+        pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
+        rc = delete_Device(param);
+        pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
+        if (rc) {
+            syslog(LOG_NOTICE, "Device %s deleted", param);
+            srv_send(s, (char *)"211 Device %s deleted", param);
+            return 1;
+        } else {
+            srv_send(s, (char *)"440 No such device");
+            return 0;
+        }
     }
 
+
     if (strcmp(opt, (char *)"GET") == 0) {
 	for (device = Config.devices; device; device = device->next) {
 	    if (strcmp(device->uuid, param) == 0) {
--- a/thermferm/websocket.c	Mon Apr 15 17:06:15 2024 +0200
+++ b/thermferm/websocket.c	Tue Apr 16 16:03:47 2024 +0200
@@ -70,7 +70,7 @@
 
 void fermenter_ws_receive(char *buf)
 {
-    struct json_object	*val, *val2, *jobj;
+    struct json_object	*val, *val2, *jobj, *profile;
     units_list		*unit;
     bool		changed;
 
@@ -212,6 +212,67 @@
                 break;
             }
 
+	    /*
+	     * We don't implement "light", "product", "profile" download here.
+	     * But "profile" commands are implemented. That means a profile
+	     * must be installed by bmsd via mqtt.
+	     * {"type":"fermenter","unit":"unit0","profile":{"command":"pause"}}
+	     * off pause start abort done
+	     */
+	    if ((json_object_object_get_ex(jobj, "profile", &profile)) && (unit->mode == UNITMODE_PROFILE)) {
+		if (json_object_object_get_ex(profile, "command", &val)) {
+		    char *cmd = xstrcpy((char *)json_object_get_string(val));
+		    syslog(LOG_NOTICE, "ws: profile command `%s'", cmd);
+		    if ((! strcmp(cmd, (char *)"off")) && (unit->prof_state == PROFILE_DONE)) {
+			unit->prof_state = PROFILE_OFF;
+			syslog(LOG_NOTICE, "ws: unit %s profile to OFF", unit->alias);
+			unit->mqtt_flag |= MQTT_FLAG_DATA;
+		    } else if (! strcmp(cmd, (char *)"pause")) {
+			if (unit->prof_state == PROFILE_RUN) {
+			    unit->prof_state = PROFILE_PAUSE;
+			    syslog(LOG_NOTICE, "ws: unit %s profile to PAUSE", unit->alias);
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			} else if (unit->prof_state == PROFILE_PAUSE) {
+			    unit->prof_state = PROFILE_RUN;
+			    syslog(LOG_NOTICE, "ws: unit %s profile resume RUN", unit->alias);
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			}
+		    } else if (! strcmp(cmd, (char *)"start")) {
+			if (unit->prof_state == PROFILE_OFF) {
+			    unit->prof_state = PROFILE_RUN;
+			    unit->prof_started = time(NULL);
+			    unit->prof_paused = unit->prof_primary_done = 0;
+			    unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
+			    syslog(LOG_NOTICE, "ws: unit %s profile start RUN", unit->alias);
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			    if (! unit->event_msg)
+				unit->event_msg = xstrcpy((char *)"Profile start");
+			}
+		    } else if (! strcmp(cmd, (char *)"abort")) {
+			if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) {
+			    unit->prof_state = PROFILE_OFF;
+			    unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
+			    unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
+			    syslog(LOG_NOTICE, "ws: unit %s profile ABORT", unit->alias);
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			    if (! unit->event_msg)
+				unit->event_msg = xstrcpy((char *)"Profile abort");
+			}
+		    } else if (! strcmp(cmd, (char *)"done")) {
+			if (unit->prof_state == PROFILE_DONE) {
+			    unit->prof_state = PROFILE_OFF;
+			    unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
+			    unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
+			    syslog(LOG_NOTICE, "ws: unit %s profile OFF", unit->alias);
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			}
+		    }
+		    free(cmd);
+		    cmd = NULL;
+		}
+		break;
+	    }
+
 	    return;
 	}
     }
--- a/www/js/fermenter.js	Mon Apr 15 17:06:15 2024 +0200
+++ b/www/js/fermenter.js	Tue Apr 16 16:03:47 2024 +0200
@@ -141,13 +141,13 @@
    { name: 'alarm', map: 'metric>alarm', type: 'int' },
    { name: 'setpoint_high', map: 'metric>setpoint>high' },
    { name: 'setpoint_low', map: 'metric>setpoint>low' },
-   { name: 'profile_uuid', type: 'string' },
-   { name: 'profile_name', type: 'string' },
-   { name: 'profile_state', type: 'string' },
-   { name: 'profile_percent', type: 'int' },
-   { name: 'profile_inittemp_high', type: 'float' },
-   { name: 'profile_inittemp_low', type: 'float' },
-   { name: 'profile_steps', type: 'string' },
+   { name: 'profile_uuid', map: 'metric>profile>uuid' },
+   { name: 'profile_name', map: 'metric>profile>name' },
+   { name: 'profile_state', map: 'metric>profile>state', type: 'string' },
+   { name: 'profile_percent', map: 'metric>profile>percent', type: 'int' },
+   { name: 'profile_inittemp_high', map: 'metric>profile>inittemp>high', type: 'float' },
+   { name: 'profile_inittemp_low', map: 'metric>profile>inittemp>low', type: 'float' },
+   { name: 'profile_steps', map: 'metric>profile>steps', type: 'string' },
    { name: 'stage', map: 'metric>stage', type: 'string' },
    { name: 'beeruuid', map: 'metric>product>uuid' }
   ],
@@ -162,6 +162,7 @@
  });
 
  function updateScreen() {
+	 console.log('mode ' + record.mode + ' profile ' + record.profile_state + ' name ' + record.profile_name);
    $('#room_thb').html(global.room_temp + '&deg;C&nbsp;&nbsp;' + global.room_hum + '% humidity');
    $('#info_system').html(record.unit);
    $('#info_beer').html(record.beercode + ' - ' + record.beername);
@@ -186,126 +187,126 @@
    } else {
     $('#fermenter_powerled').html('<div class="LEDblue_off"></div>Power');
    }
-    if (record.alarm != '0') {
-     $('#fermenter_alarmled').html('<div class="LEDred_on"></div>Alarm');
-    } else {
-     $('#fermenter_alarmled').html('<div class="LEDred_off"></div>Alarm');
-    }
-
-    $('#target_lo').val(record.setpoint_low);
-    $('#target_hi').val(record.setpoint_high);
-    if ((record.mode == 'FRIDGE') || (record.mode == 'BEER')) {
-     $('#target_lo').jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true });
-     $('#target_hi').jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true });
-    } else {
-     $('#target_lo').jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false });
-     $('#target_hi').jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false });
-    }
+   if (record.alarm != '0') {
+    $('#fermenter_alarmled').html('<div class="LEDred_on"></div>Alarm');
+   } else {
+    $('#fermenter_alarmled').html('<div class="LEDred_off"></div>Alarm');
+   }
 
-    $('.f_control_leds').show();
-    if (record.heater_state != '0') {
-     $('#fermenter_led1').html('<div class="LEDgreen_on"></div>Heat');
-    } else {
-     $('#fermenter_led1').html('<div class="LEDgreen_off"></div>Heat');
-    }
-    if (record.cooler_state != '0') {
-     $('#fermenter_led2').html('<div class="LEDgreen_on"></div>Cool');
-    } else {
-     $('#fermenter_led2').html('<div class="LEDgreen_off"></div>Cool');
-    }
-    if (record.fan_state != '0') {
-     $('#fermenter_led3').html('<div class="LEDgreen_on"></div>Fan');
-    } else {
-     $('#fermenter_led3').html('<div class="LEDgreen_off"></div>Fan');
-    }
+   $('#target_lo').val(record.setpoint_low);
+   $('#target_hi').val(record.setpoint_high);
+   if ((record.mode == 'FRIDGE') || (record.mode == 'BEER')) {
+    $('#target_lo').jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true });
+    $('#target_hi').jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true });
+   } else {
+    $('#target_lo').jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false });
+    $('#target_hi').jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false });
+   }
 
-    if (record.mode == 'NONE') {
-     $('.f_control_switches').show();
-    } else {
-     $('.f_control_switches').hide();
-    }
-    if ((record.heater_state != '0') != $('#fermenter_toggle1').jqxSwitchButton('val'))
-     $('#fermenter_toggle1').val(record.heater_state != '0');
-    if ((record.cooler_state != '0') != $('#fermenter_toggle2').jqxSwitchButton('val'))
-     $('#fermenter_toggle2').val(record.cooler_state != '0');
-    if ((record.fan_state != '0') != $('#fermenter_toggle3').jqxSwitchButton('val'))
-     $('#fermenter_toggle3').val(record.fan_state != '0');
-
-    $('#info_profile').html(record.profile_name);
-    if (record.profile_name == '')
-     $('#info_mode').jqxDropDownList('disableItem', 'PROFILE');
-    else
-     $('#info_mode').jqxDropDownList('enableItem', 'PROFILE');
+   $('.f_control_leds').show();
+   if (record.heater_state != '0') {
+    $('#fermenter_led1').html('<div class="LEDgreen_on"></div>Heat');
+   } else {
+    $('#fermenter_led1').html('<div class="LEDgreen_off"></div>Heat');
+   }
+   if (record.cooler_state != '0') {
+    $('#fermenter_led2').html('<div class="LEDgreen_on"></div>Cool');
+   } else {
+    $('#fermenter_led2').html('<div class="LEDgreen_off"></div>Cool');
+   }
+   if (record.fan_state != '0') {
+    $('#fermenter_led3').html('<div class="LEDgreen_on"></div>Fan');
+   } else {
+    $('#fermenter_led3').html('<div class="LEDgreen_off"></div>Fan');
+   }
 
-    if (record.mode == 'PROFILE') {
-     if (record.profile_state == 'OFF') {
-      $('#info_mode').jqxDropDownList({ disabled: false });
-      $('#Profile1').jqxButton({ template: 'success', value: 'Starten' });
-      $('#Profile1').show();
-      $('#Profile2').hide();
-      $('#status_profile').html('');
-     } else if (record.profile_state == 'RUN') {
-      $('#info_mode').jqxDropDownList({ disabled: true });
-      $('#Profile1').jqxButton({ template: 'danger', value: 'Afbreken' });
-      $('#Profile2').jqxButton({ template: 'primary', value: 'Pauze' });
-      $('#Profile1').show();
-      $('#Profile2').show();
-      $('#status_profile').html('Profiel actief, ' + record.profile_percent + '% gereed');
-     } else if (record.profile_state == 'PAUSE') {
-      $('#info_mode').jqxDropDownList({ disabled: true });
-      $('#Profile1').jqxButton({ template: 'danger', value: 'Afbreken' });
-      $('#Profile2').jqxButton({ template: 'success', value: 'Doorgaan' });
-      $('#Profile1').show();
-      $('#Profile2').show();
-      $('#status_profile').html('Profiel pauze, ' + record.profile_percent + '% gereed');
-     } else if (record.profile_state == 'DONE') {
-      $('#info_mode').jqxDropDownList({ disabled: true });
-      $('#Profile1').jqxButton({ template: 'primary', value: 'Profiel Ok' });
-      $('#Profile1').show();
-      $('#Profile2').hide();
-      $('#status_profile').html('Profiel is gereed');
-     }
-    } else {
+   if (record.mode == 'NONE') {
+    $('.f_control_switches').show();
+   } else {
+    $('.f_control_switches').hide();
+   }
+   if ((record.heater_state != '0') != $('#fermenter_toggle1').jqxSwitchButton('val'))
+    $('#fermenter_toggle1').val(record.heater_state != '0');
+   if ((record.cooler_state != '0') != $('#fermenter_toggle2').jqxSwitchButton('val'))
+    $('#fermenter_toggle2').val(record.cooler_state != '0');
+   if ((record.fan_state != '0') != $('#fermenter_toggle3').jqxSwitchButton('val'))
+    $('#fermenter_toggle3').val(record.fan_state != '0');
+
+   $('#info_profile').html(record.profile_name);
+   if (record.profile_name == '')
+    $('#info_mode').jqxDropDownList('disableItem', 'PROFILE');
+   else
+    $('#info_mode').jqxDropDownList('enableItem', 'PROFILE');
+
+   if (record.mode == 'PROFILE') {
+    if (record.profile_state == 'OFF') {
      $('#info_mode').jqxDropDownList({ disabled: false });
-     $('#Profile1').hide();
+     $('#Profile1').jqxButton({ template: 'success', value: 'Starten' });
+     $('#Profile1').show();
      $('#Profile2').hide();
      $('#status_profile').html('');
+    } else if (record.profile_state == 'RUN') {
+     $('#info_mode').jqxDropDownList({ disabled: true });
+     $('#Profile1').jqxButton({ template: 'danger', value: 'Afbreken' });
+     $('#Profile2').jqxButton({ template: 'primary', value: 'Pauze' });
+     $('#Profile1').show();
+     $('#Profile2').show();
+     $('#status_profile').html('Profiel actief, ' + record.profile_percent + '% gereed');
+    } else if (record.profile_state == 'PAUSE') {
+     $('#info_mode').jqxDropDownList({ disabled: true });
+     $('#Profile1').jqxButton({ template: 'danger', value: 'Afbreken' });
+     $('#Profile2').jqxButton({ template: 'success', value: 'Doorgaan' });
+     $('#Profile1').show();
+     $('#Profile2').show();
+     $('#status_profile').html('Profiel pauze, ' + record.profile_percent + '% gereed');
+    } else if (record.profile_state == 'DONE') {
+     $('#info_mode').jqxDropDownList({ disabled: true });
+     $('#Profile1').jqxButton({ template: 'primary', value: 'Profiel Ok' });
+     $('#Profile1').show();
+     $('#Profile2').hide();
+     $('#status_profile').html('Profiel is gereed');
     }
+   } else {
+    $('#info_mode').jqxDropDownList({ disabled: false });
+    $('#Profile1').hide();
+    $('#Profile2').hide();
+    $('#status_profile').html('');
+   }
 
-    var yl = record.yeast_lo;
-    var yh = record.yeast_hi;
-    var range = { ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
+   var yl = record.yeast_lo;
+   var yh = record.yeast_hi;
+   var range = { ranges: [{ startValue: 0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
                       { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
                       { startValue: yh, endValue: 45, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }]};
-    $('#gaugeContainer_air').jqxGauge(range);
-    $('#gaugeContainer_beer').jqxGauge(range);
+   $('#gaugeContainer_air').jqxGauge(range);
+   $('#gaugeContainer_beer').jqxGauge(range);
 
-    if (record.air_temperature !== undefined) {
-     $('#gaugeContainer_air').jqxGauge({ caption: { value: 'Air: ' + record.air_temperature.toFixed(3) }});
-     $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature });
-    }
-    if (record.air_state == 'OK') {
-     $('#gaugeContainer_air').jqxGauge({ disabled: false });
-    } else {
-     $('#gaugeContainer_air').jqxGauge({ disabled: true });
-    }
-    if (record.beer_temperature !== undefined) {
-     $('#gaugeContainer_beer').jqxGauge({ caption: { value: 'Beer: ' + record.beer_temperature.toFixed(3) }});
-     $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature });
-    }
-    if (record.beer_state == 'OK') {
-     $('#gaugeContainer_beer').jqxGauge({ disabled: false });
-    } else {
-     $('#gaugeContainer_beer').jqxGauge({ disabled: true });
-    }
-    if (record.chiller_temperature !== undefined) {
-     $('#gaugeContainer_chiller').jqxGauge({ value: record.chiller_temperature });
-    }
-    if (record.chiller_state == 'OK') {
-     $('#gaugeContainer_chiller').jqxGauge({ disabled: false });
-    } else {
-     $('#gaugeContainer_chiller').jqxGauge({ disabled: true });
-    }
+   if (record.air_temperature !== undefined) {
+    $('#gaugeContainer_air').jqxGauge({ caption: { value: 'Air: ' + record.air_temperature.toFixed(3) }});
+    $('#gaugeContainer_air').jqxGauge({ value: record.air_temperature });
+   }
+   if (record.air_state == 'OK') {
+    $('#gaugeContainer_air').jqxGauge({ disabled: false });
+   } else {
+    $('#gaugeContainer_air').jqxGauge({ disabled: true });
+   }
+   if (record.beer_temperature !== undefined) {
+    $('#gaugeContainer_beer').jqxGauge({ caption: { value: 'Beer: ' + record.beer_temperature.toFixed(3) }});
+    $('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature });
+   }
+   if (record.beer_state == 'OK') {
+    $('#gaugeContainer_beer').jqxGauge({ disabled: false });
+   } else {
+    $('#gaugeContainer_beer').jqxGauge({ disabled: true });
+   }
+   if (record.chiller_temperature !== undefined) {
+    $('#gaugeContainer_chiller').jqxGauge({ value: record.chiller_temperature });
+   }
+   if (record.chiller_state == 'OK') {
+    $('#gaugeContainer_chiller').jqxGauge({ disabled: false });
+   } else {
+    $('#gaugeContainer_chiller').jqxGauge({ disabled: true });
+   }
  }
 
  $('#gaugeContainer_air').jqxGauge(gaugeoptions);
@@ -331,7 +332,7 @@
  $('#Profile1').hide(); // Hide these until they are needed.
  $('#Profile2').hide();
 
- // Get the data immediatly and then at regular intervals to refresh.
+ // Get the data immediatly and then via websockets to refresh.
  dataAdapter.dataBind();
  globalData.dataBind();
 
@@ -438,15 +439,27 @@
   var msg = evt.data;
   var obj = JSON.parse(msg);
 
-  console.log('ws got ' + msg);
+//  console.log('ws got ' + msg);
 
   if (obj.ping == 1) {
-   console.log('ws got ping');
+//   console.log('ws got ping');
    websocket.send('{"pong":1}');
   }
 
+  if (obj.type == 'global') {
+   console.log('ws got global ' + msg);
+   global.name = obj.name;
+   global.node = obj.node;
+   global.os = obj.os;
+   global.os_version = obj.os_version;
+   global.FW = obj.FW;
+   global.room_temp = obj.THB.temperature;
+   global.room_hum = obj.THB.humidity;
+   updateScreen();
+  }
+
   if (obj.type == 'fermenter' && obj.unit == record.unit) {
-   console.log('ws got this device ' + msg);
+//   console.log('ws got this device ' + msg);
    record.beeruuid = obj.metric.product.uuid;
    record.beercode = obj.metric.product.code;
    record.beername = obj.metric.product.name;
@@ -475,15 +488,15 @@
    record.alarm = obj.metric.alarm;
    record.setpoint_low = obj.metric.setpoint.low;
    record.setpoint_high = obj.metric.setpoint.high;
-   if (obj.profile) {
-     record.profile_uuid = obj.profile_uuid;
-     record.profile_name = obj.profile_name;
-     record.profile_state = obj.profile_state;
-     record.profile_percent = obj.profile_percent;
-     record.profile_inittemp_high = obj.profile_inittemp_high;
-     record.profile_inittemp_low = obj.profile_inittemp_low;
+   if (obj.metric.profile) {
+     record.profile_uuid = obj.metric.profile.uuid;
+     record.profile_name = obj.metric.profile.name;
+     record.profile_state = obj.metric.profile.state;
+     record.profile_percent = obj.metric.profile.percent;
+     record.profile_inittemp_high = obj.metric.profile.inittemp.high;
+     record.profile_inittemp_low = obj.metric.profile.inittemp.low;
    } else {
-     record.profile_uuid = '';
+     record.profile_uuid = 'Haha';
      record.profile_name = '';
      record.profile_state = '';
      record.profile_percent = 0;

mercurial