diff -r 000000000000 -r 88d965579617 main/config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/config.h Tue Oct 08 12:00:31 2019 +0200 @@ -0,0 +1,195 @@ +/** + * @file config.h + * @brief The 'co2meter' configuration data. These are stored in the + * spiffs filesystem in a flash partition. + */ + +#ifndef _CONFIG_H +#define _CONFIG_H + +// Global includes for the project + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/event_groups.h" +#include "freertos/queue.h" +#include "driver/gpio.h" +#include "driver/adc.h" +#include "driver/rtc_io.h" +#include "soc/sens_periph.h" +#include "soc/rtc.h" +#include "esp_adc_cal.h" +#include "esp_sleep.h" +#include "esp_log.h" +#include "esp_spiffs.h" +#include "esp_vfs.h" +#include "esp_system.h" +#include "esp_wifi.h" +//#include "esp_wifi_types.h" +#include "esp_wpa2.h" +#include "esp_event.h" +#include "esp_spi_flash.h" +#include "esp_ota_ops.h" +#include "esp_http_client.h" +#include "nvs.h" +#include "nvs_flash.h" +#include "lwip/apps/sntp.h" +#include "lwip/sockets.h" +#include "lwip/dns.h" +#include "lwip/netdb.h" +#include "tcpip_adapter.h" +#include "mqtt_client.h" + +#include "rotary_encoder.h" +#include "u8g2_esp32_hal.h" + +#include "task_ds18b20.h" +#include "task_adc.h" +#include "task_wifi.h" +#include "task_mqtt.h" +#include "xutil.h" + + +/** + * @brief Mainloop 1 timed actions. + */ +typedef enum +{ + MAIN_LOOP1_INIT = 0, ///< Init fase + MAIN_LOOP1_CONNECT, ///< Connect WiFi + MAIN_LOOP1_MQTT_CONNECT, ///< Connect MQTT if WiFi + MAIN_LOOP1_WAITCON, ///< Wait for connection and measurements + MAIN_LOOP1_SEND, ///< Send MQTT node and units messages + MAIN_LOOP1_WAITACK, ///< MQTT messages received + MAIN_LOOP1_MQTT_DISCONNECT, ///< MQTT disconnect + MAIN_LOOP1_DISCONNECT, ///< Disconnect WiFi + MAIN_LOOP1_WIFI_OFF, ///< WiFi power off + MAIN_LOOP1_DONE ///< All done +} MAIN_LOOP1; + + + +/** + * @brief Mainloop 2 user actions. + */ +typedef enum +{ + MAIN_LOOP2_INIT = 0, + MAIN_LOOP2_UNIT1, ///< Unit 1 + MAIN_LOOP2_UNIT2, ///< Unit 2 + MAIN_LOOP2_UNIT3, ///< Unit 3 + MAIN_LOOP2_UNIT4, ///< Unit 4 + MAIN_LOOP2_SET_WIFI, ///< WiFi stations setup + MAIN_LOOP2_SET_NETWORK, ///< Network setup + MAIN_LOOP2_SET_MQTT, ///< MQTT setup + MAIN_LOOP2_UPDATE, ///< Update + MAIN_LOOP2_INACTIVE, ///< Inactive reached, cleanup + MAIN_LOOP2_DONE ///< All done +} MAIN_LOOP2; + + + +/** + * @brief Global configuration. File /spiffs/config.conf + */ +struct strConfig { + uint8_t Version; ///< Record version number for updates. + char ntp_server[32]; ///< Preffered NTP server. + char hostname[32]; ///< Our hostname. + char uuid[37]; ///< Sort of uuid code. + char xlastSSID[32]; ///< Last connected station. + char mqtt_server[32]; ///< MQTT server. + uint16_t mqtt_port; ///< MQTT TCP port. + char mqtt_user[32]; ///< MQTT user name if needed. + char mqtt_pwd[62]; ///< MQTT password. +} config; ///< Config record. + + +/** + * @brief Write configuration to disk. + */ +void write_config(void); + +/** @brief Read configuration file. If it doesn't exist create and + * write a new configuration file with sane defaults. + */ +void read_config(void); + + + +/** + * @brief Records with WiFi stations we have succesfully connected. + */ +struct strStations { + char SSID[32]; ///< Station SSID + char Password[64]; ///< Station password + bool hide; ///< Hide from AP scan. +} wifiStation; ///< Station record. + +/** + * @brief Add a new station record. + * @param SSID The SSID + * @param Password The password for this SSID + * @return The record number, or -1 if error. + */ +int add_station(uint8_t *SSID, uint8_t *Password); + +/** + * @brief Read station info record. + * @param SSID Search for the SSID and load the record if found. + * @return Return -1 if not found, else the record number and the wifiStation record is filled. + */ +int read_station(uint8_t *SSID); + +/** + * @brief Remove station record. + * @param SSID The SSID to remove. + */ +void remove_station(uint8_t *SSID); + + + +/** + * @brief Records that describes the carbonation units, + */ +typedef struct strUnit { + char uuid[37]; ///< Unit uuid + char product_uuid[37]; ///< Beer product uuid + char product_code[33]; ///< Beer product code + char product_name[129]; ///< Beer product name + char alias[33]; ///< Alias name 'unit1' + int temperature_state; ///< Reading status + char temperature_address[33]; ///< DS18B20 address + uint32_t temperature; ///< Temperature in C * 1000 + int pressure_state; ///< Reading status + uint8_t pressure_channel; ///< ADC channel + uint32_t pressure_voltage; ///< Measured voltage in mV. + uint32_t pressure_zero; ///< Zero offset in mV. + uint32_t pressure; ///< Pressure in bar * 1000; + int mode; ///< Unit mode +} unit_t; + +/** + * @brief Write units to disk. + */ +void write_units(void); + +/** @brief Read units file. If it doesn't exist create and + * write a new units file with sane defaults. + */ +void read_units(void); + + + +#endif