This commit is contained in:
2021-02-05 15:46:21 +01:00
parent c9004e13cb
commit d06fc52b38
3 changed files with 17 additions and 9 deletions

View File

@@ -2,8 +2,6 @@
FanStateService::FanStateService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, AsyncMqttClient* mqttClient, FanMqttSettingsService* fanMQTTSettingsService) : FanStateService::FanStateService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, AsyncMqttClient* mqttClient, FanMqttSettingsService* fanMQTTSettingsService) :
_httpEndpoint(FanState::read, _httpEndpoint(FanState::read,
FanState::update, FanState::update,
@@ -12,7 +10,7 @@ FanStateService::FanStateService(AsyncWebServer* server, FS* fs, SecurityManager
FAN_SETTINGS_ENDPOINT_PATH, FAN_SETTINGS_ENDPOINT_PATH,
securityManager, securityManager,
AuthenticationPredicates::IS_AUTHENTICATED), AuthenticationPredicates::IS_AUTHENTICATED),
_mqttPubSub(FanState::haRead, FanState::haUpdate, this, mqttClient), _mqttPubSub(FanState::haRead, FanState::haUpdate, this, mqttClient,"testmqtt1/set","testmqtt1/state"),
_fsPersistence(FanState::read, _fsPersistence(FanState::read,
FanState::update, FanState::update,
this, this,
@@ -64,8 +62,12 @@ void FanStateService::compute() {
unsigned long period = millis() - this->lastpoll; unsigned long period = millis() - this->lastpoll;
this->sensor_intake.requestTemperatures(); this->sensor_intake.requestTemperatures();
this->Tin = this->sensor_intake.getTempCByIndex(0); this->Tin = this->sensor_intake.getTempCByIndex(0);
this->Tout = this->sensor_intake.getTempCByIndex(1); this->Tout = this->sensor_intake.getTempCByIndex(1);
float curRpm = 60000/period*this->RPM/2; // Hall sensor = 2 tick per rotation this->RPM = 60000/period*this->ROT/2; // Hall sensor = 2 tick per rotation
Serial.print("Intake: " + (String) this->Tin + " - " + (String) this->Tout + " [ "+ (String) curRpm + " RPM ]\n"); Serial.print("Intake: " + (String) this->Tin + " - " + (String) this->Tout + " [ "+ (String) this->RPM + " RPM ]\n");
this->RPM=0; this->ROT=0;
this->_mqttPubSub.setPubTopic("testmqtt1/state");
} }

View File

@@ -77,7 +77,9 @@ class FanState {
int newThresLow = root["temperature_thres_low"] | DEFAULT_THRES_LOW; int newThresLow = root["temperature_thres_low"] | DEFAULT_THRES_LOW;
int newThresHigh = root["temperature_thres_high"] | DEFAULT_THRES_HIGH; int newThresHigh = root["temperature_thres_high"] | DEFAULT_THRES_HIGH;
int newOneWireGPIO = root["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 + "]"); Serial.println(" ** Fan update [status:" + (String)newFanState + "|gpio:" + (String)newFanPwmGPIO + "|mxspd:" + (String)newMaxSpeed + "|low:" + (String)newThresLow + "|high:" + (String)newThresHigh + "]");
*/
if ( fanState.fanStatus != newFanState if ( fanState.fanStatus != newFanState
|| fanState.fanPwmGPIO != newFanPwmGPIO || fanState.fanPwmGPIO != newFanPwmGPIO
|| fanState.fanTachGPIO != newFanTachGPIO || fanState.fanTachGPIO != newFanTachGPIO
@@ -100,7 +102,10 @@ class FanState {
} }
static void haRead(FanState& settings, JsonObject& root) { static void haRead(FanState& settings, JsonObject& root) {
root["state"] = settings.fanStatus ? ON_STATE : OFF_STATE; root["state"] = settings.fanStatus ? ON_STATE : OFF_STATE;
root["Tinput"] = settings.sensorInTemp;
root["Toutput"] = settings.sensorOutTemp;
root["RPM"] = settings.fanSpeed;
String s = root["state"]; String s = root["state"];
Serial.println(" ** Fan haRead [" + s + "]"); Serial.println(" ** Fan haRead [" + s + "]");
} }
@@ -132,7 +137,8 @@ class FanStateService : public StatefulService<FanState> {
float Tout; float Tout;
OneWire oneWire1; OneWire oneWire1;
DallasTemperature sensor_intake; DallasTemperature sensor_intake;
unsigned int RPM; float RPM;
unsigned int ROT;
FanStateService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, AsyncMqttClient* mqttClient, FanMqttSettingsService* fanMQTTSettingsService); FanStateService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, AsyncMqttClient* mqttClient, FanMqttSettingsService* fanMQTTSettingsService);

View File

@@ -32,7 +32,7 @@ FanStateService fanStateService = FanStateService (
void ICACHE_RAM_ATTR handleInterrupt() { void ICACHE_RAM_ATTR handleInterrupt() {
fanStateService.RPM++; fanStateService.ROT++;
} }