BTtoMQTT publishing
This commit is contained in:
1 parent
e47b32b1f6
commit
fc87385b38
4 files changed
+71
-57
No files matched your search
+2
-1
@@ -9,6 +9,7 @@
|
|||||||
- publish MQTT data to a different topic related to received 433Mhz signal
|
- publish MQTT data to a different topic related to received 433Mhz signal
|
||||||
- receive MQTT data from a topic and send IR signal corresponding to the received MQTT data
|
- 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
|
- publish MQTT data to a different topic related to received IR signal
|
||||||
|
- publish MQTT data to a different topic related to BLE devices rssi signal
|
||||||
|
|
||||||
Copyright: (c)1technophile
|
Copyright: (c)1technophile
|
||||||
|
|
||||||
@@ -201,7 +202,7 @@ void loop()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
//delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void storeValue(long MQTTvalue){
|
void storeValue(long MQTTvalue){
|
||||||
|
|||||||
+40
-25
@@ -9,6 +9,7 @@
|
|||||||
- publish MQTT data to a different topic related to received 433Mhz signal
|
- publish MQTT data to a different topic related to received 433Mhz signal
|
||||||
- receive MQTT data from a topic and send IR signal corresponding to the received MQTT data
|
- 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
|
- publish MQTT data to a different topic related to received IR signal
|
||||||
|
- publish MQTT data to a different topic related to BLE devices rssi signal
|
||||||
|
|
||||||
Copyright: (c)1technophile
|
Copyright: (c)1technophile
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*----------------------------USER PARAMETERS-----------------------------*/
|
/*----------------------------USER PARAMETERS-----------------------------*/
|
||||||
/*-------------DEFINE YOUR MQTT & NETWORK PARAMETERS BELOW----------------*/
|
/*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/
|
||||||
//MQTT Parameters definition
|
//MQTT Parameters definition
|
||||||
#define mqtt_server "192.168.1.17"
|
#define mqtt_server "192.168.1.17"
|
||||||
//#define mqtt_user "your_username" // not compulsory only if your broker needs authentication
|
//#define mqtt_user "your_username" // not compulsory only if your broker needs authentication
|
||||||
@@ -38,6 +39,7 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
|
|||||||
#define will_Message "Offline"
|
#define will_Message "Offline"
|
||||||
#define Gateway_AnnouncementMsg "Online"
|
#define Gateway_AnnouncementMsg "Online"
|
||||||
|
|
||||||
|
/*-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------*/
|
||||||
// Update these with values suitable for your network.
|
// Update these with values suitable for your network.
|
||||||
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
||||||
#define wifi_ssid "wifi ssid"
|
#define wifi_ssid "wifi ssid"
|
||||||
@@ -52,23 +54,23 @@ const byte gateway[] = { 192, 168, 1, 1 }; //ip adress
|
|||||||
const byte Dns[] = { 192, 168, 1, 1 }; //ip adress
|
const byte Dns[] = { 192, 168, 1, 1 }; //ip adress
|
||||||
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
||||||
|
|
||||||
|
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
|
||||||
//Addons and module management, comment the line if you don't use
|
//Addons and module management, comment the line if you don't use
|
||||||
//#define ZsensorDHT
|
//#define ZsensorDHT
|
||||||
#define ZgatewayRF
|
#define ZgatewayRF
|
||||||
#define ZgatewayIR
|
#define ZgatewayIR
|
||||||
|
#define ZgatewayBT
|
||||||
/*----------------------------OTHER PARAMETERS-----------------------------*/
|
/*----------------------------OTHER PARAMETERS-----------------------------*/
|
||||||
/*-------------------CHANGING THEM IS NOT COMPULSORY-----------------------*/
|
/*-------------------CHANGING THEM IS NOT COMPULSORY-----------------------*/
|
||||||
//variables to avoid duplicates for RF
|
//variables to avoid duplicates for RF
|
||||||
#define time_avoid_duplicate 3000 // if you want to avoid duplicate mqtt message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates
|
#define time_avoid_duplicate 3000 // if you want to avoid duplicate mqtt message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates
|
||||||
|
|
||||||
//MQTT definitions
|
/*--------------MQTT general topics-----------------*/
|
||||||
// global MQTT subject listened by the gateway to execute commands (send RF, IR or others)
|
// global MQTT subject listened by the gateway to execute commands (send RF, IR or others)
|
||||||
#define subjectMQTTtoX "home/commands/#"
|
#define subjectMQTTtoX "home/commands/#"
|
||||||
// subject monitored to listen traffic processed by other gateways to store data and avoid ntuple
|
|
||||||
#define subjectMultiGTWRF "+/433toMQTT"
|
|
||||||
#define subjectMultiGTWIR "+/IRtoMQTT"
|
|
||||||
#define subjectMultiGTWKey "toMQTT"
|
#define subjectMultiGTWKey "toMQTT"
|
||||||
|
|
||||||
|
/*-------------------RF topics----------------------*/
|
||||||
//433Mhz MQTT Subjects and keys
|
//433Mhz MQTT Subjects and keys
|
||||||
#define subjectMQTTtoRF "home/commands/MQTTto433"
|
#define subjectMQTTtoRF "home/commands/MQTTto433"
|
||||||
#define subjectRFtoMQTT "home/433toMQTT"
|
#define subjectRFtoMQTT "home/433toMQTT"
|
||||||
@@ -77,15 +79,6 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define subjectRFtoMQTTbits "home/433toMQTT/bits"
|
#define subjectRFtoMQTTbits "home/433toMQTT/bits"
|
||||||
#define subjectRFtoMQTTlength "home/433toMQTT/length"
|
#define subjectRFtoMQTTlength "home/433toMQTT/length"
|
||||||
#define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit
|
#define RFprotocolKey "433_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit
|
||||||
#define RFpulselengthKey "PLSL_" // pulselength will be defined if a subject contains RFprotocolKey followed by a value of 3 digits
|
|
||||||
//IR MQTT Subjects
|
|
||||||
#define subjectGTWIRtoMQTT "home/IRtoMQTT"
|
|
||||||
#define subjectIRtoMQTT "home/IRtoMQTT"
|
|
||||||
#define subjectMQTTtoIR "home/commands/MQTTtoIR"
|
|
||||||
#define subjectIRtoMQTTprotocol "home/IRtoMQTT/protocol"
|
|
||||||
#define subjectIRtoMQTTbits "home/IRtoMQTT/bits"
|
|
||||||
|
|
||||||
#define pubIRunknownPrtcl false // key to avoid mqtt publication of unknown IR protocol (set to true if you want to publish unknown protocol)
|
|
||||||
/*
|
/*
|
||||||
RF supported protocols
|
RF supported protocols
|
||||||
433_1
|
433_1
|
||||||
@@ -94,18 +87,36 @@ RF supported protocols
|
|||||||
433_4
|
433_4
|
||||||
433_5
|
433_5
|
||||||
433_6
|
433_6
|
||||||
IR supported protocols
|
|
||||||
IR_NEC
|
|
||||||
IR_LG
|
|
||||||
IR_Sony
|
|
||||||
IR_DISH
|
|
||||||
IR_Sharp
|
|
||||||
IR_SAMSUNG
|
|
||||||
IR_COOLIX
|
|
||||||
IR_Whynter
|
|
||||||
*/
|
*/
|
||||||
|
#define RFpulselengthKey "PLSL_" // pulselength will be defined if a subject contains RFprotocolKey followed by a value of 3 digits
|
||||||
|
// subject monitored to listen traffic processed by other gateways to store data and avoid ntuple
|
||||||
|
#define subjectMultiGTWRF "+/433toMQTT"
|
||||||
|
|
||||||
//IR PIN definition
|
/*-------------------IR topics----------------------*/
|
||||||
|
//IR MQTT Subjects
|
||||||
|
#define subjectGTWIRtoMQTT "home/IRtoMQTT"
|
||||||
|
#define subjectIRtoMQTT "home/IRtoMQTT"
|
||||||
|
#define subjectMQTTtoIR "home/commands/MQTTtoIR"
|
||||||
|
#define subjectIRtoMQTTprotocol "home/IRtoMQTT/protocol"
|
||||||
|
#define subjectIRtoMQTTbits "home/IRtoMQTT/bits"
|
||||||
|
// subject monitored to listen traffic processed by other gateways to store data and avoid ntuple
|
||||||
|
#define subjectMultiGTWIR "+/IRtoMQTT"
|
||||||
|
|
||||||
|
#define pubIRunknownPrtcl false // key to avoid mqtt publication of unknown IR protocol (set to true if you want to publish unknown protocol)
|
||||||
|
//IR supported protocols uncomment if you want to send with this protocol, NEC protocol is available per default
|
||||||
|
#define IR_COOLIX
|
||||||
|
#define IR_Whynter
|
||||||
|
#define IR_LG
|
||||||
|
#define IR_Sony
|
||||||
|
#define IR_DISH
|
||||||
|
#define IR_RC5
|
||||||
|
#define IR_Sharp
|
||||||
|
#define IR_SAMSUNG
|
||||||
|
|
||||||
|
/*----------------------BT topics-------------------------*/
|
||||||
|
#define subjectBTtoMQTT "home/BTtoMQTT/"
|
||||||
|
|
||||||
|
/*-------------------PIN DEFINITIONS----------------------*/
|
||||||
#define IR_RECEIVER_PIN 2 // put 2 = D4 on nodemcu, 2 = D2 on arduino
|
#define IR_RECEIVER_PIN 2 // put 2 = D4 on nodemcu, 2 = D2 on arduino
|
||||||
#define RF_EMITTER_PIN 4 //put 4 = D2 on nodemcu, 4 = D4 on arduino
|
#define RF_EMITTER_PIN 4 //put 4 = D2 on nodemcu, 4 = D4 on arduino
|
||||||
|
|
||||||
@@ -113,14 +124,18 @@ IR_Whynter
|
|||||||
#define IR_EMITTER_PIN 14 // 14 = D5 on nodemcu #define only usefull for ESP8266
|
#define IR_EMITTER_PIN 14 // 14 = D5 on nodemcu #define only usefull for ESP8266
|
||||||
//RF PIN definition
|
//RF PIN definition
|
||||||
#define RF_RECEIVER_PIN 5 // 5 = D1 on nodemcu
|
#define RF_RECEIVER_PIN 5 // 5 = D1 on nodemcu
|
||||||
|
#define BT_RX D7 //ESP8266 RX connect HM-10 TX
|
||||||
|
#define BT_TX D6 //ESP8266 TX connect HM-10 RX
|
||||||
#else
|
#else
|
||||||
//IMPORTANT NOTE: On arduino UNO connect IR emitter pin to D9 , comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library <library>IRremote/IRremoteInt.h so as to free pin D3 for RF RECEIVER PIN
|
//IMPORTANT NOTE: On arduino UNO connect IR emitter pin to D9 , comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library <library>IRremote/IRremoteInt.h so as to free pin D3 for RF RECEIVER PIN
|
||||||
//RF PIN definition
|
//RF PIN definition
|
||||||
#define RF_RECEIVER_PIN 1 // 1 = D3 on arduino
|
#define RF_RECEIVER_PIN 1 // 1 = D3 on arduino
|
||||||
|
#define BT_RX 10
|
||||||
|
#define BT_TX 11
|
||||||
#endif
|
#endif
|
||||||
//RF number of signal repetition
|
//RF number of signal repetition
|
||||||
#define RF_EMITTER_REPEAT 20
|
#define RF_EMITTER_REPEAT 20
|
||||||
|
|
||||||
//Do we want to see trace for debugging purposes
|
/*-------------------ACTIVATE TRACES----------------------*/
|
||||||
#define TRACE 1 // 0= trace off 1 = trace on
|
#define TRACE 1 // 0= trace off 1 = trace on
|
||||||
|
|
||||||
+29
-31
@@ -1,12 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
OpenMQTTGateway - ESP8266 or Arduino program for home automation
|
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
|
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal/BLE and a MQTT broker
|
||||||
Send and receiving command by MQTT
|
Send and receiving command by MQTT
|
||||||
|
|
||||||
This program enables to:
|
This gateway 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 BLE devices rssi signal
|
||||||
- publish MQTT data to a different topic related to received IR signal
|
|
||||||
|
|
||||||
Copyright: (c)1technophile
|
Copyright: (c)1technophile
|
||||||
|
|
||||||
@@ -26,16 +25,16 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
|
|||||||
#ifdef ZgatewayBT
|
#ifdef ZgatewayBT
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
#define STRING_MSG "OK+DISC"
|
#define STRING_MSG "OK+DISC:"
|
||||||
#define QUESTION_MSG "AT+DISI?"
|
#define QUESTION_MSG "AT+DISI?"
|
||||||
#define RESPONSE_MSG "OK+DISIS"
|
#define RESPONSE_MSG "OK+DISIS"
|
||||||
|
#define TimeBtw_Read 10000
|
||||||
|
|
||||||
|
SoftwareSerial softserial(BT_RX, BT_TX);
|
||||||
|
|
||||||
//SoftwareSerial softserial(D7, D6);
|
|
||||||
SoftwareSerial softserial(10, 11);
|
|
||||||
unsigned long time1 = 0;
|
unsigned long time1 = 0;
|
||||||
|
|
||||||
void setupBT() {
|
void setupBT() {
|
||||||
Serial.begin(57600);
|
|
||||||
softserial.begin(9600);
|
softserial.begin(9600);
|
||||||
softserial.print(F("AT+ROLE1"));
|
softserial.print(F("AT+ROLE1"));
|
||||||
delay(100);
|
delay(100);
|
||||||
@@ -51,35 +50,34 @@ boolean BTtoMQTT() {
|
|||||||
yield();
|
yield();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String response = softserial.readString();
|
String discResult = softserial.readString();
|
||||||
Serial.println(response);
|
if (discResult.indexOf(STRING_MSG)>=0){
|
||||||
if (response.indexOf(STRING_MSG)>=0)
|
trc(F("Sending BT data to MQTT"));
|
||||||
{
|
discResult.replace(RESPONSE_MSG,"");
|
||||||
response.replace(RESPONSE_MSG,"");
|
int device_number = discResult.length()/78;
|
||||||
int device_number = response.length()/78;
|
|
||||||
Serial.println(device_number);
|
|
||||||
|
|
||||||
for (int i=0;i<device_number;i++){
|
for (int i=0;i<device_number;i++){
|
||||||
String onedevice = response.substring(0,78);
|
String onedevice = discResult.substring(0,78);
|
||||||
onedevice.replace(STRING_MSG,"");
|
onedevice.replace(STRING_MSG,"");
|
||||||
Serial.println(onedevice);
|
String company = onedevice.substring(0,8);
|
||||||
String company = onedevice.substring(1,9);
|
String uuid = onedevice.substring(9,41);
|
||||||
Serial.println(company);
|
String others = onedevice.substring(42,52);
|
||||||
String uuid = onedevice.substring(10,42);
|
String mac = onedevice.substring(53,65);
|
||||||
Serial.println(uuid);
|
String rssi = onedevice.substring(66,70);
|
||||||
String others = onedevice.substring(43,53);
|
String mactopic = subjectBTtoMQTT + mac;
|
||||||
Serial.println(others);
|
trc(mactopic + " " + rssi);
|
||||||
String mac = onedevice.substring(54,66);
|
client.publish((char *)mactopic.c_str(),(char *)rssi.c_str());
|
||||||
Serial.println(mac);
|
discResult = discResult.substring(78);
|
||||||
String rssi = onedevice.substring(67,71);
|
#ifdef ESP8266
|
||||||
Serial.println(rssi);
|
yield();
|
||||||
response = response.substring(78);
|
#endif
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (millis() > (time1 + TimeBtw_Read)) {//retriving value of adresses and rssi
|
||||||
if (millis() > (time1 + 10000)) {//retriving value of adresses and rssi
|
|
||||||
time1 = millis();
|
time1 = millis();
|
||||||
softserial.print(F(QUESTION_MSG));
|
softserial.print(F(QUESTION_MSG));
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 212 KiB |
Reference in new issue
Block a user