publish rssi value to a dedicated mqtt subject

#201 and put defines for other sub subject names
This commit is contained in:
Florian committed 2018-05-12 15:25:57 +02:00
1 parent d4ce6e4b64
commit ec7cee8f3e
2 files changed
+18 -9

No files matched your search

+12 -9
View File
@@ -6,6 +6,8 @@
This gateway enables to: This gateway enables to:
- publish MQTT data to a different topic related to BLE devices rssi signal - publish MQTT data to a different topic related to BLE devices rssi signal
- publish MQTT data related to mi flora temperature, moisture, fertility and lux
- publish MQTT data related to mi jia indoor temperature & humidity sensor
Copyright: (c)Florian ROBERT Copyright: (c)Florian ROBERT
@@ -67,8 +69,9 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht
if (advertisedDevice.haveRSSI()){ if (advertisedDevice.haveRSSI()){
trc(F("Get RSSI ")); trc(F("Get RSSI "));
String rssi = String(advertisedDevice.getRSSI()); String rssi = String(advertisedDevice.getRSSI());
trc(mactopic + " " + rssi); String rssitopic = mactopic + subjectBTtoMQTTrssi;
client.publish((char *)mactopic.c_str(),(char *)rssi.c_str()); trc(rssitopic + " " + rssi);
client.publish((char *)rssitopic.c_str(),(char *)rssi.c_str());
} }
if (advertisedDevice.haveTXPower()){ if (advertisedDevice.haveTXPower()){
trc(F("Get TXPower ")); trc(F("Get TXPower "));
@@ -238,7 +241,7 @@ boolean BTtoMQTT() {
strupp(d[0].extract); strupp(d[0].extract);
String mactopic(d[0].extract); String mactopic(d[0].extract);
trc(mactopic); trc(mactopic);
mactopic = subjectBTtoMQTT + mactopic; mactopic = subjectBTtoMQTT + mactopic + subjectBTtoMQTTrssi;
int rssi = (int)strtol(d[2].extract, NULL, 16) - 256; int rssi = (int)strtol(d[2].extract, NULL, 16) - 256;
char val[12]; char val[12];
sprintf(val, "%d", rssi); sprintf(val, "%d", rssi);
@@ -296,7 +299,7 @@ boolean BTtoMQTT() {
onedevice.replace(STRING_MSG,""); onedevice.replace(STRING_MSG,"");
String mac = onedevice.substring(53,65); String mac = onedevice.substring(53,65);
String rssi = onedevice.substring(66,70); String rssi = onedevice.substring(66,70);
String mactopic = subjectBTtoMQTT + mac; String mactopic = subjectBTtoMQTT + mac + subjectBTtoMQTTRSSI;
trc(mactopic + " " + rssi); trc(mactopic + " " + rssi);
client.publish((char *)mactopic.c_str(),(char *)rssi.c_str()); client.publish((char *)mactopic.c_str(),(char *)rssi.c_str());
discResult = discResult.substring(78); discResult = discResult.substring(78);
@@ -354,25 +357,25 @@ boolean process_data(int offset, char * rest_data, char * mac_adress){
// following the value of digit 47 we determine the type of data we get from the sensor // following the value of digit 47 we determine the type of data we get from the sensor
switch (rest_data[47 + offset]) { switch (rest_data[47 + offset]) {
case '9' : case '9' :
mactopic = mactopic + "/" + "fer"; mactopic = mactopic + subjectBTtoMQTTfer;
dtostrf(value,0,0,val); dtostrf(value,0,0,val);
break; break;
case '4' : case '4' :
mactopic = mactopic + "/" + "tem"; mactopic = mactopic + subjectBTtoMQTTtem;
if (value > 65000) value = value - 65535; if (value > 65000) value = value - 65535;
dtostrf(value/10,3,1,val); // temp has to be divided by 10 dtostrf(value/10,3,1,val); // temp has to be divided by 10
break; break;
case '6' : case '6' :
mactopic = mactopic + "/" + "hum"; mactopic = mactopic + subjectBTtoMQTThum;
if (value > 65000) value = value - 65535; if (value > 65000) value = value - 65535;
dtostrf(value/10,3,1,val); // hum has to be divided by 10 dtostrf(value/10,3,1,val); // hum has to be divided by 10
break; break;
case '7' : case '7' :
mactopic = mactopic + "/" + "lux"; mactopic = mactopic + subjectBTtoMQTTlux;
dtostrf(value,0,0,val); dtostrf(value,0,0,val);
break; break;
case '8' : case '8' :
mactopic = mactopic + "/" + "moi"; mactopic = mactopic + subjectBTtoMQTTmoi;
dtostrf(value,0,0,val); dtostrf(value,0,0,val);
break; break;
default: default:
+6
View File
@@ -25,6 +25,12 @@
*/ */
/*----------------------BT topics & parameters-------------------------*/ /*----------------------BT topics & parameters-------------------------*/
#define subjectBTtoMQTT Base_Topic Gateway_Name "/BTtoMQTT/" #define subjectBTtoMQTT Base_Topic Gateway_Name "/BTtoMQTT/"
#define subjectBTtoMQTTrssi "/rssi"
#define subjectBTtoMQTTtem "/tem"
#define subjectBTtoMQTThum "/hum"
#define subjectBTtoMQTTmoi "/moi"
#define subjectBTtoMQTTfer "/fer"
#define subjectBTtoMQTTlux "/lux"
#define TimeBtw_Read 55555 //define the time between 2 scans #define TimeBtw_Read 55555 //define the time between 2 scans
#define Scan_duration 10 //define the time for a scan #define Scan_duration 10 //define the time for a scan
#define HM-10 #define HM-10