34 &
light, constants::light_start_hour, constants::light_start_min,
35 constants::light_duration);
44 auto tim = mktime(&timeinfo);
46 strftime(buf,
sizeof(buf),
"%F", &timeinfo);
58 auto tim = mktime(&timeinfo);
60 strftime(buf,
sizeof(buf),
"%F", &timeinfo);
78 Serial.printf(
"Temperature %f\n", temp);
89 light_scheduler.run(&time_info, volt >= constants::ldr_thresh_v);
99 if (!WiFi.isConnected()) {
101 Serial.println(
"Reconnecting WiFi ...");
115 if (event == WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED) {
116 Serial.println(
"WiFi Connected, initialising ...");
119 FIREBASE_URL, FIREBASE_TOKEN, FIREBASE_USER_EMAIL,
120 FIREBASE_USER_PASSWORD);
126 Serial.begin(115200);
130 adc.
begin(constants::adc_bus_addr, pin::adc_sda, pin::adc_scl);
134 WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
135 while (!WiFi.isConnected()) {
136 Serial.println(
"Connecting WiFi ...");
141 FIREBASE_URL, FIREBASE_TOKEN, FIREBASE_USER_EMAIL,
142 FIREBASE_USER_PASSWORD);
153 Serial.println(
"Initialisation complete");
void begin(int addr, int sda_pin, int scl_pin)
void begin(const char *fire_url, const char *fire_token, const char *email, const char *pass)
initialise and authorise system to use Firebase RTDB (real time database) make sure wifi is initialis...
void set_float(const char *path, double value)
Set a float value.
void set_bool(const char *path, bool value)
Set a bool value.
bool check_and_refresh_token()
refresh token if expired
void push_time(const char *path, time_t timestamp)
Push a timestamp into a list to a relative path, useful to log times like when initialisation was com...
Light dependent resistor wrapper.
float read_voltage()
Read voltage from ADC for LDR. Make sure ADC is initialised before calling this method.
Schedules light switching depending on time of day and ambient light.
int get_state()
Get the current state.
void begin(Switch sw)
initialise pin and set initial relay state
void toggle()
Toggle the relay.
A scheduler for running tasks on the controller, minimum time between events is 1 second based off th...
void begin(long int timer_sync_interval_ms=600000)
initialise timer
void run()
This needs to be run in the loop function continuously. Best practice is to have a loop function that...
void create_task(void(*task_func)(), unsigned long interval_sec)
Create a task.
wrapper for Dallas one-wire temperature sensor (DS18B20)
void begin()
Initialise all one wire sensors.
uint8_t device_count()
Get count of total sensors on the one wire bus.
float read()
Read temperature as float value from sensor.
Timer that syncs with NTP server.
void begin(long int sync_interval_ms=600000)
initialise the timer, set a sync interval to sync with NTP server
tm get_utc_time()
Get the utc time now.
time_t get_epoch_time()
Get the seconds since epoch now.
String wrap_date_time(const char *path)
RelayAH light(pin::extra_relay)
void handle_wifi_connection(WiFiEvent_t event, WiFiEventInfo_t info)
String wrap_date(const char *path)
RelayAH misters(pin::misters)
void check_and_refresh_firebase_token()
RelayAH extra(pin::light)
TemperatureSensor temp_sensor(pin::temp_sensor_bus)
void check_and_set_light()