Version 0.3.7. The WiFi task uses the new event handlers. Cooling temperature top is now 45 instead of 30 degreees for pitching Kveik. One extra cosmetic message during OTA update.

Sun, 24 Nov 2019 16:44:00 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 24 Nov 2019 16:44:00 +0100
changeset 70
d6838a268020
parent 69
875df139d229
child 71
7a4446a77d09

Version 0.3.7. The WiFi task uses the new event handlers. Cooling temperature top is now 45 instead of 30 degreees for pitching Kveik. One extra cosmetic message during OTA update.

Makefile file | annotate | diff | comparison | revisions
main/config.h file | annotate | diff | comparison | revisions
main/recipes.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/Makefile	Sun Sep 22 18:32:31 2019 +0200
+++ b/Makefile	Sun Nov 24 16:44:00 2019 +0100
@@ -3,7 +3,7 @@
 # project subdirectory.
 #
 
-PROJECT_VER := "0.3.6"
+PROJECT_VER := "0.3.7"
 PROJECT_NAME := brewboard
 
 include $(IDF_PATH)/make/project.mk
--- a/main/config.h	Sun Sep 22 18:32:31 2019 +0200
+++ b/main/config.h	Sun Nov 24 16:44:00 2019 +0100
@@ -27,7 +27,7 @@
 #include "driver/i2c.h"
 #include "esp_log.h"
 #include "esp_spiffs.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
 #include "esp_wifi.h"
 #include "esp_wifi_types.h"
 #include "esp_system.h"
--- a/main/recipes.c	Sun Sep 22 18:32:31 2019 +0200
+++ b/main/recipes.c	Sun Nov 24 16:44:00 2019 +0100
@@ -776,7 +776,7 @@
 			    recipe.Addition[i].Type = ADDITION_HOP;
 			}
 
-			EditFloat((char *)"Koel temperatuur", &recipe.CoolTemp, 10, 30, 2);
+			EditFloat((char *)"Koel temperatuur", &recipe.CoolTemp, 10, 45, 2);
 			recipe.CoolTemp = ((int)(recipe.CoolTemp * 4)) / 4.0;
 			EditFloat((char *)"Spoelwater temperatuur", &recipe.SpargeTemp, 75, 98, 2);
 			recipe.SpargeTemp = ((int)(recipe.SpargeTemp * 4)) / 4.0;
--- a/main/task_wifi.c	Sun Sep 22 18:32:31 2019 +0200
+++ b/main/task_wifi.c	Sun Nov 24 16:44:00 2019 +0100
@@ -144,51 +144,54 @@
 
 
 
-esp_err_t task_wifi_EventHandler(void *ctx, system_event_t *event)
+static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
 {
-    switch(event->event_id) {
-	case SYSTEM_EVENT_SCAN_DONE:
+    switch(event_id) {
+	case WIFI_EVENT_SCAN_DONE:
 		// Get the results so the memory used is freed.
 		ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_num, accessp_records));
 		_wifi_Scanned = ap_num;
 		_wifi_ScanDone = true;
 		break;
 
-	case SYSTEM_EVENT_STA_START:
+	case WIFI_EVENT_STA_START:
 		// Set the configured hostname for the dhcp client.
 		ESP_ERROR_CHECK(tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, config.hostname));   
 		esp_wifi_connect();
 		break;
 
-	//   SYSTEM_EVENT_STA_STOP		3
-	case SYSTEM_EVENT_STA_CONNECTED: {
-		const system_event_sta_connected_t *connected = &event->event_info.connected;
-            	ESP_LOGI(TAG, "Event STA connected, ssid:%s, ssid_len:%d, bssid:" MACSTR ", channel:%d, authmode:%s",
-                       connected->ssid, connected->ssid_len, MAC2STR(connected->bssid), connected->channel, apsec[connected->authmode]);
+	case WIFI_EVENT_STA_CONNECTED: {
+		system_event_sta_connected_t* event = (wifi_event_sta_connected_t*) event_data;
 		wifi_ap_record_t ap_info;
-		esp_wifi_sta_get_ap_info(&ap_info);
+                esp_wifi_sta_get_ap_info(&ap_info);
+            	ESP_LOGI(TAG, "Event STA connected, ssid:%s, bssid:" MACSTR ", channel:%d, rssi: %d, authmode:%s",
+                       ap_info.ssid, MAC2STR(ap_info.bssid), event->channel, ap_info.rssi, apsec[event->authmode]);
 		if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
 		    wifi_state->STA_connected = true;
 		    wifi_state->STA_rssi = ap_info.rssi;
 		    sprintf(wifi_state->STA_ssid, "%s", ap_info.ssid);
 		    xSemaphoreGive(xSemaphoreWiFi);
-		}
+		} else {
+                    ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_CONNECTED");
+                }
 		xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED);
 		xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED);
 		break;
 	}
