From e47b32b1f69d6d16bda33a37860fa06769df5edf Mon Sep 17 00:00:00 2001 From: 1technophile Date: Sun, 30 Apr 2017 23:34:58 +0200 Subject: [PATCH] add of ZgatewayBT --- OpenMQTTGateway.ino | 10 +++++- ZgatewayBT.ino | 85 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 ZgatewayBT.ino diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index d26102f..3c5e97b 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -126,6 +126,9 @@ void setup() #ifdef ZgatewayRF setupRF(); #endif + #ifdef ZgatewayBT + setupBT(); + #endif } @@ -191,9 +194,14 @@ void loop() if(resultIR) trc(F("IR successfully sent by MQTT")); #endif + #ifdef ZgatewayBT + boolean resultBT = BTtoMQTT(); + if(resultBT) + trc(F("BT successfully sent by MQTT")); + #endif } - delay(100); + //delay(100); } void storeValue(long MQTTvalue){ diff --git a/ZgatewayBT.ino b/ZgatewayBT.ino new file mode 100644 index 0000000..c362aac --- /dev/null +++ b/ZgatewayBT.ino @@ -0,0 +1,85 @@ +/* + 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 program enables to: + - receive MQTT data from a topic and send IR signal corresponding to the received MQTT data + - publish MQTT data to a different topic related to received IR signal + + Copyright: (c)1technophile + +IMPORTANT NOTE: On arduino connect IR emitter pin to D9 , comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library IRremote/IRremoteInt.h so as to free pin D3 for RF RECEIVER PIN + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +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. +*/ +#ifdef ZgatewayBT +#include + +#define STRING_MSG "OK+DISC" +#define QUESTION_MSG "AT+DISI?" +#define RESPONSE_MSG "OK+DISIS" + +//SoftwareSerial softserial(D7, D6); +SoftwareSerial softserial(10, 11); +unsigned long time1 = 0; + +void setupBT() { + Serial.begin(57600); + softserial.begin(9600); + softserial.print(F("AT+ROLE1")); + delay(100); + softserial.print(F("AT+IMME1")); + delay(100); + softserial.print(F("AT+RESET")); + delay(100); +} + +boolean BTtoMQTT() { + while (softserial.available() > 0) { + #ifdef ESP8266 + yield(); + #endif + + String response = softserial.readString(); + Serial.println(response); + if (response.indexOf(STRING_MSG)>=0) + { + response.replace(RESPONSE_MSG,""); + int device_number = response.length()/78; + Serial.println(device_number); + + for (int i=0;i (time1 + 10000)) {//retriving value of adresses and rssi + time1 = millis(); + softserial.print(F(QUESTION_MSG)); + } +} +#endif