BTtoMQTT publishing
This commit is contained in:
1 parent
e47b32b1f6
commit
fc87385b38
4 files changed
+72
-58
No files matched your search
+28
-30
@@ -1,12 +1,11 @@
|
||||
/*
|
||||
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
|
||||
|
||||
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
|
||||
This gateway enables to:
|
||||
- publish MQTT data to a different topic related to BLE devices rssi signal
|
||||
|
||||
Copyright: (c)1technophile
|
||||
|
||||
@@ -26,16 +25,16 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
|
||||
#ifdef ZgatewayBT
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define STRING_MSG "OK+DISC"
|
||||
#define STRING_MSG "OK+DISC:"
|
||||
#define QUESTION_MSG "AT+DISI?"
|
||||
#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;
|
||||
|
||||
void setupBT() {
|
||||
Serial.begin(57600);
|
||||
softserial.begin(9600);
|
||||
softserial.print(F("AT+ROLE1"));
|
||||
delay(100);
|
||||
@@ -51,35 +50,34 @@ boolean BTtoMQTT() {
|
||||
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);
|
||||
|
||||
String discResult = softserial.readString();
|
||||
if (discResult.indexOf(STRING_MSG)>=0){
|
||||
trc(F("Sending BT data to MQTT"));
|
||||
discResult.replace(RESPONSE_MSG,"");
|
||||
int device_number = discResult.length()/78;
|
||||
for (int i=0;i<device_number;i++){
|
||||
String onedevice = response.substring(0,78);
|
||||
String onedevice = discResult.substring(0,78);
|
||||
onedevice.replace(STRING_MSG,"");
|
||||
Serial.println(onedevice);
|
||||
String company = onedevice.substring(1,9);
|
||||
Serial.println(company);
|
||||
String uuid = onedevice.substring(10,42);
|
||||
Serial.println(uuid);
|
||||
String others = onedevice.substring(43,53);
|
||||
Serial.println(others);
|
||||
String mac = onedevice.substring(54,66);
|
||||
Serial.println(mac);
|
||||
String rssi = onedevice.substring(67,71);
|
||||
Serial.println(rssi);
|
||||
response = response.substring(78);
|
||||
String company = onedevice.substring(0,8);
|
||||
String uuid = onedevice.substring(9,41);
|
||||
String others = onedevice.substring(42,52);
|
||||
String mac = onedevice.substring(53,65);
|
||||
String rssi = onedevice.substring(66,70);
|
||||
String mactopic = subjectBTtoMQTT + mac;
|
||||
trc(mactopic + " " + rssi);
|
||||
client.publish((char *)mactopic.c_str(),(char *)rssi.c_str());
|
||||
discResult = discResult.substring(78);
|
||||
#ifdef ESP8266
|
||||
yield();
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (millis() > (time1 + 10000)) {//retriving value of adresses and rssi
|
||||
if (millis() > (time1 + TimeBtw_Read)) {//retriving value of adresses and rssi
|
||||
time1 = millis();
|
||||
softserial.print(F(QUESTION_MSG));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user