Remote I/O Sensor bus with AT&T flow and M2X cloud

Dependencies:   DHT11 FXOS8700CQ MODSERIAL mbed

Fork of Avnet_ATT_Cellular_IOT by Avnet

Revision:
64:09004cd610df
Parent:
61:f6b93129f954
Child:
68:6e311c747045
--- a/sensors.cpp	Mon Aug 01 20:19:58 2016 +0000
+++ b/sensors.cpp	Mon Aug 01 23:32:55 2016 +0000
@@ -110,13 +110,13 @@
     if (SN_7020[4] != 0x14)
     {
         bSi7020_present = false;
-        printf("Si7020 sensor not found\n");
+        PRINTF("Si7020 sensor not found\n");
     }
     else 
     {
         bSi7020_present = true;
-        printf("Si7020 SN = 0x%02X%02X%02X%02X%02X%02X%02X%02X\n", SN_7020[0], SN_7020[1], SN_7020[2], SN_7020[3], SN_7020[4], SN_7020[5], SN_7020[6], SN_7020[7]);
-        printf("Si7020 Version# = 0x%02X\n", Ver_7020[0]);
+        PRINTF("Si7020 SN = 0x%02X%02X%02X%02X%02X%02X%02X%02X\n", SN_7020[0], SN_7020[1], SN_7020[2], SN_7020[3], SN_7020[4], SN_7020[5], SN_7020[6], SN_7020[7]);
+        PRINTF("Si7020 Version# = 0x%02X\n", Ver_7020[0]);
     } //bool bSi7020_present = true
 
 } //Init_Si7020()
@@ -133,19 +133,19 @@
         wait (0.05); //wait for measurement.  Can also keep reading until no NACK is received
         //I2C_WriteSingleByte(Si7020_PMOD_I2C_ADDR, 0xE5, false); //Hold mod, the device does a clock stretch on the read until it is done (crashes the I2C bus...
         I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &Humidity[0], 2); //read humidity
-        //printf("Read Si7020 Humidity = 0x%02X%02X\n", Humidity[0], Humidity[1]);
+        //PRINTF("Read Si7020 Humidity = 0x%02X%02X\n", Humidity[0], Humidity[1]);
         int rh_code = (Humidity[0] << 8) + Humidity[1];
         float fRh = (125.0*rh_code/65536.0) - 6.0; //from datasheet
-        //printf("Si7020 Humidity = %*.*f %%\n", 4, 2, fRh); //double % sign for escape //printf("%*.*f\n", myFieldWidth, myPrecision, myFloatValue);
+        //PRINTF("Si7020 Humidity = %*.*f %%\n", 4, 2, fRh); //double % sign for escape //PRINTF("%*.*f\n", myFieldWidth, myPrecision, myFloatValue);
         sprintf(SENSOR_DATA.Humidity_Si7020, "%0.2f", fRh);
         
         //Command to read temperature when humidity is already done:
         I2C_WriteSingleByte(Si7020_PMOD_I2C_ADDR, 0xE0, false);
         I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &Temperature[0], 2); //read temperature
-        //printf("Read Si7020 Temperature = 0x%02X%02X\n", Temperature[0], Temperature[1]);
+        //PRINTF("Read Si7020 Temperature = 0x%02X%02X\n", Temperature[0], Temperature[1]);
         int temp_code = (Temperature[0] << 8) + Temperature[1];
         float fTemp = (175.72*temp_code/65536.0) - 46.85; //from datasheet in Celcius
-        //printf("Si7020 Temperature = %*.*f deg C\n", 4, 2, fTemp);
+        //PRINTF("Si7020 Temperature = %*.*f deg C\n", 4, 2, fTemp);
         sprintf(SENSOR_DATA.Temperature_Si7020, "%0.2f", fTemp);
     } //bool bSi7020_present = true
 
