ADC pin reading (#106)
* ADC pin reading #95 * arduino and always flag correction * optimize sram use and remove adc sensor option per default * integrate a threshold
This commit is contained in:
1 parent
d7ebd123d1
commit
c915ddfa48
4 files changed
+110
-7
No files matched your search
+10
-7
@@ -134,21 +134,21 @@ void setup()
|
|||||||
ArduinoOTA.setPassword(ota_password);
|
ArduinoOTA.setPassword(ota_password);
|
||||||
|
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
Serial.println("Start");
|
trc(F("Start"));
|
||||||
});
|
});
|
||||||
ArduinoOTA.onEnd([]() {
|
ArduinoOTA.onEnd([]() {
|
||||||
Serial.println("\nEnd");
|
trc(F("\nEnd"));
|
||||||
});
|
});
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||||
});
|
});
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
Serial.printf("Error[%u]: ", error);
|
Serial.printf("Error[%u]: ", error);
|
||||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
if (error == OTA_AUTH_ERROR) trc(F("Auth Failed"));
|
||||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
else if (error == OTA_BEGIN_ERROR) trc(F("Begin Failed"));
|
||||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
else if (error == OTA_CONNECT_ERROR) trc(F("Connect Failed"));
|
||||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
else if (error == OTA_RECEIVE_ERROR) trc(F("Receive Failed"));
|
||||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
else if (error == OTA_END_ERROR) trc(F("End Failed"));
|
||||||
});
|
});
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
#else
|
#else
|
||||||
@@ -247,6 +247,9 @@ void loop()
|
|||||||
#ifdef ZsensorDHT
|
#ifdef ZsensorDHT
|
||||||
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
|
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
|
||||||
#endif
|
#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
|
// Receive loop, if data received by RF433 or IR send it by MQTT
|
||||||
#ifdef ZgatewayRF
|
#ifdef ZgatewayRF
|
||||||
boolean resultRF = RFtoMQTT();
|
boolean resultRF = RFtoMQTT();
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#include "config_IR.h"
|
#include "config_IR.h"
|
||||||
#define ZgatewayBT
|
#define ZgatewayBT
|
||||||
#include "config_BT.h"
|
#include "config_BT.h"
|
||||||
|
#define ZsensorADC
|
||||||
|
#include "config_ADC.h"
|
||||||
#define ZsensorBH1750
|
#define ZsensorBH1750
|
||||||
#include "config_BH1750.h"
|
#include "config_BH1750.h"
|
||||||
#define ZsensorBME280
|
#define ZsensorBME280
|
||||||
@@ -98,6 +100,8 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
//#include "config_BH1750.h"
|
//#include "config_BH1750.h"
|
||||||
//#define ZsensorBME280
|
//#define ZsensorBME280
|
||||||
//#include "config_BME280.h"
|
//#include "config_BME280.h"
|
||||||
|
//#define ZsensorADC
|
||||||
|
//#include "config_ADC.h"
|
||||||
//#define ZgatewayRFM69 not tested
|
//#define ZgatewayRFM69 not tested
|
||||||
//#include "config_RFM69.h"
|
//#include "config_RFM69.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#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
|
||||||
|
|
||||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user