蓝牙模块JDY-08找不到Android设备



我有一个JDY-08 MASTER,它扫描查找myDeviceName,并在找到该设备名称时触发一个函数。

String get_ble_scan_data(void){
String  final_result = "";
String result = "";//reset and declare
String extract = set_ble("AT+SCAN1");//scan for device name, signal strength and mac address
String extract2 = set_ble("AT+GETDCD");//get number of device found
//now we are going to check for which extraction has the data we interested in
if((extract.length() > threshold or extract.length() > threshold)){
result = extract;//pass extract as result
if(extract2.length() > extract.length()){//check which is bigger
result = extract2;//pass extract2 as result if its bigger in length than extract
}
}
if(result.length() > 0){//add filter and execution here
String filter = result;//copy
result = "";// reset
while(filter.indexOf('=') > -1){// we use the char = as a seperator
filter = filter.substring(filter.indexOf('=') + 1);//remove strings before seperator
result += filter.substring(0, filter.indexOf('n')) + ' '; //extract till newline character
filter = filter.substring(filter.indexOf(result) + result.length());//remove extracted result so we go on to next extraction of same result if there is more device picked up
detect
}
result.trim();//remove spaces at the end or start if any
final_result = result;
}
return final_result;
}
void ble_response(String search_result){
String scan_result = search_result;//do bluetooth scan
if(scan_result.indexOf(myDeviceName) > -1 ){//when data present in scan and it contains desired key
if(scan_result.indexOf(' ') == -1){//if only one ble is picked up
ble_macaddress = scan_result.substring(0, scan_result.indexOf(','));
scan_result = scan_result.substring(scan_result.indexOf(ble_macaddress) + 1 + ble_macaddress.length(), scan_result.length());//remove mac address
ble_strength = scan_result.substring(0, scan_result.indexOf(','));
ble_name = scan_result.substring(scan_result.indexOf(ble_strength) + 1 + ble_strength.length(), scan_result.length());//remove mac address
if(((int) ble_strength.toFloat()) >= trigger_threshold and ble_name == key){
trigger_action();
}
}else{//if multiple ble is picked up
String cut = "";
while(scan_result.indexOf(',') > -1){//while there is still result to be processed
cut = scan_result.substring(0, scan_result.indexOf(' '));
scan_result = scan_result.substring(scan_result.indexOf(cut) + 1 + cut.length(), scan_result.length());
if(cut.indexOf(myDeviceName) > -1){//only analyze if it contains key
ble_macaddress = cut.substring(0, cut.indexOf(','));
cut = cut.substring(cut.indexOf(ble_macaddress) + 1 + ble_macaddress.length(), cut.length());//remove mac address
ble_strength = cut.substring(0, cut.indexOf(','));
ble_name = cut.substring(cut.indexOf(ble_strength) + 1 + ble_strength.length(), cut.length());//remove mac address
if(((int) ble_strength.toFloat()) >= trigger_threshold and ble_name == key){
trigger_action();
break;
}
}
}
}
}

如果我使用另一个带有一个按钮的JDY-08设备,它会找到该设备并触发操作:


if(!digitalRead(11)){//if button is pushed///////
delay(500);
set_ble("AT+NAMEmyDeviceName");//change ble name
while(!digitalRead(11));//do nothing while button is still pressed
delay(2000);//allow time before name change back
set_ble("AT+NAMEJDY-08");//change name back

但当我使用手机时,它不会触发动作:

private void advertise(){
final BluetoothLeAdvertiser advertiser = BluetoothAdapter.getDefaultAdapter().getBluetoothLeAdvertiser();
final AdvertiseSettings settings = new AdvertiseSettings.Builder()
.setAdvertiseMode( AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY )
.setTxPowerLevel( AdvertiseSettings.ADVERTISE_TX_POWER_HIGH )
.setConnectable( true )
.build();
final AdvertiseData data = new AdvertiseData.Builder()
.setIncludeDeviceName( true )
.build();
final AdvertiseCallback advertisingCallback = new AdvertiseCallback() {
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
super.onStartSuccess(settingsInEffect);
}
@Override
public void onStartFailure(int errorCode) {
Log.e( "BLE", "Advertising onStartFailure: " + errorCode );
super.onStartFailure(errorCode);
}
};
advertiser.startAdvertising(settings,data,advertisingCallback);
final Handler myTimerHandler = new Handler();
myTimerHandler.postDelayed(
new Runnable()
{
@Override
public void run(){
advertiser.stopAdvertising(advertisingCallback);
}
} , 30000);
}

我还将意图用于BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE.

使用NRFConnect应用程序,我可以看到JDY-08按钮设备是如何更改设备名称的(这会触发JDY-08 MASTER上的操作(。我也可以看到带有myDeviceName的Android设备,但这不会触发操作。我在安卓应用程序中遗漏了什么吗?

问题是JDY Master只收到了JDY设备的名称。所有其他设备仅显示mac地址和信号强度。

最新更新