spliting the code into different files
Differentiate 4 categories of files: -gateway file for bridging signal and MQTT -user config -sensor files -actuators files
This commit is contained in:
1 parent
0bbf882b30
commit
a65e5fa595
4 files changed
+140
-13
No files matched your search
@@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setupIR()
|
||||||
|
{
|
||||||
|
|
||||||
|
//IR init parameters
|
||||||
|
#ifdef ESP8266
|
||||||
|
irsend.begin();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
irrecv.enableIRIn(); // Start the receiver
|
||||||
|
}
|
||||||
|
|
||||||
|
void receivingMQTTIR(char * topicOri, char * datacallback) {
|
||||||
|
|
||||||
|
// IR DATA ANALYSIS
|
||||||
|
//send received MQTT value by IR signal (example of signal sent data = 1086296175)
|
||||||
|
boolean signalSent = false;
|
||||||
|
#ifdef ESP8266 // send coolix not available for arduino IRRemote library
|
||||||
|
if (topic.lastIndexOf("IR_COOLIX") != -1 ){
|
||||||
|
irsend.sendCOOLIX(data, 24);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (topic.lastIndexOf("IR_NEC")!= -1 || topic == subjectMQTTtoIR){
|
||||||
|
irsend.sendNEC(data, 32);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (topic.lastIndexOf("IR_Whynter")!=-1){
|
||||||
|
irsend.sendWhynter(data, 32);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (topic.lastIndexOf("IR_LG")!=-1){
|
||||||
|
irsend.sendLG(data, 28);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (topic.lastIndexOf("IR_Sony")!=-1){
|
||||||
|
irsend.sendSony(data, 12);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (topic.lastIndexOf("IR_DISH")!=-1){
|
||||||
|
irsend.sendDISH(data, 16);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (topic.lastIndexOf("IR_RC5")!=-1){
|
||||||
|
irsend.sendRC5(data, 12);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (topic.lastIndexOf("IR_Sharp")!=-1){
|
||||||
|
irsend.sendSharpRaw(data, 15);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (topic.lastIndexOf("IR_SAMSUNG")!=-1){
|
||||||
|
irsend.sendSAMSUNG(data, 32);
|
||||||
|
signalSent = true;
|
||||||
|
}
|
||||||
|
if (signalSent){
|
||||||
|
boolean result = client.publish(subjectGTWIRtoMQTT, datacallback);
|
||||||
|
if (result)trc(F("Acknowedgement of reception published"));
|
||||||
|
}
|
||||||
|
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
|
||||||
|
void setupRF()
|
||||||
|
{
|
||||||
|
|
||||||
|
//RF init parameters
|
||||||
|
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
||||||
|
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
|
||||||
|
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void receivingMQTTRF(char * topicOri, char * datacallback) {
|
||||||
|
String topic = topicOri;
|
||||||
|
|
||||||
|
trc(F("Receiving data by MQTT"));
|
||||||
|
trc(topic);
|
||||||
|
trc(F("Callback value"));
|
||||||
|
trc(String(datacallback));
|
||||||
|
unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
|
||||||
|
trc(F("Converted value to unsigned long"));
|
||||||
|
trc(String(data));
|
||||||
|
|
||||||
|
// Storing data received
|
||||||
|
int pos0 = topic.lastIndexOf(subjectMultiGTWKey);
|
||||||
|
if (pos0 != -1){
|
||||||
|
trc(F("Storing signal"));
|
||||||
|
storeValue(data);
|
||||||
|
trc(F("Data stored"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// RF DATA ANALYSIS
|
||||||
|
//We look into the subject to see if a special RF protocol is defined
|
||||||
|
int valuePRT = 0;
|
||||||
|
int valuePLSL = 0;
|
||||||
|
int pos = topic.lastIndexOf(RFprotocolKey);
|
||||||
|
if (pos != -1){
|
||||||
|
pos = pos + +strlen(RFprotocolKey);
|
||||||
|
valuePRT = (topic.substring(pos,pos + 1)).toInt();
|
||||||
|
trc(F("RF Protocol number:"));
|
||||||
|
trc(String(valuePRT));
|
||||||
|
}
|
||||||
|
//We look into the subject to see if a special RF pulselength is defined
|
||||||
|
int pos2 = topic.lastIndexOf(RFpulselengthKey);
|
||||||
|
if (pos2 != -1) {
|
||||||
|
pos2 = pos2 + strlen(RFpulselengthKey);
|
||||||
|
valuePLSL = (topic.substring(pos2,pos2 + 3)).toInt();
|
||||||
|
trc(F("RF Pulse Length:"));
|
||||||
|
trc(String(valuePLSL));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((topic == subjectMQTTto433) && (valuePRT == 0) && (valuePLSL == 0)){
|
||||||
|
trc(F("Sending data by RF, default parameters"));
|
||||||
|
mySwitch.setProtocol(1,350);
|
||||||
|
mySwitch.send(data, 24);
|
||||||
|
// Acknowledgement to the GTWRF topic
|
||||||
|
boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);
|
||||||
|
if (result)trc(F("Acknowedgement of reception published"));
|
||||||
|
|
||||||
|
} else if ((valuePRT != 0) || (valuePLSL != 0)){
|
||||||
|
trc(F("Sending data by RF, user defined parameters"));
|
||||||
|
if (valuePRT == 0) valuePRT = 1;
|
||||||
|
if (valuePLSL == 0) valuePLSL = 350;
|
||||||
|
trc(String(valuePRT));
|
||||||
|
trc(String(valuePLSL));
|
||||||
|
mySwitch.setProtocol(valuePRT,valuePLSL);
|
||||||
|
mySwitch.send(data, 24);
|
||||||
|
// Acknowledgement to the GTWRF topic
|
||||||
|
boolean result = client.publish(subjectGTWRFtoMQTT, datacallback);
|
||||||
|
if (result)trc(F("Acknowedgement of reception published"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+3
-12
@@ -130,17 +130,8 @@ void setup()
|
|||||||
|
|
||||||
lastReconnectAttempt = 0;
|
lastReconnectAttempt = 0;
|
||||||
|
|
||||||
//IR init parameters
|
setupIR();
|
||||||
#ifdef ESP8266
|
setupRF();
|
||||||
irsend.begin();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
irrecv.enableIRIn(); // Start the receiver
|
|
||||||
|
|
||||||
//RF init parameters
|
|
||||||
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
|
||||||
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
|
|
||||||
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +182,7 @@ void loop()
|
|||||||
} else { //connected
|
} else { //connected
|
||||||
// MQTT loop
|
// MQTT loop
|
||||||
client.loop();
|
client.loop();
|
||||||
#ifdef ZaddonDHT
|
#ifdef ZsensorDHT
|
||||||
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
|
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
|
||||||
#endif
|
#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
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN
|
|||||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifdef ZaddonDHT
|
#ifdef ZsensorDHT
|
||||||
#include <DHT.h>
|
#include <DHT.h>
|
||||||
#include <DHT_U.h>
|
#include <DHT_U.h>
|
||||||
#define TimeBetweenReading 60000
|
#define TimeBetweenReading 60000
|
||||||
Reference in new issue
Block a user