Skip to content

Commit 4137dfe

Browse files
committed
Allow for different types of PWM outputs.
- Heater: classic dew heater with temperature sensor - Output: more generic PWM output Also removed InfluxDB push support, as the pull metrics endpoint is far simple and more reliable.
1 parent b85f61b commit 4137dfe

26 files changed

Lines changed: 434 additions & 489 deletions

platformio.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ lib_deps =
3636
robtillaart/INA219@^0.3.1
3737
sensirion/Sensirion I2C SHT4x@^1.1.0
3838
mathertel/OneButton@^2.6.1
39-
tobiasschuerg/ESP8266 Influxdb @ ^3.13.2
4039
arkhipenko/TaskScheduler@^3.8.5
4140
build_flags =
4241
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1

src/commandparser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CommandParser &CommandParser::Instance = *new CommandParser();
1010
CommandParser::CommandParser() {
1111
}
1212

13-
void CommandParser::getHeaters(JsonArray response) {
14-
Log.infoln(LOG_SCOPE "onGetHeaters: %d", Heaters::Instance.size());
15-
Heaters::toJson(response);
13+
void CommandParser::getPWMOutputs(JsonArray response) {
14+
Log.infoln(LOG_SCOPE "onGetPWMOutputs: %d", PWMOutputs::Instance.size());
15+
PWMOutputs::toJson(response);
1616
}

src/commandparser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CommandParser {
66
public:
77
CommandParser();
88
static CommandParser &Instance;
9-
void getHeaters(JsonArray response);
10-
void setHeaters(JsonVariant request);
9+
void getPWMOutputs(JsonArray response);
10+
void setPWMOutputs(JsonVariant request);
1111
};
1212
}

src/configuration.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,21 @@
1414
#define WIFIMANAGER_MAX_STATIONS 5
1515
#define APB_NETWORK_LOGGER_BACKLOG 20
1616
#define APB_AMBIENT_UPDATE_INTERVAL_SECONDS 5
17-
#define APB_HEATER_UPDATE_INTERVAL_SECONDS 5
17+
#define APB_PWM_OUTPUT_UPDATE_INTERVAL_SECONDS 5
1818
#define APB_AMBIENT_TEMPERATURE_SENSOR_I2C_ADDRESS 0x44
19-
#define APB_HEATER_TEMPERATURE_AVERAGE_COUNT 10
20-
#define APB_HEATER_TEMPERATURE_SENSOR_THERMISTOR_REFERENCE 10'000
21-
#define APB_HEATER_TEMPERATURE_SENSOR_THERMISTOR_NOMINAL 10'000
22-
#define APB_HEATER_TEMPERATURE_SENSOR_THERMISTOR_NOMINAL_TEMP 25
23-
#define APB_HEATER_TEMPERATURE_SENSOR_THERMISTOR_B_VALUE 3950
19+
#define APB_PWM_OUTPUT_TEMPERATURE_AVERAGE_COUNT 10
20+
#define APB_PWM_OUTPUT_TEMPERATURE_SENSOR_THERMISTOR_REFERENCE 10'000
21+
#define APB_PWM_OUTPUT_TEMPERATURE_SENSOR_THERMISTOR_NOMINAL 10'000
22+
#define APB_PWM_OUTPUT_TEMPERATURE_SENSOR_THERMISTOR_NOMINAL_TEMP 25
23+
#define APB_PWM_OUTPUT_TEMPERATURE_SENSOR_THERMISTOR_B_VALUE 3950
2424
#define APB_POWER_MAX_CURRENT_AMPS 8
2525
#define APB_POWER_SHUNT_OHMS 0.040
2626
#define APB_POWER_INA219_GAIN 8
2727
#define APB_POWER_INA219_VOLTAGE_RANGE 16
2828
#define APB_HISTORY_TASK_SECONDS 10'000
29-
#define APB_INFLUXDB_TASK_SECONDS 2'000
3029

3130
#define APB_AMBIENT_TEMPERATURE_SENSOR_SHT4x
32-
#define APB_HEATER_TEMPERATURE_SENSOR_THERMISTOR
31+
#define APB_PWM_OUTPUT_TEMPERATURE_SENSOR_THERMISTOR
3332

3433
#define APB_INA1219_ADDRESS 0x40
3534

src/configuration_lolin_c3_mini.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Thermistor PWM pinout. First number in a pair is the PWM pin (output), second thermistor PIN (analog input)
77
// Setting -1 for the thermistor indicates there's no thermistor available.
88
// IMPORTANT: there is no compiler check for pinout size, so be careful.
9-
#define APB_HEATERS_PWM_PINOUT Pinout{3,1},{4,0},{20,-1}
10-
#define APB_HEATERS_SIZE 3
11-
#define APB_HEATERS_TEMP_SENSORS 2
9+
#define APB_PWM_OUTPUTS_PWM_PINOUT {3,1,Heater},{4,0,Heater},{20,-1,Heater}
10+
#define APB_PWM_OUTPUTS_SIZE 3
11+
#define APB_PWM_OUTPUTS_TEMP_SENSORS 2
1212
#define ONEBUTTON_USER_BUTTON_1 21

