Skip to content

Commit

Permalink
Merge pull request #38 from vi7/hum_mains_power
Browse files Browse the repository at this point in the history
Control mains power outlet for humidifier
  • Loading branch information
vi7 authored Dec 15, 2022
2 parents e5c93af + 88c7cdb commit 84909a6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 33 deletions.
14 changes: 8 additions & 6 deletions include/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@
#define SSR_OUTLET_ON 0x17703
#define SSR_OUTLET_OFF 0x1770C

#define HUM_ON_CODE SSR_OUTLET_ON
#define HUM_OFF_CODE SSR_OUTLET_OFF
#define FAN_ON_CODE OUTLET3_ON
#define FAN_OFF_CODE OUTLET3_OFF
#define LAMP_ON_CODE OUTLET4_ON
#define LAMP_OFF_CODE OUTLET4_OFF
#define HUM_ON_CODE SSR_OUTLET_ON
#define HUM_OFF_CODE SSR_OUTLET_OFF
#define HUM_MAINS_ON_CODE OUTLET2_ON
#define HUM_MAINS_OFF_CODE OUTLET2_OFF
#define FAN_ON_CODE OUTLET3_ON
#define FAN_OFF_CODE OUTLET3_OFF
#define LAMP_ON_CODE OUTLET4_ON
#define LAMP_OFF_CODE OUTLET4_OFF
#else
#define LAMPRELAYPIN 0 // white/light-brown
#define HUMRELAYPIN 2 // violet
Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
#ifndef VERSION_H
#define VERSION_H

#define VERSION "0.12.2"
#define VERSION "0.13.0"

#endif
10 changes: 0 additions & 10 deletions src/DHTDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@

#include "DHTDevice.h"

/************ LOGGING ************/
// TODO: candidate for debug logging
// Serial.print("DHT " + String(dht.getStatusString()));
// Serial.print(F("\t"));
// Serial.print(F("temperature: "));
// Serial.print(temp);
// Serial.print(F("\t\t"));
// Serial.print(F("RH: "));
// Serial.println(rH);
/************ END LOGGING ************/
void DHTDevice::tempDataHandler(Device* device, uint8_t MAX_TEMP, uint8_t TEMP_HYSTERESIS) {
temp = dht.getTemperature();
if (isnan(temp)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
void Device::powerOn() {
#ifdef RADIO_POWER
this->isPowerOn = PowerManager::manualPowerOn(&_onCode);
Serial.printf("Device powered on with code %X\n", _onCode);
#else
this->isPowerOn = PowerManager::manualPowerOn(_pin);
Serial.printf("Device powered on on pin %d\n", _pin);
#endif
this->isAutoPowerOn = true;
}

void Device::powerOff() {
#ifdef RADIO_POWER
this->isPowerOn = PowerManager::manualPowerOff(&_offCode);
Serial.printf("Device powered off with code %X\n", _offCode);
#else
this->isPowerOn = PowerManager::manualPowerOff(_pin);
Serial.printf("Device powered off on pin %d\n", _pin);
#endif
this->isAutoPowerOn = false;
}
Expand Down
1 change: 0 additions & 1 deletion src/LDRDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ uint16_t LDRDevice::getLightValue() {

void LDRDevice::lampStatus() {
uint16_t lightVal = getLightValue();
// TODO: candidate for debug logging
// Serial.println("LDR sensor: " + String(lightVal));
if (lightVal < LAMP_ON_VALUE && !isPowerOn) {
Serial.println(F("LDR sensor: lamp is on"));
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const endpoint HUM_STATUS = {
DEVICE_STATUS
};

endpoint DHT_ENDPOINTS[] = {TEMP_STATUS, HUM_STATUS};
endpoint HT_ENDPOINTS[] = {TEMP_STATUS, HUM_STATUS};


const endpoint LDR_STATUS = {
Expand Down
22 changes: 8 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ WebServer server(WEB_SERVER_PORT);
#ifdef RADIO_POWER
RCSwitch PowerManager::transmitter = RCSwitch();
Device hum(HUM_ON_CODE, HUM_OFF_CODE);
/*
* Additional 'humMains' device switches on an outlet on main power
* extender where we have humidifier power outlet connected
*/
Device humMains(HUM_MAINS_ON_CODE, HUM_MAINS_OFF_CODE);
Device lamp(LAMP_ON_CODE, LAMP_OFF_CODE);
Device fan(FAN_ON_CODE, FAN_OFF_CODE);
#else
Expand Down Expand Up @@ -131,25 +136,15 @@ void setup() {
timer.setInterval(htu2xD.getReadInterval(), []{htu2xD.rhDataHandler(&hum, MAX_RH, RH_HYSTERESIS);});
timer.setInterval(LIGHT_CHECK_INTERVAL * 1000, []{ldr.lampStatus();});

// TODO: candidate for debug logging
// Serial.print(F("[MAIN] [D] Requested watering start time: "));
// Serial.println(waterScheduler.getStartDateTime());
// Serial.print(F("[MAIN] [D] Next watering scheduled on: "));
// Serial.println(waterScheduler.getNextDateTime());

humMains.powerOn();
waterScheduler = Scheduler([]{
waterDevice.scheduledWater(
waterScheduler, []{waterDevice.powerOff();}
);
}, WATER_SCHEDULE);
lampOnScheduler = Scheduler([]{lamp.scheduledPowerOn(lampOnScheduler);}, LAMP_ON_SCHEDULE);
lampOffScheduler = Scheduler([]{lamp.scheduledPowerOff(lampOffScheduler);}, LAMP_OFF_SCHEDULE);
/*
* Fan on/off schedule disabled due to power on issues
* while using computer fan with AC/DC 230V/12V power supply
* It is probably caused by the usage of solid-state relays
* See https://omronfs.omron.com/en_US/ecb/products/pdf/precautions_ssr.pdf
*/
/* Uncomment lines below to enable automatic on/off schedule for the fan */
// fanOnScheduler = Scheduler([]{fan.scheduledPowerOn(fanOnScheduler);}, FAN_ON_SCHEDULE);
// fanOffScheduler = Scheduler([]{fan.scheduledPowerOff(fanOffScheduler);}, FAN_OFF_SCHEDULE);
humOnScheduler = Scheduler([]{hum.scheduledPowerOn(humOnScheduler);}, HUM_ON_SCHEDULE);
Expand All @@ -159,8 +154,7 @@ void setup() {
server.registerEndpoint(&fan, FAN_ENDPOINTS, sizeof(FAN_ENDPOINTS)/sizeof(FAN_ENDPOINTS[0]));
server.registerEndpoint(&hum, HUM_ENDPOINTS, sizeof(HUM_ENDPOINTS)/sizeof(HUM_ENDPOINTS[0]));
server.registerEndpoint(&waterDevice, WATER_ENDPOINTS, sizeof(WATER_ENDPOINTS)/sizeof(WATER_ENDPOINTS[0]));
// TODO: rename DHT endpoints to HTU2xD endpoints
server.registerEndpoint(&htu2xD, DHT_ENDPOINTS, sizeof(DHT_ENDPOINTS)/sizeof(DHT_ENDPOINTS[0]));
server.registerEndpoint(&htu2xD, HT_ENDPOINTS, sizeof(HT_ENDPOINTS)/sizeof(HT_ENDPOINTS[0]));
server.registerEndpoint(&ldr, LDR_ENDPOINTS, sizeof(LDR_ENDPOINTS)/sizeof(LDR_ENDPOINTS[0]));

server.begin();
Expand Down

0 comments on commit 84909a6

Please sign in to comment.