# HG changeset patch # User Michiel Broek # Date 1592221126 -7200 # Node ID 07a1a07fdc8c81059a53f5922692f8ea610029ae # Parent 52d9405474e10db2fe5c579e5d3232f0861824ba write_units now overwrites instead of truncate/write the records. Add ssid to the node mqtt message. Lower rotary log messages. Removed most menu log messages. diff -r 52d9405474e1 -r 07a1a07fdc8c main/config.c --- a/main/config.c Mon Jun 15 12:08:21 2020 +0200 +++ b/main/config.c Mon Jun 15 13:38:46 2020 +0200 @@ -62,7 +62,7 @@ void write_units() { uint8_t *dst = (uint8_t *)&units; - FILE *f = fopen("/spiffs/etc/units.conf", "w+"); + FILE *f = fopen("/spiffs/etc/units.conf", "r+"); if (f == NULL) { ESP_LOGE(TAG, "write /spiffs/etc/units.conf failed"); @@ -80,8 +80,9 @@ void read_units() { - uint8_t *dst; + uint8_t *dst = (uint8_t *)&units; uint8_t mac_addr[8] = {0}; + size_t bytes; FILE *f = fopen("/spiffs/etc/units.conf", "r"); if (f == NULL) { @@ -89,8 +90,7 @@ ESP_LOGE(TAG, "/spiffs/etc/units.conf not found, create new"); goto u_error; } else { - dst = (uint8_t*)&units; - size_t bytes = fread(dst, 1, sizeof(units), f); + bytes = fread(dst, 1, sizeof(units), f); fclose(f); if (bytes != sizeof(units)) { ESP_LOGE(TAG, "/spiffs/etc/units.conf read %d of %d bytes", bytes, sizeof(units)); @@ -112,6 +112,13 @@ units[i].pressure_zero = 110; } f = fopen("/spiffs/etc/units.conf", "w+"); + bytes = fwrite(dst, 1, sizeof(units), f); + fclose(f); + if (bytes != sizeof(units)) { + ESP_LOGE(TAG, "/spiffs/etc/units.conf written %d/%d bytes", bytes, sizeof(units)); + } else { + ESP_LOGI(TAG, "/spiffs/etc/units.conf written %d bytes", bytes); + } } diff -r 52d9405474e1 -r 07a1a07fdc8c main/task_mqtt.c --- a/main/task_mqtt.c Mon Jun 15 12:08:21 2020 +0200 +++ b/main/task_mqtt.c Mon Jun 15 13:38:46 2020 +0200 @@ -226,7 +226,9 @@ if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { payload = xstrcat(payload, (char *)",\"net\":{\"address\":\""); payload = xstrcat(payload, wifi_state->STA_ip); - payload = xstrcat(payload, (char *)"\",\"ifname\":\"sta\",\"rssi\":"); + payload = xstrcat(payload, (char *)"\",\"ifname\":\"sta\",\"ssid\":\""); + payload = xstrcat(payload, wifi_state->STA_ssid); + payload = xstrcat(payload, (char *)"\",\"rssi\":"); sprintf(buf, "%d", wifi_state->STA_rssi); payload = xstrcat(payload, buf); payload = xstrcat(payload, (char *)"}"); diff -r 52d9405474e1 -r 07a1a07fdc8c main/task_user.c --- a/main/task_user.c Mon Jun 15 12:08:21 2020 +0200 +++ b/main/task_user.c Mon Jun 15 13:38:46 2020 +0200 @@ -755,7 +755,7 @@ PushDuration = 0; } else if (gpio_get_level(io_num) == 1) { PushDuration = (esp_timer_get_time() - pushed) / 1000; - ESP_LOGI(TAG, "GPIO rotary button intr, val: %d time: %d", gpio_get_level(io_num), PushDuration); + ESP_LOGD(TAG, "GPIO rotary button intr, val: %d time: %d", gpio_get_level(io_num), PushDuration); if (! user_busy()) { xEventGroupSetBits(xEventGroupUser, TASK_USER_WAKEUP); } @@ -888,18 +888,15 @@ break; case ML2_SETUP_WIFI: - ESP_LOGI(TAG, "Loop user: WiFi setup"); screen_wifi_setup(SubMenu); break; case ML2_LIST_APS: - ESP_LOGI(TAG, "Loop user: WiFi list APs"); SubMenu = SubOffset = 0; screen_list_aps(SubMenu, SubOffset); break; case ML2_EDIT_AP: - ESP_LOGI(TAG, "Loop user: WiFi edit AP"); screen_edit_ap(0); break; @@ -908,7 +905,6 @@ break; case ML2_SETUP_NETWORK: - ESP_LOGI(TAG, "Loop user: Network setup"); screen_network_setup(SubMenu); break; @@ -917,7 +913,6 @@ break; case ML2_SETUP_MQTT: - ESP_LOGI(TAG, "Loop user: MQTT setup"); screen_mqtt_setup(SubMenu); break; @@ -932,7 +927,6 @@ case ML2_SETUP_UNIT1: case ML2_SETUP_UNIT2: case ML2_SETUP_UNIT3: - ESP_LOGI(TAG, "Loop user: Setup Unit %d", Main_Loop2 - ML2_SETUP_UNIT1); SubMenu = SubOffset = 0; screen_unit_setup(Main_Loop2 - ML2_SETUP_UNIT1, SubMenu); break; @@ -940,7 +934,6 @@ case ML2_ZERO_UNIT1: case ML2_ZERO_UNIT2: case ML2_ZERO_UNIT3: - ESP_LOGI(TAG, "Loop user: Zero Unit %d", Main_Loop2 - ML2_ZERO_UNIT1); SubMenu = SubOffset = 0; screen_unit_zero(Main_Loop2 - ML2_ZERO_UNIT1, SubMenu); break; @@ -948,7 +941,6 @@ case ML2_SEL_SENSOR1: case ML2_SEL_SENSOR2: case ML2_SEL_SENSOR3: - ESP_LOGI(TAG, "Loop user: Select sensor %d", Main_Loop2 - ML2_SEL_SENSOR1); SubMenu = SubOffset = 0; screen_list_sensors(Main_Loop2 - ML2_SEL_SENSOR1, SubMenu, SubOffset); break;