esp_garden git · master
Distributed ESP sensor and actuator system (garden)
C++ 70.7% Markdown 18% C 10.7%git clone https://git.christianimmanuel.de/embedded/esp_garden.gitwget https://git.christianimmanuel.de/embedded/esp_garden/archive/esp_garden.tar.gzclient_pump/main/globals.h raw
#ifndef GLOBALS_H
#define GLOBALS_H
#include "esp_log.h"
#include "esp_timer.h"
#include "esp_attr.h"
#include <stdint.h>
#include <stdbool.h>
// Network Time
#define NTP_SERVER "pool.ntp.org"
// Size for buffering data
#define BUFFER_SIZE 50
#define TABLE_SIZE 12
#define VALUE_SIZE 16
#define JSON_PER_ENTRY (29 + (TABLE_SIZE - 1) + (VALUE_SIZE - 1) + 10)
#define JSON_BUFFER_SIZE (BUFFER_SIZE * JSON_PER_ENTRY + 2)
#define SENSOR_CONFIG_COUNT 2
#define millis() (esp_timer_get_time() / 1000ULL)
// Global variables
extern uint32_t g_setup_duration;
extern uint32_t g_wakeup_earlier_server;
extern uint32_t g_wakeup_earlier_sensor;
extern uint32_t g_wakeup_earlier_pump;
// Structs
struct SensorConfigServer_s {
char sensor_name[32];
bool success;
bool is_active;
int pin;
int min_moisture;
char notification_name[32];
int pumping_delay_sec;
int pumping_duration;
int delay_ms;
bool use_time;
uint16_t times[8];
uint8_t time_count;
};
struct SensorConfig_s {
char sensor_name[32];
bool is_active;
int pin;
int min_moisture;
char notification_name[32];
int pumping_delay_sec;
int pumping_duration;
uint8_t pump_mac[6];
int delay_ms;
bool use_time;
uint16_t times[8];
uint8_t time_count;
int64_t last_sensor_read;
int64_t next_sensor_read;
};
struct PumpInformation_s {
char notifiaction_name[32];
int pumping_delay_sec;
int pumping_duration;
int64_t next_message;
};
struct SensorEntry_s {
char table[TABLE_SIZE];
char value[VALUE_SIZE];
int64_t time;
bool pump_reached;
};
// Extern variables
extern SensorEntry_s g_buffer[BUFFER_SIZE];
extern uint8_t g_buffer_count;
#define MAX_PENDING_SENSOR_CONFIGS 4
extern char g_pending_sensor_configs[MAX_PENDING_SENSOR_CONFIGS][32];
extern uint8_t g_pending_sensor_configs_count;
extern bool g_received_ok_from_server;
extern const uint32_t g_min_sleep_time;
extern bool all_init_configs_received;
extern const uint8_t PEER_SERVER[];
extern const uint8_t PEER_SENSOR[];
extern const uint8_t PEER_PUMP[];
extern RTC_DATA_ATTR SensorConfig_s sensor_configs[];
extern uint8_t config_request_attempts_max;
#endif