This program connects to a few sensors via I2C and sends the data collected to a WNC Cellular Module which is located on an Avnet WNC-Shield card.

Dependencies:   FXOS8700CQ MODSERIAL mbed

/media/uploads/kevinkeryk/avnet_logo_tagline_rgb.png

Avnet Cellular IoT Instructions

  • One problematic area is setting the MY_SERVER_URL. When you copy the URL from the flow, you must make sure the MY_SERVER_URL is also set to the appropriate server. It can be either "run-east.att.io" or "run-west.att.io".

Useful Links

Adding Additional Sensors

The FLOW_DEVICE_NAME field must contain the name of the instance of the Virtual Starter Kit in FLOW you will be communicating with. Usually this is "vstarterkit001", but if you have problems communicating you can verify this is correct. Note: This device will not be created until you click the “Initialize” input on the Virtual Device tab of the Starter Kit project in FLOW. At that point, it becomes available in M2X and you can see it as the DEVICE SERIAL field under Devices as in the image below. /media/uploads/JMF/vstarterkit.png

Sensors: When executing, the FRDM-K64F board uploads sensor measurements to AT&T’s Flow environment every 5 seconds, using the Cellular shield board. You can adjust how often you want to do this by editing the SENSOR_UPDATE_INTERVAL_MS value in the header file.

Temperature and humidity: By default, the board reports readings from the HTS221 temperature and humidity sensor. These two values are sent to the HTTP IN /climate port in FLOW with field names “temp” and “humidity”. Temperature is in degrees Fahrenheit and humidity is a %. This default assignment is: iSensorsToReport = TEMP_HUMIDITY_ONLY;

Accelerometer: If you want to expand and use the onboard motion sensor, you can also send 3-axis accelerometer information from the board as “accelX”, “accelY”, and “accelZ”. This is useful if you want to know the stationary position of the board with regards to gravity, or whether it is in motion. These readings are in g’s. To send these values, change the assignment to: iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER;

PMOD Sensors: If you have a Silicon Labs sensor module that can plug into the PMOD connector on the Cellular shield, you are able to measure proximity, UV light, ambient visible and infrared light from the Si1145 sensor. This PMOD also has a temperature and humidity sensor, but in this case it is redundant. When enabled, the fields “proximity”, “light_uv”, “light_vis” and “light_ir” are also sent. To enable all these sensors, change the assignment to: iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS;

Connecting the PMOD sensors: Because the pinouts do not align, the SiLabs PMOD sensor board cannot be plugged into the J10 PMOD receptacle on the shield directly. The following wiring instructions must be followed:

SignalJ10ShieldPMOD Color in the image below
VCCPin 6Pin 6Red
GNDPin 5Pin 5Black
SDAPin4Pin 3Green
SCLPin3Pin 2Yellow

/media/uploads/JMF/xyz.jpg

AT&T M2X and FLOW Instructions

M2X & FLOW Instructions

Link to AT&T M2X

M2X

Link to AT&T Flow

FLOW

Avnet WNC-Shield Information

Getting Started with the Avnet WNC-Shield Software

  • This project uses Revision 119 of the MBED library because of I2C implementation differences with the tip (Revision 121).
  • This project uses Revision 4 of the FXOS8700CQ library for sensors.

Easily Modifiable Parameters

Inside the mbed Avnet_ATT_Cellular_IOT project, the parameters needed to customize your board are in the config_me.h file.

  • FLOW parameters: This project assumes you are using a fork of the Starter Kit Base project, which is a reference design created using AT&T’s FLOW (https://flow.att.com) that allows the creation of online virtualization and other IoT functionality. The default parameters in the config_me.h file are done for a specific instance of this project. When you fork the original project, you get your own instance and it will have its own base address. At the bottom of the FLOW environment, when you click on the Endpoints tab, URL information that is specific to your instance is displayed. Of note is the Base URL. In the example below (as in the default mbed project), the Base URL is: https://run-west.att.io/1e464b19cdcde/774c88d68202/86694923d5bf28a/in/flow You have to take note of two parts of this address. The run-west.att.io part is the server URL, and you have to make sure the
  • MY_SERVER_URL field in config_me.h matches this. The rest of the base URL, in green above, needs to be pasted into the FLOW_BASE_URL field.

There is also a FLOW_INPUT_NAME field. This should match the name of the HTTP IN port in the FLOW project that you want to send sensor data to. The default is "/climate", as in the FLOW image below.

/media/uploads/JMF/sf.png

Where is the Binary I compiled

When the COMPILE button is pressed, it compiles your project and links it. The result is placed in the DOWNLOAD folder you use when downloading files from the Internet. It will be called AvnetATT_shape_hackathon_K64F.bin.

Additional Information on Compiling/Configuring

Comprehensive instructions can be found at: Quick Start Instructions

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]);