SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.

Wed, 10 Jun 2020 09:43:51 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 10 Jun 2020 09:43:51 +0200
changeset 87
47253f294a9f
parent 86
8d0287a1a9e1
child 88
7f02dbee58d0

SDK settings to reduce bin size. Some log messages to debug level. Added KWH usage registration. Added equipment power usage for HLT and MLT. Equipment database upgraded to version 2, expandable. Fixed some screen errors during temperature mash steps.

README.md file | annotate | diff | comparison | revisions
main/automation.c file | annotate | diff | comparison | revisions
main/brewboard.c file | annotate | diff | comparison | revisions
main/buttons.c file | annotate | diff | comparison | revisions
main/buttons.h file | annotate | diff | comparison | revisions
main/config.c file | annotate | diff | comparison | revisions
main/config.h file | annotate | diff | comparison | revisions
main/files.c file | annotate | diff | comparison | revisions
main/setup.c file | annotate | diff | comparison | revisions
main/task_driver.c file | annotate | diff | comparison | revisions
main/task_http.c file | annotate | diff | comparison | revisions
main/task_sdcard.c file | annotate | diff | comparison | revisions
main/task_wifi.c file | annotate | diff | comparison | revisions
main/updates.c file | annotate | diff | comparison | revisions
sdkconfig file | annotate | diff | comparison | revisions
--- a/README.md	Sun Jun 07 22:30:07 2020 +0200
+++ b/README.md	Wed Jun 10 09:43:51 2020 +0200
@@ -89,3 +89,38 @@
       - Nosleep js code toevoegen.
       - Bug: import 2 x hop met dezelfde naam met verschillende tijden krijgen 1 tijd na import.
 
+Voor kleinere image, van 10000272 -> 914944 de volgende settings:
+
+diff -r 8d0287a1a9e1 sdkconfig
+--- a/sdkconfig	Sun Jun 07 22:30:07 2020 +0200
++++ b/sdkconfig	Mon Jun 08 22:13:50 2020 +0200
+@@ -85,8 +85,8 @@
+ CONFIG_SSR_HLT_GPIO=33
+ CONFIG_SSR_PUMP_GPIO=12
+ CONFIG_BUZZER_GPIO=25
+-CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
+-# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set
++# CONFIG_COMPILER_OPTIMIZATION_DEFAULT is not set
++CONFIG_COMPILER_OPTIMIZATION_SIZE=y
+ # CONFIG_COMPILER_OPTIMIZATION_PERF is not set
+ # CONFIG_COMPILER_OPTIMIZATION_NONE is not set
+ CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
+@@ -340,7 +340,6 @@
+ # CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
+ # CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
+ # CONFIG_FREERTOS_DEBUG_INTERNALS is not set
+-CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
+ CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
+ # CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
+ # CONFIG_HEAP_POISONING_DISABLED is not set
+@@ -583,8 +582,8 @@
+ # CONFIG_MONITOR_BAUD_OTHER is not set
+ CONFIG_MONITOR_BAUD_OTHER_VAL=115200
+ CONFIG_MONITOR_BAUD=115200
+-CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y
+-# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set
++# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set
++CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=y
+ CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
+ # CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set
+ # CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set
--- a/main/automation.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/automation.c	Wed Jun 10 09:43:51 2020 +0200
@@ -51,6 +51,7 @@
 extern time_t			now;				///< Current time
 extern struct tm		timeinfo;			///< Current time structure
 
+
 #ifdef CONFIG_TEMP_SENSORS_SIMULATOR
 extern float                    Fake_MLT;
 extern float                    Fake_HLT;
@@ -118,7 +119,7 @@
 		    LastMashStep = recipe.Mashsteps - 2;
 		else
 		    LastMashStep = 0;
-                log_msg(TAG, "Last mash step %d", LastMashStep);
+                ESP_LOGD(TAG, "Last mash step %d", LastMashStep);
 
                 // Check for a crashed session.
                 if (runtime.AutoModeStarted) {
@@ -182,6 +183,8 @@
 		runtime.PumpCooling = false;
 		runtime.MashStep = 0;
 		runtime.MaltAdded = false;
+		runtime.MLT_usage = 0;
+		runtime.HLT_usage = 0;
 		write_runtime();
                 power_MLT = power_HLT = counts = 0;
 		log_clean();
@@ -380,6 +383,9 @@
                     driver_state->pump_run = 0;
                     xSemaphoreGive(xSemaphoreDriver);
                 }
+		double mwu = (runtime.MLT_usage / 1000.0 / 60.0 / 60.0) * equipment.MLT_watt / 1000.0;
+		double hwu = (runtime.HLT_usage / 1000.0 / 60.0 / 60.0) * equipment.HLT_watt / 1000.0;
+		log_msg(TAG, "MLT usage %.3f KWU, HLT usage %.3f KWU, total %.3f KWU", mwu, hwu, mwu + hwu);
                 _fg = TFT_YELLOW;
                 TFT_setFont(DEJAVU24_FONT, NULL);
                 if (Main_Screen == MAIN_AUTO_DONE) {
@@ -576,7 +582,7 @@
 		} else {
 		    runtime.UseHLT = _UseHLT = false;
 		}