-	case SYSTEM_EVENT_STA_DISCONNECTED: {
-		const system_event_sta_disconnected_t *disconnected = &event->event_info.disconnected;
+	case WIFI_EVENT_STA_DISCONNECTED: {
+		wifi_event_sta_disconnected_t* disconnected = (wifi_event_sta_disconnected_t*) event_data;
 		wifi_ap_record_t    ap;
 
             	ESP_LOGW(TAG, "Event STA disconnected, ssid:%s, ssid_len:%d, bssid:" MACSTR ", reason:%d",
                        disconnected->ssid, disconnected->ssid_len, MAC2STR(disconnected->bssid), disconnected->reason);
-		if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) {
+		if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
 		    wifi_state->STA_connected = false;
 		    wifi_state->STA_online = false;
 		    wifi_state->STA_rssi = 0;
 		    xSemaphoreGive(xSemaphoreWiFi);
-		}
+		} else {
+                    ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_STA_DISCONNECTED");
+                }
 		xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_STA_CONNECTED);
 		xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_STA_DISCONNECTED);
 		sntp_stop();
@@ -233,116 +236,122 @@
 		}
 		break;
 	}
-	//   SYSTEM_EVENT_STA_AUTHMODE_CHANGE	6
-	case SYSTEM_EVENT_STA_GOT_IP:
-		xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
-		tcpip_adapter_ip_info_t ip;
-		memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t));
-		if (tcpip_adapter_get_ip_info(ESP_IF_WIFI_STA, &ip) == 0) {
-		    if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) {
-			wifi_state->STA_online = true;
-		    	snprintf(wifi_state->STA_ip, 16, IPSTR, IP2STR(&ip.ip));
-			snprintf(wifi_state->STA_nm, 16, IPSTR, IP2STR(&ip.netmask));
-			snprintf(wifi_state->STA_gw, 16, IPSTR, IP2STR(&ip.gw));
-		    	xSemaphoreGive(xSemaphoreWiFi);
-		    }
-		}
-		/*
-		 * There doesn't seem to be support for configuring NTP via DHCP so
-		 * we need to hardcode the ntp servers. The preffered server can be
-		 * set via the setup screen. It should be on your LAN, else leave it
-		 * empty. And if you are on a different lan someday, there is no extra
-		 * delay because the hostname will not be found. 
-		 */
-		sntp_stop();
-		if (strlen(config.ntp_server))
-		    sntp_setservername(0, config.ntp_server);
-		sntp_setservername(1, (char *)"pool.ntp.org"); // Will get you servers nearby
-                sntp_set_sync_mode(SNTP_SYNC_MODE_IMMED);
-                sntp_set_time_sync_notification_cb(time_sync_notification_cb);
-                sntp_init();
-#if 0
-		if (strlen(config.ntp_server))
-                    ESP_LOGI(TAG, "NTP server %s", sntp_getservername(0));
-		ESP_LOGI(TAG, "NTP server %s", sntp_getservername(1));
-#endif
-		break;
-
-	case SYSTEM_EVENT_STA_LOST_IP:
-		ESP_LOGW(TAG, "Lost IP address");
-		xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
-		if (xSemaphoreTake(xSemaphoreWiFi, 10) == pdTRUE) {
-		    wifi_state->STA_ip[0] = '\0';
-		    wifi_state->STA_nm[0] = '\0';
-		    wifi_state->STA_gw[0] = '\0';
-		    wifi_state->STA_online = false;
-		    xSemaphoreGive(xSemaphoreWiFi);
-		}
-		sntp_stop();
-		break;
-
-	//   SYSTEM_EVENT_STA_WPS_ER_SUCCESS	9
-	//   SYSTEM_EVENT_STA_WPS_ER_FAILED	10
-	//   SYSTEM_EVENT_STA_WPS_ER_TIMEOUT	11
-	//   SYSTEM_EVENT_STA_WPS_ER_PIN	12
-
-    	case SYSTEM_EVENT_AP_START:
+    	case WIFI_EVENT_AP_START:
     		xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_AP_STARTED);
 		if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
 		    wifi_state->AP_active = true;
 		    wifi_state->AP_clients = 0;
 		    xSemaphoreGive(xSemaphoreWiFi);
-		}
+		} else {
+                    ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_AP_START");
+                }
 		break;
 
