Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable blynk #19

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/grower_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef GROWER_VERSION_H
#define GROWER_VERSION_H

const char GROWER_VERSION[] = "0.8.0-beta2-prom";
const char GROWER_VERSION[] = "0.8.0-beta3";
// Example version with appended build version (autoincrementing part):
// const char VERSION[] = "0.4.0-230498"

Expand Down
1 change: 0 additions & 1 deletion include/secrets.h.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define ORANGE_SSID "orange-tram"
#define ASUS_SSID "tram4-2g"

const char BLYNK_AUTH[] = "blabla124324234234234223dsfassa";
const char WIFI_SSID[] = ASUS_SSID;
const char WIFI_PSK[] = "access-point-password";

Expand Down
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ monitor_dtr = 0

lib_deps =
ezTime@0.8.3
https://github.com/Kristty/blynk-library.git#v0.6.1-linker-patch
DHT sensor library for ESPx@1.17
https://github.com/jfturcot/SimpleTimer.git#b30890b8f7046bf3b0258e5870e5dda78ac5c71a
53 changes: 0 additions & 53 deletions src/BlynkManager.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions src/BlynkManager.h

This file was deleted.

43 changes: 8 additions & 35 deletions src/DHTDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@

#include "DHTDevice.h"

void DHTDevice::init(uint8_t pin, uint8_t blynkTempPin) {
pinMode(pin, INPUT_PULLUP);
dht.setup(pin, DHT_MODEL);
dhtReadInterval = (dht.getMinimumSamplingPeriod());
Serial.printf((char*)F("DHT sensor read interval is: %u\n"), dhtReadInterval);
}

void DHTDevice::init(uint8_t pin, uint8_t blynkTempPin, uint8_t blynkRhPin) {
init(pin, blynkTempPin);
this->blynkTempPin = blynkTempPin;
this->blynkRhPin = blynkRhPin;
};