-		log_msg(TAG, "Use HLT %s", (_UseHLT)?"true":"false");
+		ESP_LOGD(TAG, "Use HLT %s", (_UseHLT)?"true":"false");
                 updateRuntime = true;
                 if (_UseHLT) {
                     /*
@@ -613,7 +619,7 @@
                     if (driver_state->hlt_pv >= driver_state->hlt_sp) {
                         Main_Screen = MAIN_AUTO_MASH;
                         driver_state->hlt_sp = recipe.SpargeTemp;       // Set final setpoint
-			log_msg(TAG, "HLT preheat done");
+			ESP_LOGD(TAG, "HLT preheat done");
                     }
                     xSemaphoreGive(xSemaphoreDriver);
                 }
@@ -801,14 +807,13 @@
 			float part = ((stageTime * 60.0) - TimeLeft) / (stageTime * 60.0);
 			newTemp = ((int)(((part * (recipe.MashStep[runtime.MashStep].End_temp - recipe.MashStep[runtime.MashStep].Step_temp)) +
 				  recipe.MashStep[runtime.MashStep].Step_temp) * 16)) / 16.0;
-			//newTemp = ((int)(newTemp * 16)) / 16.0;
 			if (newTemp != stageTemp) {
 			    stageTemp = newTemp;
 			    if (xSemaphoreTake(xSemaphoreDriver, 10) == pdTRUE) {
                         	driver_state->mlt_sp = stageTemp;
                         	xSemaphoreGive(xSemaphoreDriver);
                     	    }
-			ESP_LOGI(TAG, "Curent %7.4f new %7.4f part %7.4f", stageTemp, newTemp, part);
+			//ESP_LOGI(TAG, "Current %7.4f new %7.4f part %7.4f", stageTemp, newTemp, part);
 			}
 		    }
 		    oldTimeLeft = TimeLeft;
@@ -816,6 +821,10 @@
                     if (TimeLeft == 0) {
 			runtime.StageTimeLeft = 0;
 			updateRuntime = true;
+			TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
+			snprintf(msg, 63, "{\"main\":\"%d\",\"sub\":\"%d\",\"timer\":\"\"}", Main_Screen, Sub_Screen);
+                        ws_server_send_text_clients((char *)"/ws", msg, strlen(msg));
+
                         if (runtime.MashStep == 0 && ! runtime.MaltAdded && config.AskAdd) {
                             /*
                              * Add Mash prompt.
@@ -826,7 +835,6 @@
                         	xSemaphoreGive(xSemaphoreDriver);
                     	    }
 			    log_annotation(ANNOTATION_EVENT, (char *)"Mout storten");
-			    TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
                             Buttons_Clear();
                             Buttons_Add(  5,120, 60, 40, (char *)"Halt", 0);
 			    Buttons[0].dark = true;
@@ -848,7 +856,6 @@
                              * Iodone test prompt.
                              */
 			    log_annotation(ANNOTATION_EVENT, (char *)"Jodium test");
-                            TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
                             Buttons_Clear();
                             Buttons_Add(  5,120, 60, 40, (char *)"Halt", 0);
 			    Buttons[0].dark = true;
@@ -872,7 +879,6 @@
                              * Mash remove prompt.
                              */
 			    log_annotation(ANNOTATION_EVENT, (char *)"Mout verwijderen");
-                            TFT_fillRect(0, 120, 320, 50, TFT_BLACK);
                             Buttons_Clear();
                             Buttons_Add(  5,120, 60, 40, (char *)"Halt", 0);
 			    Buttons[0].dark = true;
@@ -1347,7 +1353,7 @@
 			    driver_state->pump_run = (driver_state->mlt_pv < equipment.PumpMaxTemp) ? 1 : 0;
 			    xSemaphoreGive(xSemaphoreDriver);
 			}
-			log_annotation(ANNOTATION_STAGE, (char *)"Whirlpool");
+			log_annotation(ANNOTATION_EVENT, (char *)"Whirlpool");
 
 			TimerSet(TimeWhirlPool * 60);
 			runtime.StageTimeLeft = TimeWhirlPool;
--- a/main/brewboard.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/brewboard.c	Wed Jun 10 09:43:51 2020 +0200
@@ -83,16 +83,10 @@
     TFT_print((char *)"Ok\r\n", LASTX, LASTY);
 
     // Just to debug, list the /spiffs filesystem.
-#if 1
+#if 0
     DIR *dir = opendir("/spiffs");
     struct dirent* de = readdir(dir);
     while (de) {
-	if (de->d_type == DT_REG) {
-	    printf("F ");
-	}
-	if (de->d_type == DT_DIR) {
-	    printf("D ");
-	}
 	printf("%s\n", de->d_name);
 	de = readdir(dir);
     }
--- a/main/buttons.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/buttons.c	Wed Jun 10 09:43:51 2020 +0200
@@ -577,12 +577,19 @@
  *  Data show and edit functions.
  */
 
-void ShowText(uint16_t x, uint16_t y, char *label, char *txt)
+void ShowLabel(uint16_t x, uint16_t y, char *label)
 {
     _fg = TFT_LIGHTGREY;
     TFT_print(label, x, y);
     _fg = TFT_YELLOW;
     TFT_print((char *)" ", LASTX, LASTY);
+}
+
+
+
+void ShowText(uint16_t x, uint16_t y, char *label, char *txt)
+{
+    ShowLabel(x, y, label);
     TFT_print(txt, LASTX, LASTY);
 }
 