@@ -221,12 +221,12 @@
     if (readbyte != 0x45)
     {
         bSi1145_present = false;
-        printf("Si1145 sensor not found\n");
+        PRINTF("Si1145 sensor not found\n");
     }
     else
     {
         bSi1145_present = true;
-        printf("Si1145 Part ID : 0x%02X\n", readbyte);
+        PRINTF("Si1145 Part ID : 0x%02X\n", readbyte);
         //Initialize Si1145 by writing to HW_KEY (I2C Register 0x07 = 0x17)
         WriteTo_Si1145_Register(REG_HW_KEY, HW_KEY_VAL0);
     
@@ -261,28 +261,28 @@
         int PS1 = ReadFrom_Si1145_Register(REG_PS1_DATA0) + 256 * ReadFrom_Si1145_Register(REG_PS1_DATA1);
         int PS2 = ReadFrom_Si1145_Register(REG_PS2_DATA0) + 256 * ReadFrom_Si1145_Register(REG_PS2_DATA1);
         int PS3 = ReadFrom_Si1145_Register(REG_PS3_DATA0) + 256 * ReadFrom_Si1145_Register(REG_PS3_DATA1);
-        //printf("PS1_Data = %d\n", PS1);
-        //printf("PS2_Data = %d\n", PS2);
-        //printf("PS3_Data = %d\n", PS3);
+        //PRINTF("PS1_Data = %d\n", PS1);
+        //PRINTF("PS2_Data = %d\n", PS2);
+        //PRINTF("PS3_Data = %d\n", PS3);
         //OBJECT PRESENT?
 #if (0)
         if(PS1 < 22000){
-            //printf("Object Far\n");
+            //PRINTF("Object Far\n");
             sprintf(SENSOR_DATA.Proximity, "Object Far\0");
         }
         else if(PS1 < 24000)
         {
-            //printf("Object in Vicinity\n");
+            //PRINTF("Object in Vicinity\n");
             sprintf(SENSOR_DATA.Proximity, "Object in Vicinity\0");
         }
         else if (PS1 < 30000)
         {
-            //printf("Object Near\n");
+            //PRINTF("Object Near\n");
             sprintf(SENSOR_DATA.Proximity, "Object Near\0");
         }
         else
         {
-            //printf("Object Very Near\n");
+            //PRINTF("Object Very Near\n");
             sprintf(SENSOR_DATA.Proximity, "Object Very Near\0");
         }
 #else    
@@ -295,17 +295,17 @@
         int ALS_VIS = ReadFrom_Si1145_Register(REG_ALS_VIS_DATA0) + 256 * ReadFrom_Si1145_Register(REG_ALS_VIS_DATA1);
         int ALS_IR = ReadFrom_Si1145_Register(REG_ALS_IR_DATA0) + 256 * ReadFrom_Si1145_Register(REG_ALS_IR_DATA1);
         int UV_INDEX = ReadFrom_Si1145_Register(REG_UVINDEX0) + 256 * ReadFrom_Si1145_Register(REG_UVINDEX1);
-        //printf("ALS_VIS_Data = %d\n", ALS_VIS);
-        //printf("ALS_IR_Data = %d\n", ALS_IR);
-        //printf("UV_INDEX_Data = %d\n", UV_INDEX);
+        //PRINTF("ALS_VIS_Data = %d\n", ALS_VIS);
+        //PRINTF("ALS_IR_Data = %d\n", ALS_IR);
+        //PRINTF("UV_INDEX_Data = %d\n", UV_INDEX);
     
-        //printf("Ambient Light Visible  Sensor = %d\n", ALS_VIS);
+        //PRINTF("Ambient Light Visible  Sensor = %d\n", ALS_VIS);
         sprintf(SENSOR_DATA.AmbientLightVis, "%d", ALS_VIS);
-        //printf("Ambient Light Infrared Sensor = %d\n", ALS_IR);
+        //PRINTF("Ambient Light Infrared Sensor = %d\n", ALS_IR);
         sprintf(SENSOR_DATA.AmbientLightIr, "%d", ALS_IR);
         //float fUV_value = (UV_INDEX -50.0)/10000.0;
         float fUV_value = (UV_INDEX)/100.0; //this is the aux reading
-        //printf("UV_Data = %0.2f\n", fUV_value);
+        //PRINTF("UV_Data = %0.2f\n", fUV_value);
         sprintf(SENSOR_DATA.UVindex, "%0.2f", fUV_value);
     } //bSi1145_present = true
 } //Read_Si1145()
@@ -321,14 +321,14 @@
     FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1)
     int iWhoAmI = fxos.get_whoami();
 
