2 * @file config.h |
2 * @file config.h |
3 * @brief The 'co2meter' configuration data. These are stored in the |
3 * @brief The 'co2meter' configuration data. These are stored in the |
4 * spiffs filesystem in a flash partition. |
4 * spiffs filesystem in a flash partition. |
5 */ |
5 */ |
6 |
6 |
7 #ifndef _CONFIG_H |
7 #ifndef _G_CONFIG_H |
8 #define _CONFIG_H |
8 #define _G_CONFIG_H |
9 |
9 |
10 // Global includes for the project |
10 // Global includes for the project |
11 |
11 |
12 #include <stdio.h> |
12 #include <stdio.h> |
13 #include <stdlib.h> |
13 #include <stdlib.h> |
14 #include <string.h> |
14 #include <string.h> |
15 #include <stdbool.h> |
15 #include <stdbool.h> |
16 #include <time.h> |
16 #include <time.h> |
|
17 #include <inttypes.h> |
17 #include <errno.h> |
18 #include <errno.h> |
18 #include <sys/unistd.h> |
19 #include <sys/unistd.h> |
19 #include <sys/fcntl.h> |
20 #include <sys/fcntl.h> |
20 #include <sys/time.h> |
21 #include <sys/time.h> |
21 |
22 |
23 #include "freertos/task.h" |
24 #include "freertos/task.h" |
24 #include "freertos/semphr.h" |
25 #include "freertos/semphr.h" |
25 #include "freertos/event_groups.h" |
26 #include "freertos/event_groups.h" |
26 #include "freertos/queue.h" |
27 #include "freertos/queue.h" |
27 #include "driver/gpio.h" |
28 #include "driver/gpio.h" |
28 #include "driver/adc.h" |
|
29 #include "driver/rtc_io.h" |
29 #include "driver/rtc_io.h" |
30 #include "soc/sens_periph.h" |
30 #include "soc/sens_periph.h" |
31 #include "soc/rtc.h" |
31 #include "soc/rtc.h" |
32 #include "esp_adc_cal.h" |
32 #include "esp_adc/adc_oneshot.h" |
|
33 #include "esp_adc/adc_cali.h" |
|
34 #include "esp_adc/adc_cali_scheme.h" |
33 #include "esp_log.h" |
35 #include "esp_log.h" |
34 #include "esp_spiffs.h" |
36 #include "esp_spiffs.h" |
35 #include "esp_vfs.h" |
37 #include "esp_vfs.h" |
36 #include "esp_system.h" |
38 #include "esp_system.h" |
|
39 #include "esp_chip_info.h" |
|
40 #include "esp_mac.h" |
37 #include "esp_wifi.h" |
41 #include "esp_wifi.h" |
38 #include "esp_wpa2.h" |
42 #include "esp_wpa2.h" |
39 #include "esp_event.h" |
43 #include "esp_event.h" |
40 #include "esp_spi_flash.h" |
44 #include "esp_timer.h" |
41 #include "esp_ota_ops.h" |
45 #include "esp_ota_ops.h" |
42 #include "esp_http_client.h" |
46 #include "esp_http_client.h" |
|
47 #include "esp_app_format.h" |
43 #include "nvs_flash.h" |
48 #include "nvs_flash.h" |
44 #include "lwip/sockets.h" |
49 #include "lwip/sockets.h" |
45 #include "lwip/dns.h" |
50 #include "lwip/dns.h" |
46 #include "lwip/netdb.h" |
51 #include "lwip/netdb.h" |
47 #include "mqtt_client.h" |
52 #include "mqtt_client.h" |
113 |
118 |
114 |
119 |
115 /** |
120 /** |
116 * @brief Global configuration. File /spiffs/config.conf |
121 * @brief Global configuration. File /spiffs/config.conf |
117 */ |
122 */ |
118 struct strConfig { |
123 typedef struct { |
119 uint8_t Version; ///< Record version number for updates. |
124 uint8_t Version; ///< Record version number for updates. |
120 char ntp_server[32]; ///< Preffered NTP server. |
125 char ntp_server[32]; ///< Preffered NTP server. |
121 char hostname[32]; ///< Our hostname. |
126 char hostname[32]; ///< Our hostname. |
122 char uuid[37]; ///< Sort of uuid code. |
127 char uuid[37]; ///< Sort of uuid code. |
123 char xlastSSID[32]; ///< Not used anymore. |
128 char xlastSSID[32]; ///< Not used anymore. |
124 char mqtt_server[32]; ///< MQTT server. |
129 char mqtt_server[32]; ///< MQTT server. |
125 uint16_t mqtt_port; ///< MQTT TCP port. |
130 uint16_t mqtt_port; ///< MQTT TCP port. |
126 char mqtt_user[32]; ///< MQTT user name if needed. |
131 char mqtt_user[32]; ///< MQTT user name if needed. |
127 char mqtt_pwd[62]; ///< MQTT password. |
132 char mqtt_pwd[62]; ///< MQTT password. |
128 } config; ///< Config record. |
133 } strConfig_t; ///< Config record. |
129 |
134 |
130 |
135 |
131 /** |
136 /** |
132 * @brief Write configuration to disk. |
137 * @brief Write configuration to disk. |
133 */ |
138 */ |
142 |
147 |
143 |
148 |
144 /** |
149 /** |
145 * @brief Records with WiFi stations we have succesfully connected. |
150 * @brief Records with WiFi stations we have succesfully connected. |
146 */ |
151 */ |
147 struct strStations { |
152 typedef struct { |
148 char SSID[32]; ///< Station SSID |
153 char SSID[32]; ///< Station SSID |
149 char Password[64]; ///< Station password |
154 char Password[64]; ///< Station password |
150 bool xhide; ///< Hide from AP scan. |
155 bool xhide; ///< Hide from AP scan. |
151 } wifiStation; ///< Station record. |
156 } wifiStation_t; ///< Station record. |
|
157 |
152 |
158 |
153 /** |
159 /** |
154 * @brief Add a new station record. |
160 * @brief Add a new station record. |
155 * @param SSID The SSID |
161 * @param SSID The SSID |
156 * @param Password The password for this SSID |
162 * @param Password The password for this SSID |
174 |
180 |
175 |
181 |
176 /** |
182 /** |
177 * @brief Records that describes the carbonation units, |
183 * @brief Records that describes the carbonation units, |
178 */ |
184 */ |
179 typedef struct strUnit { |
185 typedef struct { |
180 char uuid[37]; ///< Unit uuid |
186 char uuid[37]; ///< Unit uuid |
181 char alias[33]; ///< Alias name 'unit1' |
187 char alias[33]; ///< Alias name 'unit1' |
182 int temperature_state; ///< Reading status |
188 int temperature_state; ///< Reading status |
183 char temperature_rom_code[17]; ///< DS18B20 address |
189 char temperature_rom_code[17]; ///< DS18B20 address |
184 uint32_t temperature; ///< Temperature in C * 1000 |
190 uint32_t temperature; ///< Temperature in C * 1000 |