Mwadime Makokha / Mbed 2 deprecated BlueToothSIM868

Dependencies:   mbed

Revision:
0:3d4b4cf5f0e3
Child:
1:940070f92554
diff -r 000000000000 -r 3d4b4cf5f0e3 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 13 22:08:48 2019 +0000
@@ -0,0 +1,51 @@
+#include "global.h"
+char modem_response[255];
+Timer t;
+ int main(){
+     DEBUG_PRINTLN("PROGRAM START");
+     MODEM_PRINTLN("AT");
+      get_response(1000,false);
+     if((strcmp(modem_response,"OK") != 0)){
+         DEBUG_PRINTLN("%s",modem_response);
+         return 0;
+    }
+    DEBUG_PRINTLN("%s",modem_response);
+    MODEM_PRINTLN("AT+BTHOST?");
+    get_response(1000,false);
+    DEBUG_PRINTLN("%s",modem_response);
+    MODEM_PRINTLN("AT+BTSTATUS?");
+    get_response(1000,false);
+    DEBUG_PRINTLN("%s",modem_response);
+    MODEM_PRINTLN("AT+BTPOWER=1");
+    get_response(1000,false);
+    DEBUG_PRINTLN("%s",modem_response);
+    MODEM_PRINTLN("AT+BTSCAN=1,10");
+    get_response(10000,true);
+    DEBUG_PRINTLN("%s",modem_response);
+ while(1){
+    
+ } 
+    
+}
+void get_response(uint16_t timeout,bool is_multiline){
+    int arr_index=0;
+    while(timeout){
+    if(arr_index >= 254) break;
+    while(modemSerial.readable()){
+    char c = modemSerial.getc();
+    if(c == '\r') continue;
+    if(c=='\n' && arr_index==0){
+    continue;
+    }
+    if(c=='\n' && !is_multiline){
+    break;    
+    }
+    modem_response[arr_index] = c;
+    arr_index++;
+    }
+    timeout--;
+    wait_ms(1);
+    }
+    modem_response[arr_index] = 0;
+    
+}