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) :
_httpEndpoint(FanState::read,
FanState::update,
@@ -12,7 +10,7 @@ FanStateService::FanStateService(AsyncWebServer* server, FS* fs, SecurityManager
FAN_SETTINGS_ENDPOINT_PATH,
securityManager,
AuthenticationPredicates::IS_AUTHENTICATED),
_mqttPubSub(FanState::haRead, FanState::haUpdate, this, mqttClient),
_mqttPubSub(FanState::haRead, FanState::haUpdate, this, mqttClient,"testmqtt1/set","testmqtt1/state"),
_fsPersistence(FanState::read,
FanState::update,
this,
@@ -64,8 +62,12 @@ void FanStateService::compute() {
unsigned long period = millis() - this->lastpoll;
this->sensor_intake.requestTemperatures();
this->Tin = this->sensor_intake.getTempCByIndex(0);
this->Tout = this->sensor_intake.getTempCByIndex(1);
float curRpm = 60000/period*this->RPM/2; // Hall sensor = 2 tick per rotation
Serial.print("Intake: " + (String) this->Tin + " - " + (String) this->Tout + " [ "+ (String) curRpm + " RPM ]\n");
this->RPM=0;
this->RPM = 60000/period*this->ROT/2; // Hall sensor = 2 tick per rotation
Serial.print("Intake: " + (String) this->Tin + " - " + (String) this->Tout + " [ "+ (String) this->RPM + " RPM ]\n");
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 newThresHigh = root["temperature_thres_high"] | DEFAULT_THRES_HIGH;
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
|| fanState.fanTachGPIO != newFanTachGPIO
@@ -101,6 +103,9 @@ class FanState {
static void haRead(FanState& settings, JsonObject& root) {
root["state"] = settings.fanStatus ? ON_STATE : OFF_STATE;
root["Tinput"] = settings.sensorInTemp;
root["Toutput"] = settings.sensorOutTemp;
root["RPM"] = settings.fanSpeed;
String s = root["state"];
Serial.println(" ** Fan haRead [" + s + "]");
}
@@ -132,7 +137,8 @@ class FanStateService : public StatefulService<FanState> {
float Tout;
OneWire oneWire1;
DallasTemperature sensor_intake;
unsigned int RPM;
float RPM;
unsigned int ROT;
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() {
fanStateService.RPM++;
fanStateService.ROT++;
}