This commit is contained in:
2021-02-02 09:21:44 +01:00
parent 0287da7ff5
commit 7535042f9a
3 changed files with 60 additions and 22 deletions

View File

@@ -4,16 +4,15 @@
#include <FSPersistence.h>
#include <HttpEndpoint.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define FAN_PIN 13
#define PRINT_DELAY 5000
#define DEFAULT_FAN_STATE false
#define DEFAULT_FAN_PWM_GPIO 13
#define DEFAULT_FAN_PWM_GPIO 12
#define DEFAULT_FAN_TACH_GPIO 13
#define DEFAULT_ONEWIRE_GPIO 16
#define DEFAULT_ONEWIRE_GPIO 14
#define DEFAULT_THRES_LOW 25
#define DEFAULT_THRES_HIGH 70
#define DEFAULT_FAN_MAX_SPEED 1021
@@ -51,8 +50,7 @@ class FanSettings {
static void read(FanSettings& settings, JsonObject& root) {
root["oneWire_gpio"] = settings.OneWireGPIO;
root["sensor_in_temp"] = settings.sensorInTemp;
root["sensor_out_temp"] = settings.sensorOutTemp;
root["sensor_out_temp"] = settings.sensorOutTemp;
root["fan_status"] = settings.fanStatus;
root["fan_pwm_gpio"] = settings.fanPwmGPIO;
root["fan_tach_gpio"] = settings.fanTachGPIO;
@@ -61,10 +59,12 @@ class FanSettings {
root["temperature_thres_high"] = settings.thresHigh;
// String s = (String)root["fan_status"] + "|" + (String)root["fan_gpio"] + "|" + (String)root["fan_max_speed"] + "|" + (String)root["temperature_thres_low"] + "|" + (String)root["temperature_thres_high"];
String s = root["fan_status"]; Serial.println(" ** Fan read [fan_status : " + s + "]");
String t = root["fan_gpio"]; Serial.println(" ** Fan read [fan_gpio : " + t + "]");
String u = root["fan_max_speed"]; Serial.println(" ** Fan read [fan_max_speed : " + u + "]");
String v = root["temperature_thres_low"]; Serial.println(" ** Fan read [temperature_thres_low : " + v + "]");
String w = root["temperature_thres_high"]; Serial.println(" ** Fan read [temperature_thres_high : " + w + "]");
String t = root["fan_pwm_gpio"]; Serial.println(" ** Fan read [fan_pwm_gpio : " + t + "]");
String u = root["fan_tach_gpio"]; Serial.println(" ** Fan read [fan_tach_gpio : " + u + "]");
String v = root["fan_max_speed"]; Serial.println(" ** Fan read [fan_max_speed : " + v + "]");
String w = root["temperature_thres_low"]; Serial.println(" ** Fan read [temperature_thres_low : " + w + "]");
String x = root["temperature_thres_high"]; Serial.println(" ** Fan read [temperature_thres_high : " + x + "]");
String y = root["oneWire_gpio"]; Serial.println(" ** Fan read [oneWire_gpio : " + y + "]");
}
static StateUpdateResult update(JsonObject& root, FanSettings& fanState) {
@@ -74,7 +74,7 @@ class FanSettings {
int newMaxSpeed = root["fan_max_speed"] | DEFAULT_FAN_MAX_SPEED;
int newThresLow = root["temperature_thres_low"] | DEFAULT_THRES_LOW;
int newThresHigh = root["temperature_thres_high"] | DEFAULT_THRES_HIGH;
int newOneWireGPIO = root["sensor_onewire_gpio"] | DEFAULT_ONEWIRE_GPIO;
int newOneWireGPIO = root["oneWire_gpio"] | DEFAULT_ONEWIRE_GPIO;
Serial.println(" ** Fan update [status:" + (String)newFanState + "|gpio:" + (String)newFanPwmGPIO + "|mxspd:" + (String)newMaxSpeed + "|low:" + (String)newThresLow + "|high:" + (String)newThresHigh + "]");
if ( fanState.fanStatus != newFanState
|| fanState.fanPwmGPIO != newFanPwmGPIO
@@ -125,9 +125,20 @@ class FanSettings {
class FanStateService : public StatefulService<FanSettings> {
public:
unsigned long lastpoll;
float Tin;
float Tout;
OneWire oneWire1;
DallasTemperature sensor_intake;
unsigned int RPM;
FanStateService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
void begin();
void save();
void compute();
void SetLastPoll(unsigned long l);
int getTachGPIO();
private:
HttpEndpoint<FanSettings> _httpEndpoint;