Fork from Sog Yang

Dependencies:   BNO055_AS7000 NNN50_WIFI_API

Fork of NNN50_BLEWIFISensor by Sog Yang

Revision:
9:d1861b00e0fd
Parent:
8:ff7fdd152f14
Child:
10:248b81efda00
--- a/main.cpp	Thu May 04 05:08:42 2017 +0000
+++ b/main.cpp	Thu May 04 10:43:36 2017 +0000
@@ -28,11 +28,13 @@
 BNO055 imu(p0,p30);
 AS7000 hrm(p0,p30);
 Serial pc(USBTX, USBRX);
+DigitalInOut myOutputPin(USBTX);
 EthernetInterface eth;
 WIFIDevice wifi;
 
 TCPSocketConnection sock_tcp;
-char* ECHO_SERVER_ADDRESS = "10.0.1.13";
+//char* ECHO_SERVER_ADDRESS = "10.0.1.13";
+char* ECHO_SERVER_ADDRESS = "192.168.2.184";
 int ECHO_SERVER_PORT = 1030;
 
 uint8_t initialValueForDOORCharacteristic = 0xFF;
@@ -112,7 +114,8 @@
 
 
 int main (void) {
-        
+    myOutputPin.mode(PullUp); 
+    pc.baud(38400);    
     hrm.enable(); 
     imu.reset();    
     imu.setmode(OPERATION_MODE_NDOF);
@@ -122,15 +125,37 @@
     ble.onEventsToProcess(scheduleBleEventsProcessing);
     ble.init(bleInitComplete);
     
+    int i = 0;
+    int j = 0;
+    BLE_RX_CMD = 0xFF;
+    wait_ms(10);
+    sprintf(out_buffer,"\r\n");
+    
+    
     while (true) {
+        wait_ms(2);
         imu.get_angles(); //query the i2c device
         hrm.hr_only();
-        pc.printf("*HR=%03d#", hrm.hrm.hreat_rate);  
+        wait_ms(8);
+        if (BLE_RX_CMD != 0xA1) {
+            if (i > 40){
+                pc.printf("");
+                pc.printf("*HR=%03d#", hrm.hrm.hreat_rate);
+                i=0;
+            } i++;
+        }
         /* GATT Command 0xA1 Cloud Data Transfer*/
         if (BLE_RX_CMD == 0xA1){
             ADV_manuf[5] = 0xF1; 
             if (isWiFiEnable == true){                 
                 if (isConnect == true) {
+#if 1                    
+                    if (j > 2){
+                        pc.printf("");
+                        pc.printf("*HR=%03d#", hrm.hrm.hreat_rate);
+                        j = 0;
+                    }j++;
+ #endif                   
                     sprintf(out_buffer,"hrm:%03d yaw:%6.2f pitch:%6.2f roll:%6.2f\n", hrm.hrm.hreat_rate, imu.euler.yaw, imu.euler.pitch, imu.euler.roll);
                     sock_tcp.send_all(out_buffer, sizeof(out_buffer) - 1);  
                      isCloudFiling = true;
@@ -155,6 +180,7 @@
         }
         /* GATT Command 0x02 WiFI & Cloud Connection Close*/
          if (BLE_RX_CMD == 0x02){
+            BLE_RX_CMD = 0xFF;
             ADV_manuf[5] = 0xF2;  
             if ( isConnect == true ) {
                 sock_tcp.close(); 
@@ -165,17 +191,20 @@
                 wifi.sleep();
                 isWiFiEnable = false;
             } 
+            while(true) {
+                    if (wifi.is_AP_connected()==0) break; //make sure wifi disconnect
+            }
             if (isConnect == true) isConnect = false;   
             isConnect = false;
             isWiFiEnable = false;
-            isCloudFiling = false;        
-            
-            BLE_RX_CMD = 0xFF;    
+            isCloudFiling = false;      
+             
             ADV_manuf[0] = 0x00;
             ADV_manuf[1] = 0x00;
             ADV_manuf[2] = 0x00;
             ADV_manuf[3] = 0x00;
-            ADV_manuf[4] = 0x00;         
+            ADV_manuf[4] = 0x00;
+            sprintf(out_buffer,"\n");         
         }
         /* GATT Command 0x0 init WiFI & Cloud Connection*/ 
        if (BLE_RX_CMD == 0x00){
@@ -185,7 +214,8 @@
             
             if (isWiFiEnable == false) {
                 eth.init();  
-                wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "SOG", "0227322327"); 
+                //wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "SOG", "0227322327");
+                wifi.setNetwork(M2M_WIFI_SEC_WPA_PSK, "20-4F-5_Guest", "11223344");  
                 eth.connect(); 
                 while(true) {
                     if (wifi.is_AP_connected()==1) break;