2020-10-18 13:10:12 +01:00
|
|
|
/*
|
|
|
|
xsns_78_ezoph.ino - EZO pH I2C pH sensor support for Tasmota
|
|
|
|
|
2021-01-01 12:44:04 +00:00
|
|
|
Copyright (C) 2021 Christopher Tremblay
|
2020-10-18 13:10:12 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_I2C
|
|
|
|
#ifdef USE_EZOPH
|
|
|
|
|
|
|
|
#define EZO_PH_READ_LATENCY 900
|
|
|
|
|
2020-10-26 07:09:44 +00:00
|
|
|
struct EZOPH : public EZOStruct {
|
|
|
|
EZOPH(uint32_t addr) : EZOStruct(addr), pH(NAN) {}
|
2020-10-23 11:47:24 +01:00
|
|
|
|
|
|
|
virtual void ProcessMeasurement(void)
|
2020-10-18 13:10:12 +01:00
|
|
|
{
|
|
|
|
char data[D_EZO_MAX_BUF];
|
|
|
|
|
|
|
|
EZOStruct::ProcessMeasurement(data, sizeof(data), EZO_PH_READ_LATENCY);
|
|
|
|
pH = CharToFloat(data);
|
|
|
|
}
|
|
|
|
|
2020-10-23 11:47:24 +01:00
|
|
|
virtual void Show(bool json, const char *name)
|
2020-10-18 13:10:12 +01:00
|
|
|
{
|
2020-10-23 11:47:24 +01:00
|
|
|
char str[6];
|
|
|
|
dtostrfd(pH, 2, str);
|
2020-10-18 13:10:12 +01:00
|
|
|
|
2020-10-23 11:47:24 +01:00
|
|
|
if (json) {
|
|
|
|
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_PH "\":%s}" ), name, str);
|
|
|
|
}
|
2021-01-01 12:44:04 +00:00
|
|
|
#ifdef USE_WEBSERVER
|
2020-10-23 11:47:24 +01:00
|
|
|
else {
|
|
|
|
WSContentSend_PD(HTTP_SNS_PH, name, str);
|
2020-10-18 13:10:12 +01:00
|
|
|
#endif // USE_WEBSERVER
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 07:09:44 +00:00
|
|
|
static const char id[] PROGMEM;
|
|
|
|
|
2020-10-18 13:10:12 +01:00
|
|
|
private:
|
2020-10-23 11:47:24 +01:00
|
|
|
float pH;
|
2020-10-18 13:10:12 +01:00
|
|
|
};
|
|
|
|
|
2020-10-26 07:09:44 +00:00
|
|
|
const char EZOPH::id[] PROGMEM = "pH";
|
|
|
|
|
2020-10-18 13:10:12 +01:00
|
|
|
#endif // USE_EZOPH
|
|
|
|
#endif // USE_I2C
|