Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: BT.cpp
- Revision:
- 3:936c6d909891
- Parent:
- 2:83d03d7148a5
- Child:
- 4:6f32ed1480a4
--- a/BT.cpp Thu Nov 14 22:38:08 2019 +0000 +++ b/BT.cpp Wed Jan 08 11:23:14 2020 +0000 @@ -2,8 +2,13 @@ Serial* BT::modemSerial =0; BT::BT(Serial &port){ modemSerial = &port; + //Test if the modem is good send_bt_cmd("ATE0"); get_response(1000,false); + DEBUG_PRINTLN("%s",modem_response); + //Power the device and unpair all devices + power_bt_device(1); + bt_unpair_device(); } void BT::get_bt_status(){ send_bt_cmd("AT+BTSTATUS?"); @@ -50,7 +55,8 @@ } char* BT::get_phone_mac_addr(){ - return "74:e6:0f:b1:45:58"; + return mac_addr_1; + } char BT::get_phone_id(char* addr){ char id=0; @@ -108,33 +114,21 @@ get_response(1000,false); } -void BT::bt_connect_device(char id,char profile_id){ - DEBUG_PRINTLN("%c",id); - DEBUG_PRINTLN("%c",profile_id); - // modemSerial->printf("AT+BTCONNECT=%c,%c\n\r",id,profile_id); - send_bt_cmd("AT+BTCONNECT=1,10"); - get_response(3000,true); +void BT::bt_connect_device(char id){ + modemSerial->printf("AT+BTCONNECT=%c,10\n\r",id); + get_response(2000,true); DEBUG_PRINTLN("%s",modem_response); } -char BT::bt_get_profile_id(char id){ - char profile_id=0; +void BT::bt_disconnect_device(char id){ + modemSerial->printf("AT+BTDISCONN=%c",id); + get_response(2000,true); + DEBUG_PRINTLN("%s",modem_response); +} +void BT::bt_get_profile_id(char id){ modemSerial->printf("AT+BTGETPROF=%c\n\r",id); get_response(2000,true); - int arr_index=0; DEBUG_PRINTLN("%s",modem_response); - while(modem_response[arr_index]!='\n'){ - if(modem_response[arr_index] == ':'){ - if(modem_response[arr_index+1] == ' '){ - profile_id = modem_response[arr_index+2]; - break; - } - profile_id = modem_response[arr_index+1]; - break; - } - arr_index++; - } - return profile_id; } void BT::send_bt_cmd(char* cmd){ @@ -161,4 +155,7 @@ wait_ms(1); } modem_response[arr_index] = 0; +} +char* BT::get_response(){ + return modem_response; } \ No newline at end of file