Skip to content

Commit

Permalink
Add support for chamber controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-se committed Dec 7, 2024
1 parent a876a98 commit acdebb7
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/kegconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void KegConfig::createJson(JsonObject& doc) {
doc[PARAM_BREWFATHER_USERKEY] = getBrewfatherUserKey();

doc[PARAM_BREWPI_URL] = getBrewpiUrl();
doc[PARAM_CHAMBERCTRL_URL] = getChamberCtrlUrl();

doc[PARAM_BREWLOGGER_URL] = getBrewLoggerUrl();

Expand Down Expand Up @@ -158,6 +159,7 @@ void KegConfig::parseJson(JsonObject& doc) {
setBrewfatherUserKey(doc[PARAM_BREWFATHER_USERKEY]);

if (!doc[PARAM_BREWPI_URL].isNull()) setBrewpiUrl(doc[PARAM_BREWPI_URL]);
if (!doc[PARAM_CHAMBERCTRL_URL].isNull()) setChamberCtrlUrl(doc[PARAM_CHAMBERCTRL_URL]);

if (!doc[PARAM_BREWLOGGER_URL].isNull())
setBrewLoggerUrl(doc[PARAM_BREWLOGGER_URL]);
Expand Down
11 changes: 10 additions & 1 deletion src/kegconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ constexpr auto PARAM_BREWFATHER_APIKEY = "brewfather_apikey";
constexpr auto PARAM_BREWSPY_TOKEN1 = "brewspy_token1";
constexpr auto PARAM_BREWSPY_TOKEN2 = "brewspy_token2";
constexpr auto PARAM_BREWPI_URL = "brewpi_url";
constexpr auto PARAM_CHAMBERCTRL_URL = "chamberctrl_url";
constexpr auto PARAM_BARHELPER_APIKEY = "barhelper_apikey";
constexpr auto PARAM_BARHELPER_MONITOR1 = "barhelper_monitor1";
constexpr auto PARAM_BARHELPER_MONITOR2 = "barhelper_monitor2";
Expand Down Expand Up @@ -147,7 +148,8 @@ enum TempSensorType {
SensorDHT22 = 0,
SensorDS18B20 = 1,
SensorBME280 = 2,
SensorBrewPI = 3
SensorBrewPI = 3,
SensorChamberCtrl = 4
};
enum ScaleSensorType { ScaleHX711 = 0, ScaleNAU7802 = 1 };
enum DisplayDriverType { OLED_1306 = 0, LCD = 1 };
Expand All @@ -172,6 +174,7 @@ class KegConfig : public BaseConfig {
String _barhelperMonitor[2] = {"Kegmon TAP 1", "Kegmon TAP 2"};

String _brewpiUrl = "";
String _chamberCtrlUrl = "";

String _brewLoggerUrl = "";

Expand Down Expand Up @@ -242,6 +245,12 @@ class KegConfig : public BaseConfig {
_saveNeeded = true;
}

const char* getChamberCtrlUrl() { return _chamberCtrlUrl.c_str(); }
void setChamberCtrlUrl(String s) {
_chamberCtrlUrl = s;
_saveNeeded = true;
}

const char* getBrewLoggerUrl() { return _brewLoggerUrl.c_str(); }
void setBrewLoggerUrl(String s) {
_brewLoggerUrl = s;
Expand Down
76 changes: 76 additions & 0 deletions src/temp_chamberctrl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
MIT License
Copyright (c) 2024 Magnus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <kegconfig.hpp>
#include <main.hpp>
#include <temp_chamberctrl.hpp>
#include <utils.hpp>

TempSensorChamberCtrl::TempSensorChamberCtrl() { _push = new BasePush(&myConfig); }

TempSensorChamberCtrl::~TempSensorChamberCtrl() {
if (_push) delete _push;
}

TempReading TempSensorChamberCtrl::read() {
TempReading reading = TEMP_READING_FAILED;
String url = myConfig.getChamberCtrlUrl();

if (url.length() > 0 || _push != NULL) {
String ret;

url += "/api/temps";

Log.notice(F("TEMP: Fetching temperature from %s." CR), url.c_str());

ret = _push->sendHttpGet(ret, url.c_str(), "", "");

if (_push->getLastResponseCode() == 200) {
Log.notice(F("TEMP: Data received %s." CR), ret.c_str());

DynamicJsonDocument doc(200);
DeserializationError err = deserializeJson(doc, ret);

/* This is the payload structure from BrewPI-ESP by Thorrak
{
"pid_beer_temp": 0,
"pid_fridge_temp": 19.5,
"pid_beer_target_temp": 0,
"pid_fridge_target_temp": 7,
"pid_temp_format": "C"
}
*/

if (!err) {
reading.temperature = doc["pid_fridge_temp"].as<float>();
_hasSensor = true;
return reading;
}
}
}

_hasSensor = false;
return reading;
}

// EOF
46 changes: 46 additions & 0 deletions src/temp_chamberctrl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
MIT License
Copyright (c) 2024 Magnus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef SRC_TEMP_CHAMBERCTRL_HPP_
#define SRC_TEMP_CHAMBERCTRL_HPP_

#include <basepush.hpp>
#include <temp_base.hpp>

class TempSensorChamberCtrl : public TempSensorBase {
private:
BasePush* _push = NULL;
bool _hasSensor = false;

public:
TempSensorChamberCtrl();
~TempSensorChamberCtrl();

void setup() override {}
bool hasSensor() override { return _hasSensor; }
TempReading read() override;
};

#endif // SRC_TEMP_CHAMBERCTRL_HPP_

// EOF
6 changes: 6 additions & 0 deletions src/temp_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SOFTWARE.
#include <kegconfig.hpp>
#include <temp_bme.hpp>
#include <temp_brewpi.hpp>
#include <temp_chamberctrl.hpp>
#include <temp_dht.hpp>
#include <temp_ds.hpp>
#include <temp_mgr.hpp>
Expand Down Expand Up @@ -64,6 +65,11 @@ void TempSensorManager::setup() {
_sensor.reset(new TempSensorBrewpi);
break;

case SensorChamberCtrl:
Log.info(F("TEMP: Initializing temp sensor Chamber Controller." CR));
_sensor.reset(new TempSensorChamberCtrl);
break;

default:
Log.error(F("TEMP: Unable to find sensor type, exiting." CR));
return;
Expand Down
6 changes: 6 additions & 0 deletions src_docs/source/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Releases
########

v1.1.0
======

* Added new integration to BrewLogger (TapList/Pour Logging)
* Added new integration to Chamber Controller (Temp Sensor)

v1.0.0
======

Expand Down

0 comments on commit acdebb7

Please sign in to comment.