-    printf("FXOS8700CQ WhoAmI = %X\r\n", iWhoAmI);
+    PRINTF("FXOS8700CQ WhoAmI = %X\r\n", iWhoAmI);
     // Iterrupt for active-low interrupt line from FXOS
     // Configured with only one interrupt on INT2 signaling Data-Ready
     //fxos_int2.fall(&trigger_fxos_int2);
     if (iWhoAmI != 0xC7)
     {
         bMotionSensor_present = false;
-        printf("FXOS8700CQ motion sensor not found\n");
+        PRINTF("FXOS8700CQ motion sensor not found\n");
     }
     else
     {
@@ -346,7 +346,7 @@
     {
         fxos.enable();
         fxos.get_data(&accel_data, &magn_data);
-        //printf("Roll=%5d, Pitch=%5d, Yaw=%5d;\r\n", magn_data.x, magn_data.y, magn_data.z);
+        //PRINTF("Roll=%5d, Pitch=%5d, Yaw=%5d;\r\n", magn_data.x, magn_data.y, magn_data.z);
         sprintf(SENSOR_DATA.MagnetometerX, "%5d", magn_data.x);
         sprintf(SENSOR_DATA.MagnetometerY, "%5d", magn_data.y);
         sprintf(SENSOR_DATA.MagnetometerZ, "%5d", magn_data.z);
@@ -356,7 +356,7 @@
         fAccelScaled_x = (accel_data.x/2048.0);
         fAccelScaled_y = (accel_data.y/2048.0);
         fAccelScaled_z = (accel_data.z/2048.0);
-        //printf("Acc: X=%2.3f Y=%2.3f Z=%2.3f;\r\n", fAccelScaled_x, fAccelScaled_y, fAccelScaled_z);
+        //PRINTF("Acc: X=%2.3f Y=%2.3f Z=%2.3f;\r\n", fAccelScaled_x, fAccelScaled_y, fAccelScaled_z);
         sprintf(SENSOR_DATA.AccelX, "%2.3f", fAccelScaled_x);
         sprintf(SENSOR_DATA.AccelY, "%2.3f", fAccelScaled_y);
         sprintf(SENSOR_DATA.AccelZ, "%2.3f", fAccelScaled_z);
@@ -382,14 +382,14 @@
     if (i)
     {
         bHTS221_present = true;
-        pc.printf(BLU "HTS221 Detected (0x%02X)\n\r",i);
-        printf("  Temp  is: %0.2f F \n\r",CTOF(hts221.readTemperature()));
-        printf("  Humid is: %02d %%\n\r",hts221.readHumidity());
+        PRINTF(BLU "HTS221 Detected (0x%02X)\n\r",i);
+        PRINTF("  Temp  is: %0.2f F \n\r",CTOF(hts221.readTemperature()));
+        PRINTF("  Humid is: %02d %%\n\r",hts221.readHumidity());
     }
     else
     {
         bHTS221_present = false;
-        pc.printf(RED "HTS221 NOT DETECTED!\n\r");
+        PRINTF(RED "HTS221 NOT DETECTED!\n\r");
     }
 } //Init_HTS221()
 
@@ -431,7 +431,7 @@
 //********************************************************************************************************************************************
 int parse_usbhost_message()
 {
-    //printf("String = %s\n", usbhost_rx_string); //test
+    //PRINTF("String = %s\n", usbhost_rx_string); //test
     uint8_t length;
     uint8_t x ;
     //It seems that sscanf needs 11 characters to store a 7-character number.  There must be some formatting and termination values...
@@ -442,7 +442,7 @@
     int args_assigned = sscanf(usbhost_rx_string, "%[^','],%[^','],%[^','],%[^','],%[^','],%[^','],%[^','],%[^','],%[^\n]", Record[0], Record[1], Record[2], Record[3], Record[4], Record[5], Record[6], Record[7],  StringRecord);
 
     //StringRecord[109] = '\0';
-    //printf("Last = %s\n", StringRecord); //test
+    //PRINTF("Last = %s\n", StringRecord); //test
 
     if (args_assigned == 9)
     { //sscanf was able to assign all 9 values
@@ -468,7 +468,7 @@
             f_sensor7_value = atof(Record[6]);
             f_sensor8_value = atof(Record[7]);
             sprintf(usb_sensor_string,StringRecord);
-            //printf("Received = %s, %s, %s, %s, %s, %s, %s, %s, %s\n", Record[0], Record[1], Record[2], Record[3], Record[4], Record[5], Record[6], Record[7], usb_sensor_string); //test
+            //PRINTF("Received = %s, %s, %s, %s, %s, %s, %s, %s, %s\n", Record[0], Record[1], Record[2], Record[3], Record[4], Record[5], Record[6], Record[7], usb_sensor_string); //test
             sprintf(SENSOR_DATA.Virtual_Sensor1, "%s", Record[0]);
             sprintf(SENSOR_DATA.Virtual_Sensor2, "%s", Record[1]);
             sprintf(SENSOR_DATA.Virtual_Sensor3, "%s", Record[2]);