@@ -592,10 +599,8 @@
 {
     char        tmp[32];
 
-    _fg = TFT_LIGHTGREY;
-    TFT_print(label, x, y);
-    _fg = TFT_YELLOW;
-   sprintf(tmp, " %d", val);
+    ShowLabel(x, y, label);
+   sprintf(tmp, "%d", val);
    TFT_print(tmp, LASTX, LASTY);
    if (suffix) {
         _fg = TFT_LIGHTGREY;
@@ -607,22 +612,18 @@
 
 void ShowBool(uint16_t x, uint16_t y, char *label, bool val)
 {
-    _fg = TFT_LIGHTGREY;
-    TFT_print(label, x, y);
-    _fg = TFT_YELLOW;
+    ShowLabel(x, y, label);
     if (val)
-        TFT_print((char *)" J", LASTX, LASTY);
+        TFT_print((char *)"J", LASTX, LASTY);
     else
-        TFT_print((char *)" N", LASTX, LASTY);
+        TFT_print((char *)"N", LASTX, LASTY);
 }
 
 
 
 void ShowSSR2(uint16_t x, uint16_t y, int val)
 {
-    _fg = TFT_LIGHTGREY;
-    TFT_print((char *)"SSR2 ", x, y);
-    _fg = TFT_YELLOW;
+    ShowLabel(x, y, (char *)"SSR2");
     TFT_clearStringRect(TFT_X, TFT_Y, (char *)"HLT en MLT");
     TFT_print((char *)SSR2Types[val], LASTX, LASTY);
 }
@@ -633,10 +634,8 @@
 {
     char        tmp[32];
 
-    _fg = TFT_LIGHTGREY;
-    TFT_print(label, x, y);
-    _fg = TFT_YELLOW;
-    sprintf(tmp, " %.*f", decimals, val);
+    ShowLabel(x, y, label);
+    sprintf(tmp, "%.*f", decimals, val);
     TFT_print(tmp, LASTX, LASTY);
     if (suffix) {
         _fg = TFT_LIGHTGREY;
@@ -650,10 +649,8 @@
 {
     char        tmp[32];
 
-    _fg = TFT_LIGHTGREY;
-    TFT_print(label, x, y);
-    _fg = TFT_YELLOW;
-    sprintf(tmp, " %.*f", decimals, val);
+    ShowLabel(x, y, label);
+    sprintf(tmp, "%.*f", decimals, val);
     TFT_print(tmp, LASTX, LASTY);
     if (suffix) {
 	_fg = TFT_LIGHTGREY;
@@ -663,14 +660,21 @@
 
 
 
+void EditerTop(char *label)
+{
+    _bg = TFT_BLACK;
+    TFT_fillScreen(_bg);
+    TFT_resetclipwin();
+    TopMessage(label);
+}
+
+
+
 void Editer(char *label, char *txt, char *errmsg, int len, int type)
 {
     int		key;
 
-    _bg = TFT_BLACK;
-    TFT_fillScreen(_bg);
-    TFT_resetclipwin();
-    TopMessage((char *)"Wijzigen");
+    EditerTop((char *)"Wijzigen");
     _fg = TFT_LIGHTGREY;
     TFT_setFont(DEFAULT_FONT, NULL);
     TFT_print(label, 2, 28);
@@ -892,10 +896,7 @@
     bool	loop = true, value = *val;
     int		curpos;
 
-    _bg = TFT_BLACK;
-    TFT_fillScreen(_bg);
-    TFT_resetclipwin();
-    TopMessage((char *)"Wijzigen");
+    EditerTop((char *)"Wijzigen");
     _fg = TFT_LIGHTGREY;
     TFT_setFont(DEFAULT_FONT, NULL);
     TFT_print(label, 2, 28);
@@ -939,10 +940,7 @@
     int		value = *val;
     int		key;
 
-    _bg = TFT_BLACK;
-    TFT_fillScreen(_bg);
-    TFT_resetclipwin();
-    TopMessage((char *)"Wijzigen");
+    EditerTop((char *)"Wijzigen");
 
     Buttons_Clear();
     Buttons_Add( 20,  60,120, 40, (char *)SSR2Types[0], 0);
@@ -978,10 +976,7 @@
     int		value = (int)*val;
     int         key;
 
-    _bg = TFT_BLACK;
-    TFT_fillScreen(_bg);
-    TFT_resetclipwin();
-    TopMessage((char *)"Wijzigen");
+    EditerTop((char *)"Wijzigen");
 
     Buttons_Clear();
     Buttons_Add( 80,  40,160, 40, (char *)mashTypes[0], 0);
@@ -1016,8 +1011,7 @@
     int		rc = false;
     bool	loop = true;
 
-    TFT_fillScreen(TFT_BLACK);
-    TopMessage(top);
+    EditerTop(top);
     Buttons_Clear();
     Buttons_Add( 40, 100, 80, 40, ack, 0);
     Buttons_Add(200, 100, 80, 40, nak, 1);
--- a/main/buttons.h	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/buttons.h	Wed Jun 10 09:43:51 2020 +0200
@@ -142,7 +142,13 @@
  * @param val The float data value to show.
  * @param decimals The number of decimals to show.
  */
- void ShowDouble(uint16_t x, uint16_t y, char *label, char *suffix, double val, int decimals);
+void ShowDouble(uint16_t x, uint16_t y, char *label, char *suffix, double val, int decimals);
+
+/**
+ * @brief A complete new screen is used to show only the top message.
+ * @param label The top field name text.
+ */
+void EditerTop(char *label);
 
 /**
  * @brief Edit data field. A complete new screen is used.
--- a/main/config.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/config.c	Wed Jun 10 09:43:51 2020 +0200
@@ -21,8 +21,6 @@
     fclose(f);
     if (bytes != sizeof(config)) {
 	ESP_LOGE(TAG, "/spiffs/etc/config.conf written %d/%d bytes", bytes, sizeof(config));
-    } else {
-	ESP_LOGD(TAG, "/spiffs/etc/config.conf written %d bytes", bytes);
     }
 }
 
@@ -60,25 +58,16 @@
 	write_config();
     } else {
 	dst = (uint8_t*)&config;
-	size_t bytes = fread(dst, 1, sizeof(config), f);
+	fread(dst, 1, sizeof(config), f);
 	fclose(f);
-	ESP_LOGD(TAG, "/spiffs/etc/config.conf read %d bytes", bytes);
-	if (config.AskIodine && ! config.IodineTime) {
-	    config.IodineTime = 30;
-	    write_config();
-	}
-	if (strlen(config.uuid) !=36) {
-	    esp_efuse_mac_get_default(mac_addr);
-	    sprintf(config.uuid, "c0ffeeee-dead-beef-cafe-%02x%02x%02x%02x%02x%02x", 
-			    mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
-	    write_config();
-	}
     }
 }
 
 
 
-void append_equipment() {
+void append_equipment()
+{
+return;
     uint8_t *dst = (uint8_t *)&equipment;
     FILE *f = fopen("/spiffs/etc/equipments.conf", "a");
 	      
@@ -87,21 +76,35 @@
 	return;
     }
 	        
-    size_t bytes = fwrite(dst, 1, sizeof(equipment), f);
+    size_t bytes = fwrite(dst, 1, equipment_hdr.recsize, f);
     fclose(f);
     ESP_LOGI(TAG, "/spiffs/etc/equipments.conf appended %d bytes", bytes);
 }
 
 
 
-void read_equipment(int RecNo) {
-    uint8_t *dst;
-    FILE  *f = fopen("/spiffs/etc/equipments.conf", "r");
-	      
+void read_equipment(int RecNo)
+{
+    size_t	bytes;
+    uint8_t	*dst;
+    FILE	*f = fopen("/spiffs/etc/equipments.conf", "r");
+
     if (f == NULL) {
 	// No configuration yet, create it.
-	equipment.Version = 1;
-	equipment.Record = 1;
+	dst = (uint8_t*)&equipment_hdr;
+        memset(dst, 0, sizeof(equipment_hdr));
+        equipment_hdr.version = EQUIPMENT_VERSION;
+        equipment_hdr.hdrsize = sizeof(equipment_hdr);
+        equipment_hdr.recsize = sizeof(equipment);
+        f = fopen("/spiffs/etc/equipments.conf", "w");
+        bytes = fwrite(dst, 1, sizeof(equipment_hdr), f);
+        if (bytes != sizeof(equipment_hdr)) {
+            ESP_LOGE(TAG, "/spiffs/etc/equipment.conf write header, %d/%d bytes", bytes, sizeof(equipment_hdr));
+        }
+	dst = (uint8_t*)&equipment;
+        memset(dst, 0, sizeof(equipment));
+	equipment.MLT_watt = 2000;
+	equipment.HLT_watt = 2000;
 	sprintf(equipment.Name, "default");
 	equipment.BoilPower = 80;
 	equipment.MashPower = 100;
@@ -119,21 +122,59 @@
 	equipment.PID_kI = 2.0;
 	equipment.PID_kD = 1.5;
 	equipment.SampleTime = 3000;
-	append_equipment();
+	bytes = fwrite(dst, 1, sizeof(equipment), f);
+	fclose(f);
     } else {
+	/*
+	 * Try to read the new header
+	 */
+	dst = (uint8_t*)&equipment_hdr;
+        fseek(f, 0, SEEK_SET);
+        bytes = fread(dst, 1, sizeof(equipment_hdr), f);
+        if (bytes != sizeof(equipment_hdr)) {
+            ESP_LOGE(TAG, "/spiffs/etc/equipments.conf read header, %d/%d bytes", bytes, sizeof(equipment_hdr));
+            fclose(f);
+            return;
+        }
+#if 0
+	if (equipment_hdr.version < EQUIPMENT_VERSION) {
+	    FILE	*nf = fopen("/spiffs/etc/equipments.new", "w");
+
+            ESP_LOGW(TAG, "/spiffs/etc/equipments.conf version %d, new %d", equipment_hdr.version, EQUIPMENT_VERSION);
+	    dst = (uint8_t*)&equipment_hdr;
+            memset(dst, 0, sizeof(equipment_hdr));
+            equipment_hdr.version = EQUIPMENT_VERSION;
+            equipment_hdr.hdrsize = sizeof(equipment_hdr);
+            equipment_hdr.recsize = sizeof(equipment);
+            bytes = fwrite(dst, 1, sizeof(equipment_hdr), nf);
+
+            fseek(f, 0, SEEK_SET);
+            dst = (uint8_t*)&recipe;
+            while ((bytes = fread(dst, 1, equipment_hdr.recsize, f))) {
+                // Upgrade data here
+                bytes = fwrite(dst, 1, sizeof(equipment), nf);
+                if (bytes != sizeof(equipment)) {
+                    ESP_LOGE(TAG, "/spiffs/etc/equipments.new write data, %d/%d bytes", bytes, sizeof(equipment));
+                }
+            }
+            // Update the header with new sizes
+            fclose(nf);
+            fclose(f);
+            rename("/spiffs/etc/equipments.conf", "/spiffs/etc/equipments.old");
+            rename("/spiffs/etc/equipments.new", "/spiffs/etc/equipments.conf");
+            unlink("/spiffs/etc/equipments.old");
+	    f = fopen("/spiffs/etc/equipments.conf", "r");
+	}
+#endif
 	dst = (uint8_t*)&equipment;
-	while (1) {
-	    size_t bytes = fread(dst, 1, sizeof(equipment), f);
-	    if (bytes && equipment.Record == RecNo) {
-		fclose(f);
-		ESP_LOGD(TAG, "/spiffs/etc/equipments.conf read %d bytes, record %d: %s", bytes, RecNo, equipment.Name);
-		return;
-	    }
-	    if (bytes == 0)
-		break;
+	fseek(f, (RecNo - 1) * equipment_hdr.recsize + equipment_hdr.hdrsize, SEEK_SET);
+	bytes = fread(dst, 1, equipment_hdr.recsize, f);
+	fclose(f);
+	if (bytes != equipment_hdr.recsize) {
+	    ESP_LOGE(TAG, "/spiffs/etc/equipments.conf read record %d, %d/%d bytes", RecNo, bytes, equipment_hdr.recsize);
+	} else {
+	    ESP_LOGD(TAG, "/spiffs/etc/equipments.conf read %d bytes, record %d: %s", bytes, RecNo, equipment.Name);
 	}
-	fclose(f);
-	ESP_LOGE(TAG, "/spiffs/etc/equipments.conf read error, record %d not found", RecNo);
     }
 }
 
@@ -149,17 +190,21 @@
 	ESP_LOGE(TAG, "write /spiffs/etc/equipments.conf failed");
 	return;
     }
-    fseek(f, (RecNo - 1) * sizeof(equipment), SEEK_SET);
-    size_t bytes = fwrite(dst, 1, sizeof(equipment), f);
+    fseek(f, (RecNo - 1) * equipment_hdr.recsize + equipment_hdr.hdrsize, SEEK_SET);
+    size_t bytes = fwrite(dst, 1, equipment_hdr.recsize, f);
     fclose(f);
-    ESP_LOGI(TAG, "/spiffs/etc/equipments.conf update record %d, %d bytes", RecNo, bytes);
+    if (bytes != equipment_hdr.recsize)
+	ESP_LOGE(TAG, "/spiffs/etc/equipments.conf write record %d, %d/%d bytes", RecNo, bytes, equipment_hdr.recsize);
+    else
+	ESP_LOGI(TAG, "/spiffs/etc/equipments.conf update record %d, %d bytes", RecNo, bytes);
 }
 
 
 
 void delete_equipment(int RecNo)
 {
-    int		RecNow = 1;
+return;
+    int		RecRead = 1, RecWrite = 1;
     FILE	*n, *o;
     uint8_t	*dst;
     size_t	bytes;
@@ -176,26 +221,27 @@
 	return;
     }
 
+    dst = (uint8_t*)&equipment_hdr;
+    fread(dst, 1, equipment_hdr.hdrsize, o);
+    fwrite(dst, 1, equipment_hdr.hdrsize, n);
+
     dst = (uint8_t*)&equipment;
     while (true) {
-	bytes = fread(dst, 1, sizeof(equipment), o);
+	bytes = fread(dst, 1, equipment_hdr.recsize, o);
 	if (bytes == 0)
 	    break;
 
-	if (equipment.Record == RecNo) {
-	    // Record to delete, don't copy
-	    printf("Ditch %d\n", RecNo);
-	} else {
-	    if ((config.EquipmentRec == equipment.Record) && (config.EquipmentRec != RecNow)) {
+	if (RecRead != RecNo) {
+	    // Record to copy
+	    if ((config.EquipmentRec == RecRead) && (config.EquipmentRec != RecWrite)) {
 		// We need to change the default record.
-		config.EquipmentRec = RecNow;
+		config.EquipmentRec = RecWrite;
 		write_config();
 	    }
-	    printf("Copy %d to %d\n", equipment.Record, RecNow);
-	    equipment.Record = RecNow;
-	    fwrite(dst, 1, sizeof(equipment), n);
-	    RecNow++;
+	    fwrite(dst, 1, equipment_hdr.recsize, n);
+	    RecWrite++;
 	}
+	RecRead++;
     }
     fclose(o);
     fclose(n);
@@ -203,6 +249,7 @@
     rename("/spiffs/etc/equipments.conf", "/spiffs/etc/equipments.old");
     rename("/spiffs/etc/equipments.new", "/spiffs/etc/equipments.conf");
     unlink("/spiffs/etc/equipments.old");
+    ESP_LOGI(TAG, "Deleted equipment %d", RecNo);
 }
 
 
@@ -340,8 +387,6 @@
     fclose(f);
     if (bytes != sizeof(runtime)) {
 	ESP_LOGE(TAG, "/spiffs/etc/runtime.conf written %d/%d bytes", bytes, sizeof(runtime));
-    } else {
-	ESP_LOGD(TAG, "/spiffs/etc/runtime.conf written %d bytes", bytes);
     }
 }
 
@@ -366,6 +411,8 @@
 	runtime.PumpCooling = false;
 	runtime.TimeBrewing = 0;
 	runtime.MashStep = 0;
+	runtime.MLT_usage = 0;
+	runtime.HLT_usage = 0;
 	write_runtime();
     } else {
 	dst = (uint8_t*)&runtime;
@@ -373,8 +420,8 @@
 	fclose(f);
 	if (bytes != sizeof(runtime)) {
 	    ESP_LOGE(TAG, "/spiffs/etc/runtime.conf read %d/%d bytes", bytes, sizeof(runtime));
-	    runtime.MashStep = 0;
-	    runtime.MaltAdded = false;
+	    runtime.MLT_usage = 0;
+	    runtime.HLT_usage = 0;
 	}
 #if 0
 	printf("Auto started     %s\n", runtime.AutoModeStarted ? "yes":"no");
--- a/main/config.h	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/config.h	Wed Jun 10 09:43:51 2020 +0200
@@ -192,13 +192,20 @@
 void read_config(void);
 
 
+#define EQUIPMENT_VERSION	2		///< Equipment file version
 
 /**
  * @brief Equipment configuration. File /spiffs/equipments.conf
  */
+struct hdrEquipment {
+    uint32_t            version;		///< Structure version.
+    uint32_t            hdrsize;		///< Size of this header.
+    uint32_t            recsize;		///< Size of a record.
+} equipment_hdr;
+
 struct strEquipment {
-    int		Version;			///< Record version number for updates.
-    int		Record;				///< Record number.
+    int		MLT_watt;			///< MLT watts.
+    int		HLT_watt;			///< HLT watts.
     char	Name[32];			///< Equipment name.
     int		BoilPower;			///< The power percentage needed to keep the wort boiling.
     int		MashPower;			///< The power percentage needed to heat during mash.
@@ -303,6 +310,8 @@
     uint32_t		TimeBrewing;			///< Time we are brewing.
     uint8_t		MashStep;			///< Current mash step.
     bool		MaltAdded;			///< If malt was added.
+    TickType_t		MLT_usage;			///< MLT usage counter.
+    TickType_t		HLT_usage;			///< HLT usage counter.
 } runtime;						///< Runtime record.
 
 
--- a/main/files.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/files.c	Wed Jun 10 09:43:51 2020 +0200
@@ -24,9 +24,7 @@
     struct dirent	*de;
     struct stat		st;
 
-    _bg = TFT_BLACK;
-    TFT_fillScreen(_bg);
-    TopMessage(path);
+    EditerTop(path);
     _fg = TFT_WHITE;
     TFT_setFont(DEFAULT_FONT, NULL);
 
--- a/main/setup.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/setup.c	Wed Jun 10 09:43:51 2020 +0200
@@ -69,9 +69,10 @@
 	case MAIN_TOOLS_SETUP_EQUIPMENT:
 			TopMessage((char *)"Apparatuur");
 			f = fopen("/spiffs/etc/equipments.conf", "r");
+			fseek(f, equipment_hdr.hdrsize, SEEK_SET);
 			dst = (uint8_t*)&equipment;
 			Records = 0;
-			while ((bytes = fread(dst, 1, sizeof(equipment), f))) {
+			while ((bytes = fread(dst, 1, equipment_hdr.recsize, f))) {
 			    Records++;
 			}
 			fclose(f);
@@ -190,7 +191,9 @@
 			    ShowDouble(2, 140, (char *)"PID P", NULL, equipment.PID_kP, 3);
 			    ShowInteger(161, 140, (char *)"Sample tijd", (char *)"mS", equipment.SampleTime);
 			    ShowDouble(2, 156, (char *)"PID I", NULL, equipment.PID_kI, 3);
+			    ShowInteger(161, 156, (char *)"MLT watt", NULL, equipment.MLT_watt);
 			    ShowDouble(2, 172, (char *)"PID D", NULL, equipment.PID_kD, 3);
+			    ShowInteger(161, 172, (char *)"HLT watt", NULL, equipment.HLT_watt);
 			    Buttons_Clear();
 			    Buttons_Add(  0, 210, 45, 30, (char *)"Ok"  , 0);
 			    Buttons_Add( 46, 210, 45, 30, (char *)"+"   , 1);
@@ -219,8 +222,8 @@
 					break;
 
 			    case 1:	memset(&equipment, 0, sizeof(equipment));
-					equipment.Version = 1;
-					equipment.Record = Records + 1;
+					equipment.MLT_watt = 2000;
+					equipment.HLT_watt = 2000;
 					sprintf(equipment.Name, "new eq %d", Records + 1);
 					equipment.BoilPower = 80;
 					equipment.MashPower = 100;
@@ -242,13 +245,17 @@
 					Records++;
 					CurrentRec = Records;
 					UpdateRec = true;
-					ESP_LOGI(TAG, "New equipment record %d", equipment.Record);
+					ESP_LOGI(TAG, "New equipment record %d", CurrentRec);
 					break;
 
 			    case 2:	if ((CurrentRec != config.EquipmentRec) && (Records > 1)) {
+					    _bg = TFT_BLACK;
+                                             TFT_fillScreen(_bg);
+                                            TFT_resetclipwin();
+                                            TopMessage((char *)"Apparatuur verwijderen");
 					    delete_equipment(CurrentRec);
 					    Records--;
-					    if (CurrentRec > Records)
+					    if (CurrentRec >= Records)
 						CurrentRec = Records;
 					    UpdateRec = true;
 					}
@@ -305,10 +312,12 @@
 			EditInt((char *)"Sample tijd in mS", &equipment.SampleTime, 1000, 20000);
 			// Round to 250 mSec units.
 			equipment.SampleTime = ((int)(equipment.SampleTime / 250)) * 250;
+			EditInt((char *)"MLT watt", &equipment.MLT_watt, 100, 45000);
+			EditInt((char *)"HLT watt", &equipment.HLT_watt, 100, 45000);
 
 			crc2 = crc32_le(0, dst, sizeof(equipment));
 			if ((crc1 != crc2) && Confirm((char *)"Gewijzigd, opslaan?", (char *)"Ja", (char *)"Nee")) {
-			    write_equipment(equipment.Record);
+			    write_equipment(CurrentRec);
 			}
 			Main_Screen = MAIN_TOOLS_SETUP_EQUIPMENT;
 			break;
--- a/main/task_driver.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/task_driver.c	Wed Jun 10 09:43:51 2020 +0200
@@ -34,12 +34,17 @@
 double			HLT_Setpoint = 0;			///< HLT setpoint values
 int			HLT_Output = 0;				///< HLT output value
 int			HLT_Mode = HLT_MODE_NONE;		///< HLT mode flag
+TickType_t		MLT_time, HLT_time;
+
+
+static const char	*MLTTypes[] = { "None", "Bang", "PID", "Off", "Ext" };
+static const char	*HLTTypes[] = { "None", "Bang", "Off", "On" };
 
 static const char       *TAG = "task_driver";
 
-extern SemaphoreHandle_t xSemaphoreDS18B20;
-extern DS18B20_State * ds18b20_state;
-extern unsigned long lastTime;
+extern SemaphoreHandle_t	xSemaphoreDS18B20;
+extern DS18B20_State		*ds18b20_state;
+extern unsigned long		lastTime;
 
 
 /**
@@ -62,9 +67,13 @@
 void MLT(int onoff) {
 
     if (onoff && outEnable) {
+	if (MLT_pin != 1)
+	    MLT_time = xTaskGetTickCount();
 	gpio_set_level(SSR_MLT, 1);
 	MLT_pin = 1;
     } else {
+	if (MLT_pin)
+	    runtime.MLT_usage += xTaskGetTickCount() - MLT_time;
 	gpio_set_level(SSR_MLT, 0);
 	MLT_pin = 0;
     }
@@ -75,9 +84,13 @@
 void HLT(int onoff) {
 
     if (onoff && outEnable) {
+	if (HLT_pin != 1)
+	    HLT_time = xTaskGetTickCount();
 	gpio_set_level(SSR_HLT, 1);
 	HLT_pin = 1;
     } else {
+	if (HLT_pin)
+	    runtime.HLT_usage += xTaskGetTickCount() - HLT_time;
 	gpio_set_level(SSR_HLT, 0);
 	HLT_pin = 0;
     }
@@ -184,11 +197,11 @@
 		    LoadPIDsettings();
 		}
 		MLT_Mode = driver_state->mlt_mode;
-		ESP_LOGI(TAG, "MLT mode set to %d", MLT_Mode);
+		ESP_LOGI(TAG, "MLT mode set to %s", MLTTypes[MLT_Mode]);
 	    }
 	    if (driver_state->hlt_mode != HLT_Mode) {
 		HLT_Mode = driver_state->hlt_mode;
-		ESP_LOGI(TAG, "HLT mode set to %d", HLT_Mode);
+		ESP_LOGI(TAG, "HLT mode set to %s", HLTTypes[HLT_Mode]);
 	    }
 	    outEnable = driver_state->enable;
 	    HLT_Input = driver_state->hlt_pv;
--- a/main/task_http.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/task_http.c	Wed Jun 10 09:43:51 2020 +0200
@@ -307,11 +307,7 @@
 
     switch(type) {
 	case WEBSOCKET_CONNECT:
-			ESP_LOGI(TAG,"Websocket client %i connected!",num);
-			break;
-										            
 	case WEBSOCKET_DISCONNECT_EXTERNAL:
-			ESP_LOGI(TAG,"Websocket client %i sent a disconnect message",num);
 			break;
 
 	case WEBSOCKET_DISCONNECT_INTERNAL:
--- a/main/task_sdcard.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/task_sdcard.c	Wed Jun 10 09:43:51 2020 +0200
@@ -133,11 +133,7 @@
 	    f = fopen(filename, "a");
 	    if (f) {
 		strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
-		fprintf(f, "{\n");
-		fprintf(f, " \"brew\": [{\n");
-		fprintf(f, "  \"Recipe\":\"%s %s\",\n", recipe.Code, recipe.Name);
-		fprintf(f, "  \"Date\":\"%s\",\n", strftime_buf);
-		fprintf(f, "  \"brewdata\":[\n");
+		fprintf(f, "{\"brew\":[{\"Recipe\":\"%s %s\",\"Date\":\"%s\",\"brewdata\":[\n", recipe.Code, recipe.Name, strftime_buf);
 		addcomma = false;
 		fclose(f);
 	    } else {
@@ -522,8 +518,7 @@
 		    // First close the JSON data records
 		    FILE *f = fopen(filename, "a+");
 		    if (f) {
-			fprintf(f, "  ],\n");	// End of brewdata
-			fprintf(f, "  \"annotations\":[\n");
+			fprintf(f, "],\"annotations\":[\n");	// End of brewdata
 			// Insert annotation records
 			sprintf(destname, "/spiffs/log/%s.anno", sdcard_state->logfile);
 			FILE *a = fopen(destname, "r");
@@ -539,9 +534,7 @@
 			    fclose(a);
 			    unlink(destname);
 			}
-			fprintf(f, "  ]\n");	// End of annotations
-			fprintf(f, " }]\n");	// End of brew
-			fprintf(f, "}\n");
+			fprintf(f, "]}]}\n");	// End of annotations and brew
 			fclose(f);
 		    }
 		    sprintf(destname, "/sdcard/w/log/%s.json", sdcard_state->logfile);
--- a/main/task_wifi.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/task_wifi.c	Wed Jun 10 09:43:51 2020 +0200
@@ -134,7 +134,7 @@
 	sz = sizeof(task_wifi_ConfigSTA->sta.password);
 	memcpy(task_wifi_ConfigSTA->sta.password, wifiStation.Password, sz);
 
-	ESP_LOGI(TAG, "FetchStaConfig: last connected to ssid: %s", task_wifi_ConfigSTA->sta.ssid);
+	ESP_LOGD(TAG, "FetchStaConfig: last connected to ssid: %s", task_wifi_ConfigSTA->sta.ssid);
 	return task_wifi_ConfigSTA->sta.ssid[0] != '\0';
     }
 
@@ -266,7 +266,6 @@
                     ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_AP_STACONNECTED");
                 }
 		wifi_event_ap_staconnected_t* staconnected = (wifi_event_ap_staconnected_t*) event_data;
-//		const system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected;
             	ESP_LOGI(TAG, "Event AP connected, mac:" MACSTR ", aid:%d, conns:%d",
                        MAC2STR(staconnected->mac), staconnected->aid, wifi_state->AP_clients);
 		break;
@@ -282,7 +281,6 @@
                     ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_AP_STADISCONNECTED");
                 }
 		wifi_event_ap_stadisconnected_t* stadisconnected = (wifi_event_ap_stadisconnected_t*) event_data;
-//		const system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected;
             	ESP_LOGI(TAG, "Event AP disconnected, mac:" MACSTR ", aid:%d, conns:%d",
                        MAC2STR(stadisconnected->mac), stadisconnected->aid, wifi_state->AP_clients);
 		break;
@@ -349,7 +347,7 @@
                 break;
 
 	case IP_EVENT_AP_STAIPASSIGNED:
-		ESP_LOGI(TAG, "IP_EVENT_AP_STAIPASSIGNED");
+		ESP_LOGD(TAG, "IP_EVENT_AP_STAIPASSIGNED");
 		break;
 
         default:
--- a/main/updates.c	Sun Jun 07 22:30:07 2020 +0200
+++ b/main/updates.c	Wed Jun 10 09:43:51 2020 +0200
@@ -133,7 +133,7 @@
                         http_cleanup(client);
 			goto updateerr;
                     }
-                    ESP_LOGI(TAG, "Continue upgrade application");
+                    ESP_LOGD(TAG, "Continue upgrade application");
 		    TFT_print((char *)"Download new version.\r\n", 0, LASTY);
                 } else {
                     ESP_LOGE(TAG, "Received package is not fit len");
--- a/sdkconfig	Sun Jun 07 22:30:07 2020 +0200
+++ b/sdkconfig	Wed Jun 10 09:43:51 2020 +0200
@@ -77,16 +77,14 @@
 CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
 CONFIG_PARTITION_TABLE_OFFSET=0x8000
 CONFIG_PARTITION_TABLE_MD5=y
-CONFIG_TEMP_SENSORS_ONEWIRE=y
-# CONFIG_TEMP_SENSORS_SIMULATOR is not set
-CONFIG_ONE_WIRE_MLT=27
-CONFIG_ONE_WIRE_HLT=26
+# CONFIG_TEMP_SENSORS_ONEWIRE is not set
+CONFIG_TEMP_SENSORS_SIMULATOR=y
 CONFIG_SSR_MLT_GPIO=32
 CONFIG_SSR_HLT_GPIO=33
 CONFIG_SSR_PUMP_GPIO=12
 CONFIG_BUZZER_GPIO=25
-CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
-# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set
+# CONFIG_COMPILER_OPTIMIZATION_DEFAULT is not set
+CONFIG_COMPILER_OPTIMIZATION_SIZE=y
 # CONFIG_COMPILER_OPTIMIZATION_PERF is not set
 # CONFIG_COMPILER_OPTIMIZATION_NONE is not set
 CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
@@ -340,7 +338,6 @@
 # CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
 # CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
 # CONFIG_FREERTOS_DEBUG_INTERNALS is not set
-CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
 CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
 # CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
 # CONFIG_HEAP_POISONING_DISABLED is not set
@@ -583,8 +580,8 @@
 # CONFIG_MONITOR_BAUD_OTHER is not set
 CONFIG_MONITOR_BAUD_OTHER_VAL=115200
 CONFIG_MONITOR_BAUD=115200
-CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y
-# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set
+# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set
+CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=y
 CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
 # CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set
 # CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set

mercurial