fix mhz19 calibration handler

This commit is contained in:
interfisch 2021-11-08 20:21:50 +01:00
parent 310fb73fba
commit 875a7c0101
3 changed files with 35 additions and 31 deletions

View File

@ -66,25 +66,7 @@ void Sensor_MHZ19B::setSettings(float minchange, unsigned long senddelaymax, uns
} }
bool Sensor_MHZ19B::mhz19calibrationHandler(const HomieRange& range, const String& value) {
if (range.isRange) {
return false; //if range is given but index is not in allowed range
}
Homie.getLogger() << "mhz19 calibration " << ": " << value << endl;
if (value=="zero") {
mhz19->calibrateZero();
Homie.getLogger() << "mhz19 calibration " << ": " << value << endl;
#ifdef STATUSNODE
sensorNode->setProperty("status").send("MHZ19 Zero Calibration triggered");
#endif
} else {
Homie.getLogger() << "Value outside range" << endl;
return false;
}
return true;
}
//Called during setup //Called during setup
void Sensor_MHZ19B::advertise(HomieNode& p_sensorNode) void Sensor_MHZ19B::advertise(HomieNode& p_sensorNode)
@ -92,7 +74,7 @@ void Sensor_MHZ19B::advertise(HomieNode& p_sensorNode)
sensorNode = &p_sensorNode; sensorNode = &p_sensorNode;
sensorNode->advertise("co2"); sensorNode->advertise("co2");
#ifdef MHZ19CALIBRATIONTOPIC #ifdef MHZ19CALIBRATIONTOPIC
sensorNode->advertise("mhz19calibration").settable(&Sensor_MHZ19B::mhz19calibrationHandler)); //not working!!! TODO: Fix it sensorNode->advertise("mhz19calibration").settable(mhz19calibrationHandler);
#endif #endif
} }
@ -169,4 +151,6 @@ int Sensor_MHZ19B::mhz19_readValue_reimplemented(Stream *_streamRef, MHZ19 *_mhz
return co2; return co2;
} }
void Sensor_MHZ19B::calibrateZero() {
mhz19->calibrateZero();
}

View File

@ -33,7 +33,7 @@ private:
//#define MHZ19CALIBRATIONTOPIC //TODO: fix it #define MHZ19CALIBRATIONTOPIC
public: public:
Sensor_MHZ19B(int prx, int ptx); Sensor_MHZ19B(int prx, int ptx);
@ -41,10 +41,9 @@ public:
void init(); void init();
void setSettings(float minchange, unsigned long senddelaymax, unsigned long readdelay); void setSettings(float minchange, unsigned long senddelaymax, unsigned long readdelay);
void advertise(HomieNode& p_sensorNode); void advertise(HomieNode& p_sensorNode);
void sensorloop(); void sensorloop();
bool mhz19calibrationHandler(const HomieRange& range, const String& value); void calibrateZero();
}; };
#endif #endif

View File

@ -21,6 +21,12 @@
#define STATUSNODE #define STATUSNODE
// data/homie/config.json hochladen mit platformio run --target uploadfs
// config contains homie device name, mqtt ip and wifi credentials
HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type
#include "sensordata.h" #include "sensordata.h"
@ -189,9 +195,30 @@
#endif #endif
#ifdef SENSOR_MHZ19B #ifdef SENSOR_MHZ19B
bool mhz19calibrationHandler(const HomieRange& range, const String& value);
#include "sensor_mhz19b.cpp" #include "sensor_mhz19b.cpp"
Sensor_MHZ19B sensor_mhz19b(SENSOR_MHZ19B_SERIAL_RX,SENSOR_MHZ19B_SERIAL_TX); Sensor_MHZ19B sensor_mhz19b(SENSOR_MHZ19B_SERIAL_RX,SENSOR_MHZ19B_SERIAL_TX);
bool mhz19calibrationHandler(const HomieRange& range, const String& value) {
if (range.isRange) {
return false; //if range is given but index is not in allowed range
}
Homie.getLogger() << "mhz19 calibration " << ": " << value << endl;
if (value=="zero") {
sensor_mhz19b.calibrateZero();//mhz19->calibrateZero();
Homie.getLogger() << "mhz19 calibration " << ": " << value << endl;
#ifdef STATUSNODE
sensorNode.setProperty("status").send("MHZ19 Zero Calibration triggered");
#endif
} else {
Homie.getLogger() << "Value outside range" << endl;
return false;
}
return true;
}
#ifndef SENSOR_MHZ19B_minchange #ifndef SENSOR_MHZ19B_minchange
#define SENSOR_MHZ19B_minchange 10.0 #define SENSOR_MHZ19B_minchange 10.0
#endif #endif
@ -317,12 +344,6 @@
#endif #endif
// data/homie/config.json hochladen mit platformio run --target uploadfs
// config contains homie device name, mqtt ip and wifi credentials
HomieNode sensorNode("sensors", "Sensors","sensors"); //id, name, type
char tempstring[16]; //for dtostrf char tempstring[16]; //for dtostrf