-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved MQTT setup and added support for digital switches as sensor …
…input
- Loading branch information
1 parent
ae8657a
commit a329427
Showing
21 changed files
with
244 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/**************************************************************************/ | ||
/*! | ||
@file SensorDigitalSwitch.cpp | ||
@author M. Fegerl (Sensate Digital Solutions GmbH) | ||
@license GPL (see LICENSE file) | ||
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware | ||
with the Sensate Cloud and the Sensate apps. | ||
----> https://www.sensate.io | ||
SOURCE: https://github.com/sensate-io/firmware-esp8266.git | ||
@section HISTORY | ||
v33 - Added Digital Sensor Switch | ||
*/ | ||
/**************************************************************************/ | ||
|
||
#include "SensorDigitalSwitch.h" | ||
|
||
extern boolean isResetting; | ||
extern int powerMode; | ||
|
||
SensorDigitalSwitch::SensorDigitalSwitch (long id, String category, String shortName, String name, uint8_t port, int refreshInterval, int postDataInterval, SensorCalculation* calculation) : Sensor (id, category, shortName, name, refreshInterval, postDataInterval, 0.5, calculation, true) { | ||
|
||
pinMode(port, INPUT); | ||
_port = port; | ||
|
||
} | ||
|
||
void SensorDigitalSwitch::preCycle(int cycleId) | ||
{ | ||
} | ||
|
||
Data* SensorDigitalSwitch::read(bool shouldPostData) | ||
{ | ||
if(!isResetting) | ||
{ | ||
bool portState = digitalRead(_port); | ||
if(lastPostedValue!=portState) | ||
shouldPostData = true; | ||
|
||
Data *data = _calculation->calculate(this, portState, shouldPostData); | ||
|
||
if(shouldPostData) | ||
lastPostedValue = portState; | ||
|
||
return data; | ||
} | ||
|
||
return NULL; | ||
|
||
} | ||
|
||
boolean SensorDigitalSwitch::smartSensorCheck(float currentRawValue, float threshhold, boolean shouldPostData) | ||
{ | ||
if(powerMode == 3) | ||
{ | ||
if(!shouldPostData) | ||
{ | ||
if(!isnan(lastPostedValue)) | ||
{ | ||
if(lastPostedValue-currentRawValue>threshhold|| lastPostedValue-currentRawValue<-threshhold) | ||
{ | ||
shouldPostData = true; | ||
} | ||
} | ||
} | ||
|
||
if(shouldPostData) | ||
lastPostedValue = currentRawValue; | ||
} | ||
|
||
return shouldPostData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/**************************************************************************/ | ||
/*! | ||
@file SensorDigitalSwitch.h | ||
@author M. Fegerl (Sensate Digital Solutions GmbH) | ||
@license GPL (see LICENSE file) | ||
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware | ||
with the Sensate Cloud and the Sensate apps. | ||
----> https://www.sensate.io | ||
SOURCE: https://github.com/sensate-io/firmware-esp8266.git | ||
@section HISTORY | ||
v33 - Added Digital Sensor Switch | ||
*/ | ||
/**************************************************************************/ | ||
|
||
#ifndef _SensorDigitalSwitch_h_ | ||
#define _SensorDigitalSwitch_h_ | ||
|
||
#include "Sensor.h" | ||
|
||
class SensorDigitalSwitch : public Sensor { | ||
private: | ||
bool lastPostedValue = 0; | ||
uint8_t _port; | ||
protected: | ||
Data* read(bool); | ||
void preCycle(int); | ||
boolean smartSensorCheck(float, float, boolean); | ||
public: | ||
SensorDigitalSwitch (long, String, String, String, uint8_t, int, int, SensorCalculation*); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.