diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index 40475c7..da3aa1e 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -134,21 +134,21 @@ void setup() ArduinoOTA.setPassword(ota_password); ArduinoOTA.onStart([]() { - Serial.println("Start"); + trc(F("Start")); }); ArduinoOTA.onEnd([]() { - Serial.println("\nEnd"); + trc(F("\nEnd")); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }); ArduinoOTA.onError([](ota_error_t error) { Serial.printf("Error[%u]: ", error); - if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); - else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); - else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); - else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); - else if (error == OTA_END_ERROR) Serial.println("End Failed"); + if (error == OTA_AUTH_ERROR) trc(F("Auth Failed")); + else if (error == OTA_BEGIN_ERROR) trc(F("Begin Failed")); + else if (error == OTA_CONNECT_ERROR) trc(F("Connect Failed")); + else if (error == OTA_RECEIVE_ERROR) trc(F("Receive Failed")); + else if (error == OTA_END_ERROR) trc(F("End Failed")); }); ArduinoOTA.begin(); #else @@ -247,6 +247,9 @@ void loop() #ifdef ZsensorDHT MeasureTempAndHum(); //Addon to measure the temperature with a DHT #endif + #ifdef ZsensorADC + MeasureADC(); //Addon to measure the analog value of analog pin + #endif // Receive loop, if data received by RF433 or IR send it by MQTT #ifdef ZgatewayRF boolean resultRF = RFtoMQTT(); diff --git a/User_config.h b/User_config.h index 3f11aa6..5032792 100644 --- a/User_config.h +++ b/User_config.h @@ -74,6 +74,8 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress #include "config_IR.h" #define ZgatewayBT #include "config_BT.h" + #define ZsensorADC + #include "config_ADC.h" #define ZsensorBH1750 #include "config_BH1750.h" #define ZsensorBME280 @@ -98,6 +100,8 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress //#include "config_BH1750.h" //#define ZsensorBME280 //#include "config_BME280.h" + //#define ZsensorADC + //#include "config_ADC.h" //#define ZgatewayRFM69 not tested //#include "config_RFM69.h" #endif diff --git a/ZsensorADC.ino b/ZsensorADC.ino new file mode 100644 index 0000000..2480e6d --- /dev/null +++ b/ZsensorADC.ino @@ -0,0 +1,59 @@ +/* + OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation + + Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker + Send and receiving command by MQTT + + Analog pin reading Addon + + Copyright: (c)Florian ROBERT + + Contributors: + - 1technophile + + 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 . +*/ +#ifdef ZsensorADC + +#ifdef ESP8266 + ADC_MODE(ADC_TOUT); +#endif + +//Time used to wait for an interval before resending adc value +unsigned long timeadc = 0; + +void MeasureADC(){ + if (millis() > (timeadc + TimeBetweenReadingADC)) {//retriving value of temperature and humidity of the box from DHT every xUL + timeadc = millis(); + static int persistedadc; + int val = analogRead(ADC_PIN); + + if (isnan(val)) { + trc(F("Failed to read from ADC !")); + }else{ + if(val >= persistedadc + ThresholdReadingADC || val <= persistedadc - ThresholdReadingADC){ + char value[4]; + sprintf(value, "%d", val); + trc(F("Sending analog value to MQTT")); + trc(String(val)); + client.publish(ADC,value); + persistedadc = val; + } + } + } +} +#endif + diff --git a/config_ADC.h b/config_ADC.h new file mode 100644 index 0000000..00c9f9e --- /dev/null +++ b/config_ADC.h @@ -0,0 +1,37 @@ +/* + OpenMQTTGateway - ESP8266 or Arduino program for home automation + + Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker + Send and receiving command by MQTT + + This files enables to set your parameter for the ADC value + + Copyright: (c)Florian ROBERT + + 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 . +*/ + +/*----------------------------USER PARAMETERS-----------------------------*/ +/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ +#define ADC "home/ADCtoMQTT" +#define TimeBetweenReadingADC 0 // time between 2 ADC readings, can be 0 if you want only the threshold to trigger sending +#define ThresholdReadingADC 50 // following the comparison between the previous value and the current one +- the threshold the value will be published or not + +/*-------------------PIN DEFINITIONS----------------------*/ +#define ADC_PIN A0 //on nodeMCU this is D3 GPIO0 + + +