src/configuration_lolin_s2_mini.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
// Thermistor PWM pinout. First number in a pair is the PWM pin (output), second thermistor PIN (analog input)
88
// IMPORTANT: there is no compiler check for pinout size, so be careful.
9-
#define APB_HEATERS_PWM_PINOUT Pinout{5,1}, Pinout{2,4}, {3,7}
10-
#define APB_HEATERS_SIZE 3
11-
#define APB_HEATERS_TEMP_SENSORS 3
9+
#define APB_PWM_OUTPUTS_PWM_PINOUT {5,1, Heater}, {2,4, Heater}, {3,7, Heater}
10+
#define APB_PWM_OUTPUTS_SIZE 3
11+
#define APB_PWM_OUTPUTS_TEMP_SENSORS 3

src/history.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ APB::History::History() {
1212
}
1313

1414

15-
#if APB_HEATERS_SIZE > 0
16-
void APB::History::Entry::PWMOutput::set(const APB::PWMOutput &heater) {
17-
temperatureHundredth = static_cast<int16_t>(heater.temperature().value_or(-100.0) * 100.0);
18-
duty = heater.active() ? heater.duty() : 0;
15+
#if APB_PWM_OUTPUTS_SIZE > 0
16+
void APB::History::Entry::PWMOutput::set(const APB::PWMOutput &pwmOutput) {
17+
temperatureHundredth = static_cast<int16_t>(pwmOutput.temperature().value_or(-100.0) * 100.0);
18+
duty = pwmOutput.active() ? pwmOutput.duty() : 0;
1919
}
2020
#endif
2121

@@ -45,14 +45,14 @@ void APB::History::Entry::populate(JsonObject object) {
4545
object["ambientDewpoint"] = static_cast<char*>(0);
4646
#endif
4747

48-
#if APB_HEATERS_SIZE > 0
49-
for(uint8_t i=0; i<heaters.size(); i++) {
50-
JsonObject heaterObject = object["heaters"][i].to<JsonObject>();;
51-
heaterObject["duty"] = heaters[i].getDuty();
52-
setNullableFloat(heaterObject, "temperature", heaters[i].getTemperature());
48+
#if APB_PWM_OUTPUTS_SIZE > 0
49+
for(uint8_t i=0; i<pwmOutputs.size(); i++) {
50+
JsonObject pwmOutput = object["pwmOutputs"][i].to<JsonObject>();;
51+
pwmOutput["duty"] = pwmOutputs[i].getDuty();
52+
setNullableFloat(pwmOutput, "temperature", pwmOutputs[i].getTemperature());
5353
}
5454
#else
55-
object["heaters"].to<JsonArray>();
55+
object["pwmOutputs"].to<JsonArray>();
5656
#endif
5757
object["busVoltage"] = getBusVoltage();
5858
object["power"] = getPower();
@@ -75,16 +75,16 @@ void APB::History::add() {
7575
}
7676

7777
APB::History::Entry entry {
78-
esp_timer_get_time() / 1000'000
78+
static_cast<uint32_t>(esp_timer_get_time() / 1000'000)
7979
};
8080

8181
#ifndef APB_AMBIENT_TEMPERATURE_SENSOR_NONE
8282
entry.setAmbient(APB::Ambient::Instance.reading());
8383
#endif
8484

85-
#if APB_HEATERS_SIZE > 0
86-
for(uint8_t i=0; i<APB_HEATERS_TEMP_SENSORS; i++) {
87-
entry.heaters[i].set(APB::Heaters::Instance[i]);
85+
#if APB_PWM_OUTPUTS_SIZE > 0
86+
for(uint8_t i=0; i<APB_PWM_OUTPUTS_TEMP_SENSORS; i++) {
87+
entry.pwmOutputs[i].set(APB::PWMOutputs::Instance[i]);
8888
}
8989
#endif
9090
entry.setPower(PowerMonitor::Instance.status());

src/history.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ class History {
2121
public:
2222
History();
2323
struct Entry {
24-
#if APB_HEATERS_SIZE > 0
24+
uint32_t secondsFromBoot;
25+
#if APB_PWM_OUTPUTS_SIZE > 0
2526
struct PWMOutput {
2627
int16_t temperatureHundredth;
2728
uint8_t duty;
28-
void set(const APB::PWMOutput &heater);
29+
void set(const APB::PWMOutput &pwmOutput);
2930
float getTemperature() const { return static_cast<float>(temperatureHundredth) / 100.0; }
3031
float getDuty() const { return static_cast<float>(duty); }
3132
};
32-
std::array<PWMOutput, APB_HEATERS_TEMP_SENSORS> heaters;
33+
std::array<PWMOutput, APB_PWM_OUTPUTS_TEMP_SENSORS> pwmOutputs;
3334
#endif
34-
uint32_t secondsFromBoot;
35+
3536
#ifndef APB_AMBIENT_TEMPERATURE_SENSOR_NONE
3637
void setAmbient(const std::optional<Ambient::Reading> &reading);
3738
float getAmbientTemperature() const { return static_cast<float>(ambientTemperatureHundredth) / 100.0; }

src/influxdb.cpp

Lines changed: 0 additions & 99 deletions
This file was deleted.

src/influxdb.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)