-	case SYSTEM_EVENT_AP_STOP:
+	case WIFI_EVENT_AP_STOP:
 		xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_AP_STARTED);
 		if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
 		    wifi_state->AP_active = false;
 		    wifi_state->AP_clients = 0;
 		    xSemaphoreGive(xSemaphoreWiFi);
-		}
+		} else {
+                    ESP_LOGE(TAG, "wifi_event_handler() lock error WIFI_EVENT_AP_STOP");
+                }
 		break;
 
-    	case SYSTEM_EVENT_AP_STACONNECTED: {
+    	case WIFI_EVENT_AP_STACONNECTED: {
 		if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
 		    wifi_state->AP_clients++;
 		    xSemaphoreGive(xSemaphoreWiFi);
-		}
-		const system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected;
+		} else {
+                    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;
 	}
-    	case SYSTEM_EVENT_AP_STADISCONNECTED: {
+    	case WIFI_EVENT_AP_STADISCONNECTED: {
 		if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
 		    if (wifi_state->AP_clients > 0)
 		    	wifi_state->AP_clients--;
 		    else
 		    	wifi_state->AP_clients = 0;
 		    xSemaphoreGive(xSemaphoreWiFi);
-		}
-		const system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected;
+		} else {
+                    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;
 	}
-	case SYSTEM_EVENT_AP_STAIPASSIGNED:
-		break;
-
-	//   SYSTEM_EVENT_AP_PROBEREQRECVED	18
-	//   SYSTEM_EVENT_GOT_IP6		19
-	//   SYSTEM_EVENT_ETH_START		20
-	//   SYSTEM_EVENT_ETH_STOP		21
-	//   SYSTEM_EVENT_ETH_CONNECTED		22
-	//   SYSTEM_EVENT_ETH_DISCONNECTED	23
-	//   SYSTEM_EVENT_ETH_GOT_IP		24
-
 	default:
-		printf("Unknown event %d\n", event->event_id);
+		ESP_LOGW(TAG, "Unknown WiFi event %d", event_id);
         	break;
     }
-    return ESP_OK;
+}
+
+
+
+static void got_ip_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
+{
+    switch (event_id) {
+
+        case IP_EVENT_STA_GOT_IP:
+                xEventGroupSetBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
+		ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
+                if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
+                    wifi_state->STA_online = true;
+                    snprintf(wifi_state->STA_ip, 16, "%s", ip4addr_ntoa(&event->ip_info.ip));
+                    snprintf(wifi_state->STA_nm, 16, "%s", ip4addr_ntoa(&event->ip_info.netmask));
+                    snprintf(wifi_state->STA_gw, 16, "%s", ip4addr_ntoa(&event->ip_info.gw));
+                    xSemaphoreGive(xSemaphoreWiFi);
+                } else {
+                    ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_GOT_IP");
+            	}
+
+                /*
+                 * There doesn't seem to be support for configuring NTP via DHCP so
+                 * we need to hardcode the ntp servers. The preffered server can be
+                 * set via the setup screen. It should be on your LAN, else leave it
+                 * empty. And if you are on a different lan someday, there is no extra
+                 * delay because the hostname will not be found. 
+                 */
+                sntp_stop();
+                if (strlen(config.ntp_server))
+                    sntp_setservername(0, config.ntp_server);
+                sntp_setservername(1, (char *)"pool.ntp.org"); // Will get you servers nearby
+                sntp_set_sync_mode(SNTP_SYNC_MODE_IMMED);
+                sntp_set_time_sync_notification_cb(time_sync_notification_cb);
+                sntp_init();
+#if 0
+                if (strlen(config.ntp_server))
+                    ESP_LOGI(TAG, "NTP server %s", sntp_getservername(0));
+                ESP_LOGI(TAG, "NTP server %s", sntp_getservername(1));
+#endif
+                break;
+
+        case SYSTEM_EVENT_STA_LOST_IP:
+                ESP_LOGW(TAG, "Lost IP address");
+                xEventGroupClearBits(xEventGroupWifi, TASK_WIFI_HAS_IP);
+                if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
+                    wifi_state->STA_ip[0] = '\0';
+                    wifi_state->STA_nm[0] = '\0';
+                    wifi_state->STA_gw[0] = '\0';
+                    wifi_state->STA_online = false;
+                    xSemaphoreGive(xSemaphoreWiFi);
+                } else {
+                    ESP_LOGE(TAG, "got_ip_event_handler() lock error IP_EVENT_STA_LOST_IP");
+            	}
+                sntp_stop();
+                break;
+
+        default:
+            ESP_LOGW(TAG, "Unknown IP event %d", event_id);
+            break;
+    }
 }
 
 
