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.gzglobals.h raw
#ifndef GLOBALS_H
#define GLOBALS_H
#include <Arduino.h>
// Debug macros
#define DEBUG 1
#if DEBUG
#define DBG_BEGIN() Serial.begin(115200)
#define DBG_PRINT(x) Serial.print(x)
#define DBG_PRINTLN(x) Serial.println(x)
#define DBG_PRINTF(...) Serial.printf(__VA_ARGS__)
#else
#define DBG_BEGIN()
#define DBG_PRINT(x)
#define DBG_PRINTLN(x)
#define DBG_PRINTF(...)
#endif
// 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
extern uint32_t g_setup_duration; // getting set automaticall in setup so we know how long it takes
extern uint32_t g_wakeup_earlier_server; // some safety space if setup takes longere (maybe 20sec safety?)
extern uint32_t g_wakeup_earlier_sensor; // some safety space if setup takes longere (maybe 20sec safety?)
extern uint32_t g_wakeup_earlier_pump; // some safety space if setup takes longere (maybe 20sec safety?)
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]; // {0x51,0xc1,0x79,0x1e,0xed,0x18}
int delay_ms;
bool use_time;
uint16_t times[8];
uint8_t time_count;
int64_t last_sensor_read; // Unix time
int64_t next_sensor_read; // Unix time
};
struct PumpInformation_s {
char notifiaction_name[32];
int pumping_delay_sec;
int pumping_duration; // set to 0 if you just want to notify next messaging time
int64_t next_message; // Unix time
};
struct SensorEntry {
char table[TABLE_SIZE];
char value[VALUE_SIZE];
int64_t time;
bool pump_reached;
};
extern SensorEntry g_buffer[BUFFER_SIZE];
extern uint8_t g_buffer_count;
extern char g_pending_sensor_configs[4][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 RTC_DATA_ATTR 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