Wed, 04 Oct 2023 11:28:49 +0200
Version 0.3.1. Remove obsolete files from spiffs filesystem. Removed obsolete wifi stations.conf file and functions. Removed obsolete user screens.
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * @file config.c |
41
d327e0aff62f
Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
3 | * @brief The 'co2meter' configuration data. These are stored in the |
d327e0aff62f
Updated doxygen comments. Removed some development debug logs. Increased user inactivity time to 4 minutes. More Dutch translations in the OTA update screens.
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
4 | * spiffs filesystem in a flash partition. |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | */ |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | #include "config.h" |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | static const char *TAG = "config"; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | |
4
2a57c466bf45
FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
11 | unit_t units[3]; ///< Pressure test units |
2a57c466bf45
FreeRTOS scheduler from 100 Hz to 200 Hz. All units data is now protected with a semaphore.
Michiel Broek <mbroek@mbse.eu>
parents:
3
diff
changeset
|
12 | SemaphoreHandle_t xSemaphoreUnits = NULL; ///< Semaphore Units records |
80
715785443a95
Version 0.3.1. Remove obsolete files from spiffs filesystem. Removed obsolete wifi stations.conf file and functions. Removed obsolete user screens.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
13 | //wifiStation_t wifiStation; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | void write_units() { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | uint8_t *dst = (uint8_t *)&units; |
74 | 19 | FILE *f = fopen("/spiffs/units.conf", "r+"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | if (f == NULL) { |
74 | 22 | ESP_LOGE(TAG, "write /spiffs/units.conf failed"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | return; |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | size_t bytes = fwrite(dst, 1, sizeof(units), f); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | fclose(f); |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | if (bytes != sizeof(units)) { |
74 | 28 | ESP_LOGE(TAG, "/spiffs/units.conf written %d/%d bytes", bytes, sizeof(units)); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | } else { |
74 | 30 | ESP_LOGD(TAG, "/spiffs/units.conf written %d bytes", bytes); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | void read_units() { |
60
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
37 | uint8_t *dst = (uint8_t *)&units; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | uint8_t mac_addr[8] = {0}; |
60
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
39 | size_t bytes; |
74 | 40 | FILE *f = fopen("/spiffs/units.conf", "r"); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | if (f == NULL) { |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | // No units yet, create them. |
74 | 44 | ESP_LOGE(TAG, "/spiffs/units.conf not found, create new"); |
59
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
45 | goto u_error; |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | } else { |
60
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
47 | bytes = fread(dst, 1, sizeof(units), f); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | fclose(f); |
59
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
49 | if (bytes != sizeof(units)) { |
74 | 50 | ESP_LOGE(TAG, "/spiffs/units.conf read %d of %d bytes", bytes, sizeof(units)); |
59
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
51 | goto u_error; |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
52 | } |
74 | 53 | ESP_LOGI(TAG, "/spiffs/units.conf read %d bytes", bytes); |
21
043ae27633f8
Moved the user interface into a separate task. Added a real seconds timer to this task.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
54 | for (int i = 0; i < 3; i++) |
74 | 55 | ESP_LOGI(TAG, "%d %s %d %4lu %3lu", i, units[i].alias, units[i].pressure_channel, units[i].pressure_voltage, units[i].pressure_zero); |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | } |
59
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
57 | return; |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
58 | |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
59 | u_error: |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
60 | esp_efuse_mac_get_default(mac_addr); |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
61 | for (int i = 0; i < 3; i++) { |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
62 | memset(&units[i], 0, sizeof(unit_t)); |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
63 | sprintf(units[i].uuid, "c0ffeeee-dead-beef-caf%d-%02x%02x%02x%02x%02x%02x", i & 3, |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
64 | mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
65 | sprintf(units[i].alias, "unit%d", (i + 1) & 3); |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
66 | units[i].pressure_zero = 110; |
52d9405474e1
Better check for a corrupted units file. Added a small boot delay to prevent units file corruption.
Michiel Broek <mbroek@mbse.eu>
parents:
57
diff
changeset
|
67 | } |
74 | 68 | f = fopen("/spiffs/units.conf", "w+"); |
60
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
69 | bytes = fwrite(dst, 1, sizeof(units), f); |
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
70 | fclose(f); |
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
71 | if (bytes != sizeof(units)) { |
74 | 72 | ESP_LOGE(TAG, "/spiffs/units.conf written %d/%d bytes", bytes, sizeof(units)); |
60
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
73 | } else { |
74 | 74 | ESP_LOGI(TAG, "/spiffs/units.conf written %d bytes", bytes); |
60
07a1a07fdc8c
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.
Michiel Broek <mbroek@mbse.eu>
parents:
59
diff
changeset
|
75 | } |
0
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | } |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | |
88d965579617
Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 |