@@ -384,7 +393,7 @@
     xEventGroupWifi = xEventGroupCreate();
     /* initialize the tcp stack */
     tcpip_adapter_init();
-    ESP_ERROR_CHECK(esp_event_loop_init(task_wifi_EventHandler, NULL));
+    ESP_ERROR_CHECK(esp_event_loop_create_default());
 
     /*
      * memory allocation of objects used by the task 
@@ -429,11 +438,15 @@
      */
     wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
     ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config));
+
+    ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL) );
+    ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &got_ip_event_handler, NULL) );
+
     ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
     ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
     ESP_ERROR_CHECK(esp_wifi_set_bandwidth(WIFI_IF_AP, config.ap_bandwidth));
 
-    // configure the softAP and start it */
+    /* configure the softAP and start it */
     wifi_config_t ap_config = {
 	.ap = {
 	    .ssid_len = 0,
--- a/main/updates.c	Sun Sep 22 18:32:31 2019 +0200
+++ b/main/updates.c	Sun Nov 24 16:44:00 2019 +0100
@@ -36,9 +36,6 @@
     TFT_setFont(DEJAVU18_FONT, NULL);
     _fg = TFT_CYAN;
     const esp_partition_t       *running = esp_ota_get_running_partition();
-//    snprintf(temp, 63, "Running part.type %d sub %d,\r\nat offset 0x%08x\r\n",
-//		running->type, running->subtype, running->address);
-//    TFT_print(temp, 0, LASTY);
 
     /*
      * Don't use https because it costs more then 100K memory.
@@ -137,6 +134,7 @@
 			goto updateerr;
                     }
                     ESP_LOGI(TAG, "Continue upgrade application");
+		    TFT_print((char *)"Download new version.\r\n", 0, LASTY);
                 } else {
                     ESP_LOGE(TAG, "Received package is not fit len");
                     http_cleanup(client);
--- a/sdkconfig	Sun Sep 22 18:32:31 2019 +0200
+++ b/sdkconfig	Sun Nov 24 16:44:00 2019 +0100
@@ -4,6 +4,7 @@
 #
 CONFIG_IDF_TARGET_ESP32=y
 CONFIG_IDF_TARGET="esp32"
+CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000
 
 #
 # SDK tool configuration
@@ -11,6 +12,11 @@
 CONFIG_SDK_TOOLPREFIX="xtensa-esp32-elf-"
 CONFIG_SDK_PYTHON="python"
 CONFIG_SDK_MAKE_WARN_UNDEFINED_VARIABLES=y
+CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y
+# CONFIG_APP_BUILD_TYPE_ELF_RAM is not set
+CONFIG_APP_BUILD_GENERATE_BINARIES=y
+CONFIG_APP_BUILD_BOOTLOADER=y
+CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y
 CONFIG_APP_COMPILE_TIME_DATE=y
 # CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set
 # CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set
@@ -89,8 +95,10 @@
 CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
 CONFIG_PARTITION_TABLE_OFFSET=0x8000
 CONFIG_PARTITION_TABLE_MD5=y
-CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y
-# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set
+CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
+# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set
+# CONFIG_COMPILER_OPTIMIZATION_PERF is not set
+# CONFIG_COMPILER_OPTIMIZATION_NONE is not set
 CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
 # CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT is not set
 # CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set
@@ -124,6 +132,7 @@
 CONFIG_SPI_MASTER_ISR_IN_IRAM=y
 # CONFIG_SPI_SLAVE_IN_IRAM is not set
 CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
+# CONFIG_UART_ISR_IN_IRAM is not set
 # CONFIG_EFUSE_CUSTOM_TABLE is not set
 # CONFIG_EFUSE_VIRTUAL is not set
 # CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE is not set
@@ -418,6 +427,8 @@
 CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384
 # CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set
 # CONFIG_MBEDTLS_DEBUG is not set
+# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
+# CONFIG_MBEDTLS_CMAC_C is not set
 CONFIG_MBEDTLS_HARDWARE_AES=y
 # CONFIG_MBEDTLS_HARDWARE_MPI is not set
 # CONFIG_MBEDTLS_HARDWARE_SHA is not set
@@ -584,8 +595,8 @@
 # CONFIG_MONITOR_BAUD_OTHER is not set
 CONFIG_MONITOR_BAUD_OTHER_VAL=115200
 CONFIG_MONITOR_BAUD=115200
-CONFIG_OPTIMIZATION_LEVEL_DEBUG=y
-# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set
+CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y
+# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set
 CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
 # CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set
 # CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set

mercurial