GPIOInput Third Time is a Charm! (#258)
* Added 2 files via upload * Update OpenMQTTGateway.ino * Update Test_config.h
This commit is contained in:
1 parent
19c89d9dc8
commit
0f118c2020
4 files changed
+132
-1
No files matched your search
+12
-1
@@ -106,7 +106,9 @@
|
|||||||
#ifdef ZgatewayRFM69
|
#ifdef ZgatewayRFM69
|
||||||
#include "config_RFM69.h"
|
#include "config_RFM69.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZsensorGPIOInput
|
||||||
|
#include "config_GPIOInput.h"
|
||||||
|
#endif
|
||||||
// array to store previous received RFs, IRs codes and their timestamps
|
// array to store previous received RFs, IRs codes and their timestamps
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
#define array_size 12
|
#define array_size 12
|
||||||
@@ -370,6 +372,9 @@ void setup()
|
|||||||
#ifdef ZsensorHCSR501
|
#ifdef ZsensorHCSR501
|
||||||
setupHCSR501();
|
setupHCSR501();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZsensorGPIOInput
|
||||||
|
setupGPIOInput();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -606,6 +611,9 @@ void loop()
|
|||||||
#ifdef ZsensorHCSR501
|
#ifdef ZsensorHCSR501
|
||||||
MeasureHCSR501();
|
MeasureHCSR501();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZsensorGPIOInput
|
||||||
|
MeasureGPIOInput();
|
||||||
|
#endif
|
||||||
#ifdef ZsensorADC
|
#ifdef ZsensorADC
|
||||||
MeasureADC(); //Addon to measure the analog value of analog pin
|
MeasureADC(); //Addon to measure the analog value of analog pin
|
||||||
#endif
|
#endif
|
||||||
@@ -733,6 +741,9 @@ void stateMeasures(){
|
|||||||
#ifdef ZsensorHCSR501
|
#ifdef ZsensorHCSR501
|
||||||
modules = modules + ZsensorHCSR501;
|
modules = modules + ZsensorHCSR501;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZsensorGPIOInput
|
||||||
|
modules = modules + ZsensorGPIOInput;
|
||||||
|
#endif
|
||||||
SYSdata["modules"] = modules;
|
SYSdata["modules"] = modules;
|
||||||
trc(modules);
|
trc(modules);
|
||||||
char JSONmessageBuffer[100];
|
char JSONmessageBuffer[100];
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
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
|
||||||
|
|
||||||
|
GPIO Input derived from HC SR-501 reading Addon and https://www.arduino.cc/en/Tutorial/Debounce
|
||||||
|
|
||||||
|
This reads a high (open) or low (closed) through a circuit (switch, float sensor, etc.) connected to ground.
|
||||||
|
|
||||||
|
Copyright: (c)Florian ROBERT
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
- 1technophile
|
||||||
|
- QuagmireMan
|
||||||
|
|
||||||
|
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 ZsensorGPIOInput
|
||||||
|
|
||||||
|
unsigned long lastDebounceTime = 0;
|
||||||
|
int InputState = 3; // Set to 3 so that it reads on startup
|
||||||
|
int lastInputState = 3;
|
||||||
|
|
||||||
|
|
||||||
|
void setupGPIOInput() {
|
||||||
|
pinMode(GPIOInput_PIN, INPUT_PULLUP); // declare GPIOInput pin as input_pullup to prevent floating. Pin will be high when not connected to ground
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureGPIOInput(){
|
||||||
|
int reading = digitalRead(GPIOInput_PIN);
|
||||||
|
|
||||||
|
// check to see if you just pressed the button
|
||||||
|
// (i.e. the input went from LOW to HIGH), and you've waited long enough
|
||||||
|
// since the last press to ignore any noise:
|
||||||
|
|
||||||
|
// If the switch changed, due to noise or pressing:
|
||||||
|
if (reading != lastInputState) {
|
||||||
|
// reset the debouncing timer
|
||||||
|
lastDebounceTime = millis();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((millis() - lastDebounceTime) > GPIOInputDebounceDelay) {
|
||||||
|
// whatever the reading is at, it's been there for longer than the debounce
|
||||||
|
// delay, so take it as the actual current state:
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
yield();
|
||||||
|
#endif
|
||||||
|
// if the Input state has changed:
|
||||||
|
if (reading != InputState) {
|
||||||
|
InputState = reading;
|
||||||
|
|
||||||
|
if (InputState == HIGH) {
|
||||||
|
trc(F("GPIO HIGH"));
|
||||||
|
client.publish(subjectGPIOInputtoMQTT,"HIGH");
|
||||||
|
}
|
||||||
|
if (InputState == LOW) {
|
||||||
|
trc(F("GPIO LOW"));
|
||||||
|
client.publish(subjectGPIOInputtoMQTT,"LOW");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// save the reading. Next time through the loop, it'll be the lastInputState:
|
||||||
|
lastInputState = reading;
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
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 GPIOInput sensor
|
||||||
|
|
||||||
|
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 subjectGPIOInputtoMQTT Base_Topic Gateway_Name "/GPIOInputtoMQTT"
|
||||||
|
#define GPIOInputDebounceDelay 60 //debounce time, increase if there are issues
|
||||||
|
|
||||||
|
/*-------------------PIN DEFINITIONS----------------------*/
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
#define GPIOInput_PIN 5 //D5
|
||||||
|
#else
|
||||||
|
#define GPIOInput_PIN 7
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -103,6 +103,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define ZsensorTSL2561 "TSL2561"
|
#define ZsensorTSL2561 "TSL2561"
|
||||||
#define ZsensorDHT "DHT"// If you uncomment this you can't use I2C due to the fact that I2C use also D1
|
#define ZsensorDHT "DHT"// If you uncomment this you can't use I2C due to the fact that I2C use also D1
|
||||||
#define ZgatewayRFM69 "RFM69"// If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
#define ZgatewayRFM69 "RFM69"// If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
||||||
|
#define ZsensorGPIOInput "GPIOInput"
|
||||||
#elif ESP32
|
#elif ESP32
|
||||||
#define ZgatewayRF "RF"
|
#define ZgatewayRF "RF"
|
||||||
#define ZgatewayRF "RF315"
|
#define ZgatewayRF "RF315"
|
||||||
@@ -118,6 +119,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
//#define ZsensorBME280
|
//#define ZsensorBME280
|
||||||
#define ZsensorDHT "DHT"// If you uncomment this you can't use I2C due to the fact that I2C use also D1
|
#define ZsensorDHT "DHT"// If you uncomment this you can't use I2C due to the fact that I2C use also D1
|
||||||
//#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
//#define ZgatewayRFM69 // If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
||||||
|
//#define ZsensorGPIOInput "GPIOInput" //untested
|
||||||
#else // for arduino mega + W5100
|
#else // for arduino mega + W5100
|
||||||
#define ZgatewayRF "RF"
|
#define ZgatewayRF "RF"
|
||||||
//#define Zgateway2G (not tested yet)
|
//#define Zgateway2G (not tested yet)
|
||||||
@@ -133,6 +135,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
//#define ZsensorHCSR501
|
//#define ZsensorHCSR501
|
||||||
//#define ZsensorADC
|
//#define ZsensorADC
|
||||||
//#define ZgatewayRFM69 not tested
|
//#define ZgatewayRFM69 not tested
|
||||||
|
//#define ZsensorGPIOInput //not tested
|
||||||
#endif
|
#endif
|
||||||
/*----------------------------OTHER PARAMETERS-----------------------------*/
|
/*----------------------------OTHER PARAMETERS-----------------------------*/
|
||||||
#ifdef ZgatewaySRFB
|
#ifdef ZgatewaySRFB
|
||||||
|
|||||||
Reference in new issue
Block a user