mirror of
https://github.com/1technophile/OpenMQTTGateway.git
synced 2026-03-09 08:47:18 +01:00
* Update arduino core to 3.1.1 * Fix Blufi build * Update arduinojson, fix build errors with idf * Fix narrowing * fix RF builds * WIP-Convert ino files to cpp * Fix pilight build * Fix Somfy actuator build. * Update esp32dev-rf partition * Fix Weatherstation build * Fix GFSunInverter build * Fix esp32dev-ir build * Fix ble-aws build * Fix eth builds * Fix m5Stack missing pins_arduino.h * Fix build errors for M5 stack/tough, others are upstream issues. * Fix RTL 433 build - remaining errors are from radolib * Fix nodemcu build * fix 2g builds * Fix serial build * Fix actuator on off builds * Fix SSD1306 build - remaining errors are from radiolib * Fix multiple definition of OTAserver_cert * Fix nodemcu rf2 build * Fix ADC builds * Fix sensor builds * Fix LORA builds * Fix multi-receiver builds - remaining errors are in radiolib * Fix fastled builds * Fix theegns board builds * Fix broker builds * Update fastled - old version failed all-test build * Fix RN8209 builds * Fix max temp actuator builds * Fix PWM builds * Fix C37 sensor builds * Fix HTU21 builds * Fix INA266 builds * Fix undefined variables in mqtt discovery * Fix webui build * Fix fastled invalid pin error * Fix wifi manual setup builds * Fix onewire/all-test build - bin too big error remaining * Fix theengs plug build * Fix rfbridge builds * Fix blufi builds * Fix undefined functions in serial * Fix preprocessor definition checks * Set IDF log level to erre * Add delay in loop to prevent watchdog timeout * Use xTaskCreateUniveral to support single core processors * Remove old HTTPUpdate files - upsteam fixed. * Cleanup and move common declarations to header file * Use custom partiton table to fix builds where bin is too large * Update M5StickC - fixs esp32-m5stick-c-ble build * Revert to Arduino core 2.x for builds with incompatible libs * Remove "Z" from file names and rename omg_common to TheengsCommon * Fix gateway name when using MAC with new Arduino core * Update IDF config to reduce loop task stack use * Update esp-nimble-cpp version, corrects BLE uppercase ID's * Update wifi manager to fix watchdog timeout error
83 lines
3.2 KiB
C++
83 lines
3.2 KiB
C++
/*
|
|
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
|
|
|
Act as a wifi or ethernet gateway between your 433mhz/infrared IR/BLE signal and a MQTT broker
|
|
Send and receiving command by MQTT
|
|
|
|
This file sets parameters for the integration of C-37 YL-83 HM-RD water detection sensors
|
|
|
|
This file is part of OpenMQTTGateway.
|
|
|
|
OpenMQTTGateway 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.
|
|
|
|
OpenMQTTGateway 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/>.
|
|
*/
|
|
#include "User_config.h"
|
|
|
|
#ifdef ZsensorC37_YL83_HMRD
|
|
# include "TheengsCommon.h"
|
|
# include "config_C37_YL83_HMRD.h"
|
|
|
|
//Time used to wait for an interval before resending temp and hum
|
|
unsigned long timeC37YL83HMRD = 0;
|
|
unsigned int persistedanalog = 0;
|
|
unsigned int persisteddigital = 0;
|
|
|
|
void setupZsensorC37_YL83_HMRD() {
|
|
pinMode(C37_YL83_HMRD_Digital_GPIO, INPUT);
|
|
Log.trace(F("C37_YL83_HMRD: digital configured pin: %d" CR), C37_YL83_HMRD_Digital_GPIO);
|
|
|
|
pinMode(C37_YL83_HMRD_Analog_GPIO, INPUT);
|
|
Log.trace(F("C37_YL83_HMRD: Analog configured pin: %d" CR), C37_YL83_HMRD_Analog_GPIO);
|
|
|
|
# ifdef C37_YL83_HMRD_Analog_RESOLUTION
|
|
analogReadResolution(C37_YL83_HMRD_Analog_RESOLUTION);
|
|
Log.trace(F("C37_YL83_HMRD: resolution: %d" CR), C37_YL83_HMRD_Analog_RESOLUTION);
|
|
# endif
|
|
}
|
|
|
|
void MeasureC37_YL83_HMRDWater() {
|
|
if (millis() > (timeC37YL83HMRD + C37_YL83_HMRD_INTERVAL_SEC)) { //retrieving value of water sensor every xUL
|
|
timeC37YL83HMRD = millis();
|
|
static int persistedanalog;
|
|
static int persisteddigital;
|
|
|
|
int sensorDigitalValue = digitalRead(C37_YL83_HMRD_Digital_GPIO); // Read the analog value from sensor
|
|
int sensorAnalogValue = analogRead(C37_YL83_HMRD_Analog_GPIO);
|
|
|
|
Log.trace(F("Creating C37_YL83_HMRD buffer" CR));
|
|
StaticJsonDocument<JSON_MSG_BUFFER> C37_YL83_HMRDdataBuffer;
|
|
JsonObject C37_YL83_HMRDdata = C37_YL83_HMRDdataBuffer.to<JsonObject>();
|
|
if (sensorDigitalValue != persisteddigital || C37_YL83_HMRD_ALWAYS) {
|
|
C37_YL83_HMRDdata["detected"] = (sensorDigitalValue == 1 ? "false" : "true");
|
|
} else {
|
|
Log.trace(F("Same digital don't send it" CR));
|
|
}
|
|
if (sensorAnalogValue != persistedanalog || C37_YL83_HMRD_ALWAYS) {
|
|
C37_YL83_HMRDdata["reading"] = sensorAnalogValue;
|
|
} else {
|
|
Log.trace(F("Same analog don't send it" CR));
|
|
}
|
|
if (C37_YL83_HMRDdata.size() > 0) {
|
|
C37_YL83_HMRDdata["origin"] = C37_YL83_HMRD_TOPIC;
|
|
enqueueJsonObject(C37_YL83_HMRDdata);
|
|
if (sensorDigitalValue == 1) { //No water detected, all good we can sleep
|
|
if (SYSConfig.powerMode > 0)
|
|
ready_to_sleep = true;
|
|
}
|
|
}
|
|
persistedanalog = sensorAnalogValue;
|
|
persisteddigital = sensorDigitalValue;
|
|
}
|
|
}
|
|
#endif
|