Fork from Sog Yang

Dependencies:   BNO055_AS7000 NNN50_WIFI_API

Fork of NNN50_BLEWIFISensor by Sog Yang

Revision:
13:5b96cb34bc70
Parent:
11:54a1a576df9f
--- a/main.cpp	Sat May 06 01:41:48 2017 +0000
+++ b/main.cpp	Mon May 22 08:07:48 2017 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 #include "BNO055.h"
-#include "AS7000.h"
+//#include "AS7000.h"
 #include "ble/BLE.h"
 #include "ble/Gap.h"
 #include "ble/services/BatteryService.h"
@@ -8,7 +8,7 @@
 #include "EthernetInterface.h"
 #include "WIFIDevice.h"
 
-#define DEBUG_LOG 0
+#define DEBUG_LOG 1
 
 union IP {
     unsigned int ip;
@@ -26,16 +26,16 @@
 DOORService *doorServicePtr;
 
 BNO055 imu(p0,p30);
-AS7000 hrm(p0,p30);
+//AS7000 hrm(p0,p30);
 Serial pc(USBTX, USBRX);
 DigitalInOut myOutputPin(USBTX);
 EthernetInterface eth;
 WIFIDevice wifi;
 
 TCPSocketConnection sock_tcp;
-char* AP_SSID = "SOG";
-char* AP_PWD = "1122334455667788";
-char* TCP_SERVER_ADDRESS = "10.0.1.13";
+char* AP_SSID = "TWCYNPC0209_Mac mini";
+char* AP_PWD = "mayday55555";
+char* TCP_SERVER_ADDRESS = "192.168.2.7";
 int TCP_SERVER_PORT = 1030;
 
 uint8_t initialValueForDOORCharacteristic = 0xFF;
@@ -117,7 +117,7 @@
 int main (void) {
     myOutputPin.mode(PullUp); 
     pc.baud(38400);    
-    hrm.enable(); 
+    imu.enable(); 
     imu.reset();    
     imu.setmode(OPERATION_MODE_NDOF);
     
@@ -134,13 +134,14 @@
     
     
     while (true) {
+        wait_ms(8);
+        imu.hr_only();
         wait_ms(2);
         imu.get_angles(); //query the i2c device
-        hrm.hr_only();
         wait_ms(8);
         if (BLE_RX_CMD != 0xA1) {
             if (i > 40){
-                pc.printf("*HR=%03d#", hrm.hrm.hreat_rate);
+                pc.printf("*HR=%03d# yaw:%6.2f#", imu.hrm.hreat_rate, imu.euler.yaw);
                 i=0;
             } i++;
         }
@@ -150,19 +151,19 @@
             if (isWiFiEnable == true){                 
                 if (isConnect == true) {                   
                     if (j > 2){
-                        pc.printf("*HR=%03d#", hrm.hrm.hreat_rate);
+                        pc.printf("*HR=%03d#", imu.hrm.hreat_rate);
                         j = 0;
                     }j++;                 
-                    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);
+                    sprintf(out_buffer,"hrm:%03d yaw:%6.2f pitch:%6.2f roll:%6.2f\n", imu.hrm.hreat_rate, imu.euler.yaw, imu.euler.pitch, imu.euler.roll);
+                    //sock_tcp.set_blocking(false, 1500);// Timeout after 0.2s
                     sock_tcp.send_all(out_buffer, sizeof(out_buffer) - 1);  
-                    sock_tcp.set_blocking(false, 200);// Timeout after 0.2s
                      isCloudFiling = true;
                 } else {
                     if (sock_tcp.connect(TCP_SERVER_ADDRESS, TCP_SERVER_PORT) < 0) {
                         isConnect = false;
                         BLE_RX_CMD = 0xFF;
 #if DEBUG_LOG                        
-                        pc.printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+                        pc.printf("Unable to connect to (%s) on port (%d)\n", TCP_SERVER_ADDRESS, TCP_SERVER_PORT);
 #endif                        
                         ADV_manuf[4] = 0xCF;
                         BLE_RX_CMD = 0xFF;
@@ -170,7 +171,7 @@
                          isConnect = true; 
                           ADV_manuf[4] = 0xF1;
 #if DEBUG_LOG                           
-                         pc.printf("Connected to Server at %s\n",ECHO_SERVER_ADDRESS);
+                         pc.printf("Connected to Server at %s\n",TCP_SERVER_ADDRESS);
 #endif                         
                     }
                 }
@@ -217,7 +218,7 @@
                 while(true) {
                     if (wifi.is_AP_connected()==1) break;
                 }
-                sock_tcp.set_blocking(false, 1200);// Timeout after 1.2s 
+                //sock_tcp.set_blocking(false, 1200);// Timeout after 1.2s 
 #if DEBUG_LOG               
                 pc.printf("Connect Success! \n");
                 pc.printf("MAC: %s\n", eth.getMACAddress());            
@@ -240,7 +241,7 @@
                 if (isWiFiEnable == true) {
                     if (sock_tcp.connect(TCP_SERVER_ADDRESS, TCP_SERVER_PORT) < 0) {
 #if DEBUG_LOG                         
-                            pc.printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+                            pc.printf("Unable to connect to (%s) on port (%d)\n", TCP_SERVER_ADDRESS, TCP_SERVER_PORT);
 #endif                         
                             sock_tcp.close();
                             ADV_manuf[4] = 0xCF;
@@ -249,7 +250,7 @@
                              isCloudFiling = false;
                              ADV_manuf[4] = 0xF1;
 #if DEBUG_LOG                          
-                             pc.printf("Connected to Server at %s\n",ECHO_SERVER_ADDRESS);
+                             pc.printf("Connected to Server at %s\n",TCP_SERVER_ADDRESS);
 #endif     
                         }
                     }