/************ LOGGING ************/
// TODO: candidate for debug logging
// Serial.print("DHT " + String(dht.getStatusString()));
Expand All @@ -28,37 +15,23 @@ void DHTDevice::init(uint8_t pin, uint8_t blynkTempPin, uint8_t blynkRhPin) {
// Serial.println(rH);
/************ END LOGGING ************/
void DHTDevice::tempDataHandler(Device* device, uint8_t MAX_TEMP, uint8_t TEMP_HYSTERESIS) {
float currTemp;
currTemp = dht.getTemperature();
if (isnan(currTemp)) {
temp = dht.getTemperature();
if (isnan(temp)) {
_tempReadErrs++;
Serial.printf((char*)F("DHT: Failed to read temperature!\n\tcurrent value:\t\t\t%f\n\tlast valid value:\t\t%f\n"), currTemp, temp);
Serial.printf((char*)F("DHT: Failed to read temperature! Device status: %s\n"), dht.getStatusString());
return;
}
temp = currTemp;
PowerManager::autoPower(&device->isAutoPowerOn, &device->isPowerOn, &temp, MAX_TEMP, TEMP_HYSTERESIS, device->pin, device->led);
BlynkManager::sendTempToBlynk(temp, blynkTempPin);
PowerManager::autoPower(&device->isAutoPowerOn, &device->isPowerOn, &temp, MAX_TEMP, TEMP_HYSTERESIS, this->_pin);
}

void DHTDevice::rhDataHandler(Device* device, uint8_t MAX_RH, uint8_t RH_HYSTERESIS) {
float currRH;
currRH = dht.getHumidity();
if (isnan(currRH)) {
rH = dht.getHumidity();
if (isnan(rH)) {
_rHReadErrs++;
Serial.printf((char*)F("DHT: Failed to read humidity!\n\tcurrent value:\t\t\t%f\n\tlast valid value:\t\t%f\n"), currRH, rH);
Serial.printf((char*)F("DHT: Failed to read humidity! Device status: %s\n"), dht.getStatusString());
return;
}
rH = currRH;
PowerManager::autoPower(&device->isAutoPowerOn, &device->isPowerOn, &rH, MAX_RH, RH_HYSTERESIS, device->pin, device->led);
BlynkManager::sendRhToBlynk(rH, blynkRhPin);
}

void DHTDevice::powerOn() {

}

void DHTDevice::powerOff() {

PowerManager::autoPower(&device->isAutoPowerOn, &device->isPowerOn, &rH, MAX_RH, RH_HYSTERESIS, this->_pin);
}

String DHTDevice::status() {
Expand Down
12 changes: 7 additions & 5 deletions src/DHTDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <Arduino.h>
#include <DHTesp.h>
#include "Device.h"
#include "BlynkManager.h"
#include "MetricsCollectable.h"

#define DHT_MODEL DHTesp::DHT22
Expand All @@ -17,13 +16,16 @@
class DHTDevice: public Device, MetricsCollectable {

public:
uint16_t blynkTempPin, blynkRhPin;
uint16_t dhtReadInterval;
float temp, rH;

void init(uint8_t pin, uint8_t blynkTempPin);

void init(uint8_t pin, uint8_t blynkTempPin, uint8_t blynkRhPin);
DHTDevice(uint8_t pin){
this->_pin = pin;
pinMode(pin, INPUT_PULLUP);
dht.setup(pin, DHT_MODEL);
dhtReadInterval = (dht.getMinimumSamplingPeriod());
Serial.printf((char *)F("DHT sensor read interval is: %ums\n"), dhtReadInterval);
}

void tempDataHandler(Device* device, uint8_t MAX_TEMP, uint8_t TEMP_HYSTERESIS);

Expand Down
25 changes: 6 additions & 19 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,23 @@

#include "Device.h"

Device::Device() {
};

void Device::init(uint8_t pin, uint8_t blynkPin) {
this->pin = pin;
this->led = new WidgetLED(blynkPin);

pinMode(pin, OUTPUT);

isPowerOn = PowerManager::manualPower(true, pin, led);
isAutoPowerOn = true;
};

void Device::powerOn() {
isPowerOn = PowerManager::manualPower(true, pin, led);
isAutoPowerOn = true;
this->isPowerOn = PowerManager::manualPowerOn(_pin);
this->isAutoPowerOn = true;
}

void Device::powerOff() {
this->isPowerOn = PowerManager::manualPower(false, pin, led);
isAutoPowerOn = false;
this->isPowerOn = PowerManager::manualPowerOff(_pin);
this->isAutoPowerOn = false;
}

void Device::scheduledPowerOn(Scheduler scheduler) {
powerOn();
this->powerOn();
scheduler.setNextEvent();
}

void Device::scheduledPowerOff(Scheduler scheduler) {
powerOff();
this->powerOff();
scheduler.setNextEvent();
}

Expand Down
17 changes: 9 additions & 8 deletions src/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
#define DEVICE_H

#include <Arduino.h>
#include <BlynkSimpleEsp8266_SSL.h>
#include "PowerManager.h"
#include "scheduler.h"

class Device {

public:

Device();

uint8_t pin;
uint8_t blynkPin;
WidgetLED *led;
uint8_t _pin;
bool isPowerOn;
bool isAutoPowerOn;

void init(uint8_t pin, uint8_t blynkPin);
Device(){};

Device(uint8_t pin):
_pin(pin),
isAutoPowerOn(true) {
pinMode(pin, OUTPUT);
this->isPowerOn = PowerManager::manualPowerOn(pin);
};

void powerOn();

Expand Down
12 changes: 1 addition & 11 deletions src/LDRDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@

#include "LDRDevice.h"

void LDRDevice::init(uint8_t pin, uint8_t blynkPin) {
this->pin = pin;
this->blynkPin = blynkPin;
this->led = new WidgetLED(blynkPin);
uint16_t lightVal = getLightValue();
this->isPowerOn = lightVal < LAMP_ON_VALUE ? true : false;
}

uint16_t LDRDevice::getLightValue() {
return analogRead(pin);
return analogRead(_pin);
}

void LDRDevice::lampStatus() {
uint16_t lightVal = getLightValue();
uint8_t ledBrightness = map(lightVal, 0, 1023, 255, 0);
// TODO: candidate for debug logging
// Serial.println("LDR sensor: " + String(lightVal));
if (lightVal < LAMP_ON_VALUE && !isPowerOn) {
Expand All @@ -28,7 +19,6 @@ void LDRDevice::lampStatus() {
Serial.println(F("LDR sensor: lamp is off"));
isPowerOn = false;
}
BlynkManager::sendLampToBlynk(ledBrightness, led);
}


Expand Down
10 changes: 7 additions & 3 deletions src/LDRDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@

#include <Arduino.h>
#include "Device.h"
#include "BlynkManager.h"

// LDR sensor values. The lower value is the brighter is light.
const uint8_t LAMP_ON_VALUE = 200;
const uint16_t LAMP_OFF_VALUE = 900;

class LDRDevice: public Device {
public:
void init(uint8_t pin, uint8_t blynkPin);

LDRDevice(uint8_t pin) {
this->_pin = pin;
uint16_t lightVal = getLightValue();
this->isPowerOn = lightVal < LAMP_ON_VALUE ? true : false;
Kristty marked this conversation as resolved.
Show resolved Hide resolved
};

void lampStatus();

String status();

private:

uint16_t getLightValue();
Expand Down
33 changes: 13 additions & 20 deletions src/PowerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@

#include "PowerManager.h"


void PowerManager::autoPower(bool *autoControl, bool *isOn, float *currVal, float maxVal, float valHyst, uint8_t pin, WidgetLED *led) {
void PowerManager::autoPower(bool *autoControl, bool *currentState, float *currVal, float maxVal, float valHyst, uint8_t pin) {
if (!*autoControl) return;
if (*currVal >= maxVal && *isOn) {
*isOn = manualPower(false, pin, led);
if (*currVal >= maxVal && *currentState) {
*currentState = manualPowerOff(pin);
}
else if (*currVal < maxVal - valHyst && !*isOn) {
*isOn = manualPower(true, pin, led);
else if (*currVal < maxVal - valHyst && !*currentState) {
*currentState = manualPowerOn(pin);
}
}

bool PowerManager::manualPower(bool enabled, uint8_t pin, WidgetLED *led) {
bool isOn;
if (enabled) {
digitalWrite(pin, RELAY_ON);
isOn = true;
Serial.println("Blynk: enabling led for pin: " + String(pin));
led->on();
} else {
digitalWrite(pin, RELAY_OFF);
isOn = false;
Serial.println("Blynk: disabling led for pin: " + String(pin));
led->off();
}
return isOn;
bool PowerManager::manualPowerOn(uint8_t pin) {
digitalWrite(pin, RELAY_ON);
return true;
}

bool PowerManager::manualPowerOff(uint8_t pin) {
digitalWrite(pin, RELAY_OFF);
return false;
}
Loading