main/config.h

Tue, 03 Oct 2023 17:24:06 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 03 Oct 2023 17:24:06 +0200
changeset 77
15dc572a7fcb
parent 74
34da2d2b12d5
child 80
715785443a95
permissions
-rw-r--r--

Version 0.3.0. Backported network code from experimental roaming project. Will now connect after reset to the strongest AP. Id the signal level drops below -67, extra scans are done to see for a better AP. Nothing is done yet. Removed config.conf file, all info is taken from the project menu and live tests. Better log the board type and send it via json mqtt. Send bssid and current channel too.

/**
 * @file config.h
 * @brief The 'co2meter' configuration data. These are stored in the 
 *        spiffs filesystem in a flash partition.
 */

#ifndef _G_CONFIG_H
#define _G_CONFIG_H

// Global includes for the project

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include <sys/time.h>

#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/rtc_io.h"
#include "soc/sens_periph.h"
#include "soc/rtc.h"
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali.h"
#include "esp_adc/adc_cali_scheme.h"
#include "esp_log.h"
#include "esp_spiffs.h"
#include "esp_vfs.h"
#include "esp_system.h"
#include "esp_chip_info.h"
#include "esp_mac.h"
#include "esp_wifi.h"
#include "esp_wpa2.h"
#include "esp_event.h"
#include "esp_timer.h"
#include "esp_ota_ops.h"
#include "esp_http_client.h"
#include "esp_app_format.h"
#include "nvs_flash.h"
#include "lwip/sockets.h"
#include "lwip/dns.h"
#include "lwip/netdb.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 "task_user.h"
#include "xutil.h"
#include "updates.h"


#define MAINLOOP_TIMER	60	///< Mainloop interval


/**
 * @brief Mainloop 1 timed actions.
 */
typedef enum
{
    ML1_INIT = 0,		///< Init fase
    ML1_CONNECT,		///< Connect WiFi
    ML1_MQTT_CONNECT,		///< Connect MQTT if WiFi
    ML1_WAITCON,		///< Wait for connection and measurements
    ML1_SEND,			///< Send MQTT node and units messages
    ML1_WAITACK,		///< MQTT messages received
    ML1_STATUS,			///< Update status
    ML1_SCAN,			///< Scan AP's for better one
    ML1_DONE			///< All done
} ML1;



/**
 * @brief Mainloop 2 user actions.
 */
typedef enum
{
    ML2_INIT = 0,
    ML2_USER,			///< User mainmenu
    ML2_UNIT1,			///< Unit 1
    ML2_UNIT2,			///< Unit 2
    ML2_UNIT3,			///< Unit 3
    ML2_WIFI,			///< WiFi status
    ML2_NETWORK,		///< Network status
    ML2_MQTT,			///< MQTT status
    ML2_UPDATE,			///< Update
    ML2_COUNTERS,		///< Counters display
    ML2_SETUP_UNIT1,		///< Unit 1 setup
    ML2_SETUP_UNIT2,		///< Unit 2 setup
    ML2_SETUP_UNIT3,		///< Unit 3 setup
    ML2_ZERO_UNIT1,		///< Unit 1 set zero
    ML2_ZERO_UNIT2,		///< Unit 2 set zero
    ML2_ZERO_UNIT3,		///< Unit 3 set zero
    ML2_SEL_SENSOR1,		///< Unit 1 select sensor
    ML2_SEL_SENSOR2,		///< Unit 2 select sensor
    ML2_SEL_SENSOR3,		///< Unit 3 select sensor
    ML2_INACTIVE,		///< Inactive reached, cleanup
    ML2_DONE			///< All done
} ML2;



/**
 * @brief Records with WiFi stations we have succesfully connected.
 */
typedef struct {
    char        SSID[32];                       ///< Station SSID
    char        Password[64];                   ///< Station password
    bool        xhide;                          ///< Hide from AP scan.
} wifiStation_t;                                  ///< 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 {
    char		uuid[37];			///< Unit uuid
    char		alias[33];			///< Alias name 'unit1'
    int			temperature_state;		///< Reading status
    char		temperature_rom_code[17];	///< 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 promille of the full scale.
    uint32_t		pressure;			///< Pressure in bar * 1000;
    int			mode;				///< Unit mode
    uint32_t		alarm;				///< Alarm bits
} unit_t;

#define ALARM_UNIT_PRESSURE		0x0001		///< Unit pressure sensor error
#define ALARM_UNIT_TEMPERATURE		0x0002		///< Unit temperature sensor error
#define	ALARM_SYS_TEMPERATURE		0x0004		///< System temperature sensor error


/**
 * @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

mercurial