implement minimum rssi filtering (#482)
This commit is contained in:
1 parent
34d31600ee
commit
6f73160d14
3 files changed
+45
-3
No files matched your search
@@ -72,6 +72,20 @@ you can also force a scan to be done by the following command:
|
|||||||
|
|
||||||
Once done the previous value of interval will be recovered.
|
Once done the previous value of interval will be recovered.
|
||||||
|
|
||||||
|
The default value is set into config_BT.h
|
||||||
|
|
||||||
|
## Setting the minimum RSSI accepted to publish device data
|
||||||
|
|
||||||
|
If you want to change the minimum RSSI value accepted for a device to be published, you can change it by MQTT. For example if you want to set -80
|
||||||
|
|
||||||
|
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"minrssi":-80}'`
|
||||||
|
|
||||||
|
you can also accept all the devices by the following command:
|
||||||
|
|
||||||
|
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"minrssi":0}'`
|
||||||
|
|
||||||
|
The default value is set into config_BT.h
|
||||||
|
|
||||||
## Other
|
## Other
|
||||||
|
|
||||||
To check your hm10 firmware version upload a serial sketch to the nodemcu (this will enable communication directly with the hm10) and launch the command:
|
To check your hm10 firmware version upload a serial sketch to the nodemcu (this will enable communication directly with the hm10) and launch the command:
|
||||||
|
|||||||
+29
-3
@@ -319,9 +319,6 @@ void MiBandDiscovery(char * mac){
|
|||||||
#include "soc/timer_group_struct.h"
|
#include "soc/timer_group_struct.h"
|
||||||
#include "soc/timer_group_reg.h"
|
#include "soc/timer_group_reg.h"
|
||||||
|
|
||||||
//Time used to wait for an interval before resending BLE infos
|
|
||||||
unsigned long timeBLE= 0;
|
|
||||||
|
|
||||||
//core on which the BLE detection task will run
|
//core on which the BLE detection task will run
|
||||||
static int taskCore = 0;
|
static int taskCore = 0;
|
||||||
|
|
||||||
@@ -370,6 +367,7 @@ void MiBandDiscovery(char * mac){
|
|||||||
BLEdata.set("servicedata", service_data);
|
BLEdata.set("servicedata", service_data);
|
||||||
#endif
|
#endif
|
||||||
BLEdata.set("servicedatauuid", (char *)advertisedDevice.getServiceDataUUID(j).toString().c_str());
|
BLEdata.set("servicedatauuid", (char *)advertisedDevice.getServiceDataUUID(j).toString().c_str());
|
||||||
|
if(abs((int)BLEdata["rssi"]|0) < abs(Minrssi)) { // publish only the devices close enough
|
||||||
pub((char *)mactopic.c_str(),BLEdata);
|
pub((char *)mactopic.c_str(),BLEdata);
|
||||||
if (strstr(BLEdata["servicedatauuid"].as<char*>(),"fe95") != NULL){ //Mi FLora, Mi jia, Cleargrass, LYWDS02
|
if (strstr(BLEdata["servicedatauuid"].as<char*>(),"fe95") != NULL){ //Mi FLora, Mi jia, Cleargrass, LYWDS02
|
||||||
trc("Processing BLE device data");
|
trc("Processing BLE device data");
|
||||||
@@ -447,9 +445,16 @@ void MiBandDiscovery(char * mac){
|
|||||||
#endif
|
#endif
|
||||||
process_miband(service_data,mac);
|
process_miband(service_data,mac);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
trc("Low rssi, device filtered");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
if(abs((int)BLEdata["rssi"]|0) < abs(Minrssi)) { // publish only the devices close enough
|
||||||
pub((char *)mactopic.c_str(),BLEdata); // publish device even if there is no service data
|
pub((char *)mactopic.c_str(),BLEdata); // publish device even if there is no service data
|
||||||
|
}else{
|
||||||
|
trc("Low rssi, device filtered");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
trc(F("Filtered mac device"));
|
trc(F("Filtered mac device"));
|
||||||
@@ -487,8 +492,11 @@ void MiBandDiscovery(char * mac){
|
|||||||
|
|
||||||
void setupBT(){
|
void setupBT(){
|
||||||
BLEinterval = TimeBtw_Read;
|
BLEinterval = TimeBtw_Read;
|
||||||
|
Minrssi = MinimumRSSI;
|
||||||
trc(F("BLEinterval btw scans"));
|
trc(F("BLEinterval btw scans"));
|
||||||
trc(BLEinterval);
|
trc(BLEinterval);
|
||||||
|
trc(F("Minrssi"));
|
||||||
|
trc(Minrssi);
|
||||||
// we setup a task with priority one to avoid conflict with other gateways
|
// we setup a task with priority one to avoid conflict with other gateways
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
coreTask, /* Function to implement the task */
|
coreTask, /* Function to implement the task */
|
||||||
@@ -524,8 +532,11 @@ void MiBandDiscovery(char * mac){
|
|||||||
|
|
||||||
void setupBT() {
|
void setupBT() {
|
||||||
BLEinterval = TimeBtw_Read;
|
BLEinterval = TimeBtw_Read;
|
||||||
|
Minrssi = MinimumRSSI;
|
||||||
trc(F("BLEinterval btw scans"));
|
trc(F("BLEinterval btw scans"));
|
||||||
trc(BLEinterval);
|
trc(BLEinterval);
|
||||||
|
trc(F("Minrssi"));
|
||||||
|
trc(Minrssi);
|
||||||
softserial.begin(9600);
|
softserial.begin(9600);
|
||||||
softserial.print(F("AT+ROLE1"));
|
softserial.print(F("AT+ROLE1"));
|
||||||
delay(100);
|
delay(100);
|
||||||
@@ -603,6 +614,7 @@ void MiBandDiscovery(char * mac){
|
|||||||
#ifdef pubBLEServiceData
|
#ifdef pubBLEServiceData
|
||||||
BLEdata.set("servicedata", (char *)service_data.c_str());
|
BLEdata.set("servicedata", (char *)service_data.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
if(abs((int)BLEdata["rssi"]|0) < abs(Minrssi)) { // publish only the devices close enough
|
||||||
pub((char *)topic.c_str(),BLEdata);
|
pub((char *)topic.c_str(),BLEdata);
|
||||||
int pos = -1;
|
int pos = -1;
|
||||||
pos = strpos(d[5].extract,"209800");
|
pos = strpos(d[5].extract,"209800");
|
||||||
@@ -663,6 +675,9 @@ void MiBandDiscovery(char * mac){
|
|||||||
process_milamp((char *)service_data.c_str(),d[0].extract);
|
process_milamp((char *)service_data.c_str(),d[0].extract);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}else{
|
||||||
|
trc("Low rssi, device filtered");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -908,6 +923,17 @@ void MQTTtoBT(char * topicOri, JsonObject& BTdata) { // json object decoding
|
|||||||
BLEinterval = prevBLEinterval; // as 0 was just used as a command we recover previous scan duration
|
BLEinterval = prevBLEinterval; // as 0 was just used as a command we recover previous scan duration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// MinRSSI set
|
||||||
|
if (BTdata.containsKey("minrssi")){
|
||||||
|
trc(F("Min RSSI"));
|
||||||
|
// storing Min RSSI for further use if needed
|
||||||
|
trc("previous Minrssi");
|
||||||
|
trc(Minrssi);
|
||||||
|
// set Min RSSI if present if not setting default value
|
||||||
|
Minrssi = (unsigned int)BTdata["minrssi"];
|
||||||
|
trc("new Minrssi");
|
||||||
|
trc(Minrssi);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ extern void MQTTtoBT(char * topicOri, JsonObject& RFdata);
|
|||||||
#define subjectBTtoMQTT Base_Topic Gateway_Name "/BTtoMQTT/"
|
#define subjectBTtoMQTT Base_Topic Gateway_Name "/BTtoMQTT/"
|
||||||
#define subjectMQTTtoBTset Base_Topic Gateway_Name "/commands/MQTTtoBT/set"
|
#define subjectMQTTtoBTset Base_Topic Gateway_Name "/commands/MQTTtoBT/set"
|
||||||
#define TimeBtw_Read 55555 //define default time between 2 scans
|
#define TimeBtw_Read 55555 //define default time between 2 scans
|
||||||
|
#define MinimumRSSI -90 //default minimum rssi value, all the devices below -90 will not be reported
|
||||||
#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
|
||||||
//#define HM-11 // uncomment this line if you use HM-11 and comment the line above
|
//#define HM-11 // uncomment this line if you use HM-11 and comment the line above
|
||||||
@@ -45,6 +46,7 @@ extern void MQTTtoBT(char * topicOri, JsonObject& RFdata);
|
|||||||
#define subjectHomePresence Base_Topic "home_presence/" Gateway_Name // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name)
|
#define subjectHomePresence Base_Topic "home_presence/" Gateway_Name // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name)
|
||||||
|
|
||||||
unsigned int BLEinterval ; //time between 2 scans
|
unsigned int BLEinterval ; //time between 2 scans
|
||||||
|
int Minrssi ; //minimum rssi value
|
||||||
|
|
||||||
struct BLEdevice{
|
struct BLEdevice{
|
||||||
char macAdr[13];
|
char macAdr[13];
|
||||||
|
|||||||
Reference in new issue
Block a user