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

Committer:
JMF
Date:
Fri Jul 15 13:17:26 2016 +0000
Revision:
28:886833917643
Parent:
11:e6602513730f
Child:
68:6e311c747045
comment cleanup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:9d5134074d84 1
JMF 0:9d5134074d84 2 #include "HTS221.h"
JMF 0:9d5134074d84 3
JMF 0:9d5134074d84 4
JMF 0:9d5134074d84 5 // ------------------------------------------------------------------------------
JMF 0:9d5134074d84 6 //jmf -- define I2C pins and functions to read & write to I2C device
JMF 0:9d5134074d84 7
JMF 0:9d5134074d84 8 #include <string>
JMF 0:9d5134074d84 9 #include "mbed.h"
JMF 0:9d5134074d84 10
stefanrousseau 11:e6602513730f 11 #include "hardware.h"
JMF 28:886833917643 12 //I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used. Defined in a
JMF 28:886833917643 13 //common locatioin since sensors also use I2C
JMF 0:9d5134074d84 14
JMF 0:9d5134074d84 15 // Read a single unsigned char from addressToRead and return it as a unsigned char
JMF 0:9d5134074d84 16 unsigned char HTS221::readRegister(unsigned char slaveAddress, unsigned char ToRead)
JMF 0:9d5134074d84 17 {
JMF 0:9d5134074d84 18 char data = ToRead;
JMF 0:9d5134074d84 19
stefanrousseau 11:e6602513730f 20 //i2c.write(slaveAddress, &data, 1, 0);
stefanrousseau 11:e6602513730f 21 i2c.write(slaveAddress, &data, 1, 1); //by Stefan
JMF 0:9d5134074d84 22 i2c.read(slaveAddress, &data, 1, 0);
JMF 0:9d5134074d84 23 return data;
JMF 0:9d5134074d84 24 }
JMF 0:9d5134074d84 25
JMF 0:9d5134074d84 26 // Writes a single unsigned char (dataToWrite) into regToWrite
JMF 0:9d5134074d84 27 int HTS221::writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite)
JMF 0:9d5134074d84 28 {
JMF 0:9d5134074d84 29 const char data[] = {regToWrite, dataToWrite};
JMF 0:9d5134074d84 30
JMF 0:9d5134074d84 31 return i2c.write(slaveAddress,data,2,0);
JMF 0:9d5134074d84 32 }
JMF 0:9d5134074d84 33
JMF 0:9d5134074d84 34
JMF 0:9d5134074d84 35 //jmf end
JMF 0:9d5134074d84 36 // ------------------------------------------------------------------------------
JMF 0:9d5134074d84 37
JMF 1:af7a42f7d465 38 //static inline int humidityReady(uint8_t data) {
JMF 1:af7a42f7d465 39 // return (data & 0x02);
JMF 1:af7a42f7d465 40 //}
JMF 1:af7a42f7d465 41 //static inline int temperatureReady(uint8_t data) {
JMF 1:af7a42f7d465 42 // return (data & 0x01);
JMF 1:af7a42f7d465 43 //}
JMF 0:9d5134074d84 44
JMF 0:9d5134074d84 45
JMF 0:9d5134074d84 46 HTS221::HTS221(void) : _address(HTS221_ADDRESS)
JMF 0:9d5134074d84 47 {
JMF 0:9d5134074d84 48 _temperature = 0;
JMF 0:9d5134074d84 49 _humidity = 0;
JMF 0:9d5134074d84 50 }
JMF 0:9d5134074d84 51
JMF 0:9d5134074d84 52
JMF 0:9d5134074d84 53 int HTS221::begin(void)
JMF 0:9d5134074d84 54 {
JMF 0:9d5134074d84 55 uint8_t data;
JMF 0:9d5134074d84 56
JMF 0:9d5134074d84 57 data = readRegister(_address, WHO_AM_I);
JMF 0:9d5134074d84 58 if (data == WHO_AM_I_RETURN){
JMF 0:9d5134074d84 59 if (activate()){
JMF 0:9d5134074d84 60 storeCalibration();
JMF 0:9d5134074d84 61 return data;
JMF 0:9d5134074d84 62 }
JMF 0:9d5134074d84 63 }
JMF 0:9d5134074d84 64
JMF 0:9d5134074d84 65 return 0;
JMF 0:9d5134074d84 66 }
JMF 0:9d5134074d84 67
JMF 0:9d5134074d84 68 int
JMF 0:9d5134074d84 69 HTS221::storeCalibration(void)
JMF 0:9d5134074d84 70 {
JMF 0:9d5134074d84 71 uint8_t data;
JMF 0:9d5134074d84 72 uint16_t tmp;
JMF 0:9d5134074d84 73
JMF 0:9d5134074d84 74 for (int reg=CALIB_START; reg<=CALIB_END; reg++) {
JMF 0:9d5134074d84 75 if ((reg!=CALIB_START+8) && (reg!=CALIB_START+9) && (reg!=CALIB_START+4)) {
JMF 0:9d5134074d84 76
JMF 0:9d5134074d84 77 data = readRegister(HTS221_ADDRESS, reg);
JMF 0:9d5134074d84 78
JMF 0:9d5134074d84 79 switch (reg) {
JMF 0:9d5134074d84 80 case CALIB_START:
JMF 0:9d5134074d84 81 _h0_rH = data;
JMF 0:9d5134074d84 82 break;
JMF 0:9d5134074d84 83 case CALIB_START+1:
JMF 0:9d5134074d84 84 _h1_rH = data;
JMF 0:9d5134074d84 85 break;
JMF 0:9d5134074d84 86 case CALIB_START+2:
JMF 0:9d5134074d84 87 _T0_degC = data;
JMF 0:9d5134074d84 88 break;
JMF 0:9d5134074d84 89 case CALIB_START+3:
JMF 0:9d5134074d84 90 _T1_degC = data;
JMF 0:9d5134074d84 91 break;
JMF 0:9d5134074d84 92
JMF 0:9d5134074d84 93 case CALIB_START+5:
JMF 0:9d5134074d84 94 tmp = _T0_degC;
JMF 0:9d5134074d84 95 _T0_degC = (data&0x3)<<8;
JMF 0:9d5134074d84 96 _T0_degC |= tmp;
JMF 0:9d5134074d84 97
JMF 0:9d5134074d84 98 tmp = _T1_degC;
JMF 0:9d5134074d84 99 _T1_degC = ((data&0xC)>>2)<<8;
JMF 0:9d5134074d84 100 _T1_degC |= tmp;
JMF 0:9d5134074d84 101 break;
JMF 0:9d5134074d84 102 case CALIB_START+6:
JMF 0:9d5134074d84 103 _H0_T0 = data;
JMF 0:9d5134074d84 104 break;
JMF 0:9d5134074d84 105 case CALIB_START+7:
JMF 0:9d5134074d84 106 _H0_T0 |= data<<8;
JMF 0:9d5134074d84 107 break;
JMF 0:9d5134074d84 108 case CALIB_START+0xA:
JMF 0:9d5134074d84 109 _H1_T0 = data;
JMF 0:9d5134074d84 110 break;
JMF 0:9d5134074d84 111 case CALIB_START+0xB:
JMF 0:9d5134074d84 112 _H1_T0 |= data <<8;
JMF 0:9d5134074d84 113 break;
JMF 0:9d5134074d84 114 case CALIB_START+0xC:
JMF 0:9d5134074d84 115 _T0_OUT = data;
JMF 0:9d5134074d84 116 break;
JMF 0:9d5134074d84 117 case CALIB_START+0xD:
JMF 0:9d5134074d84 118 _T0_OUT |= data << 8;
JMF 0:9d5134074d84 119 break;
JMF 0:9d5134074d84 120 case CALIB_START+0xE:
JMF 0:9d5134074d84 121 _T1_OUT = data;
JMF 0:9d5134074d84 122 break;
JMF 0:9d5134074d84 123 case CALIB_START+0xF:
JMF 0:9d5134074d84 124 _T1_OUT |= data << 8;
JMF 0:9d5134074d84 125 break;
JMF 0:9d5134074d84 126
JMF 0:9d5134074d84 127
JMF 0:9d5134074d84 128 case CALIB_START+8:
JMF 0:9d5134074d84 129 case CALIB_START+9:
JMF 0:9d5134074d84 130 case CALIB_START+4:
JMF 0:9d5134074d84 131 //DO NOTHING
JMF 0:9d5134074d84 132 break;
JMF 0:9d5134074d84 133
JMF 0:9d5134074d84 134 // to cover any possible error
JMF 0:9d5134074d84 135 default:
JMF 0:9d5134074d84 136 return false;
JMF 0:9d5134074d84 137 } /* switch */
JMF 0:9d5134074d84 138 } /* if */
JMF 0:9d5134074d84 139 } /* for */
JMF 0:9d5134074d84 140 return true;
JMF 0:9d5134074d84 141 }
JMF 0:9d5134074d84 142
JMF 0:9d5134074d84 143
JMF 0:9d5134074d84 144 int
JMF 0:9d5134074d84 145 HTS221::activate(void)
JMF 0:9d5134074d84 146 {
JMF 0:9d5134074d84 147 uint8_t data;
JMF 0:9d5134074d84 148
JMF 0:9d5134074d84 149 data = readRegister(_address, CTRL_REG1);
JMF 0:9d5134074d84 150 data |= POWER_UP;
JMF 0:9d5134074d84 151 data |= ODR0_SET;
JMF 0:9d5134074d84 152 writeRegister(_address, CTRL_REG1, data);
JMF 0:9d5134074d84 153
JMF 0:9d5134074d84 154 return true;
JMF 0:9d5134074d84 155 }
JMF 0:9d5134074d84 156
JMF 0:9d5134074d84 157
JMF 0:9d5134074d84 158 int HTS221::deactivate(void)
JMF 0:9d5134074d84 159 {
JMF 0:9d5134074d84 160 uint8_t data;
JMF 0:9d5134074d84 161
JMF 0:9d5134074d84 162 data = readRegister(_address, CTRL_REG1);
JMF 0:9d5134074d84 163 data &= ~POWER_UP;
JMF 0:9d5134074d84 164 writeRegister(_address, CTRL_REG1, data);
JMF 0:9d5134074d84 165 return true;
JMF 0:9d5134074d84 166 }
JMF 0:9d5134074d84 167
JMF 0:9d5134074d84 168
JMF 0:9d5134074d84 169 int
JMF 0:9d5134074d84 170 HTS221::bduActivate(void)
JMF 0:9d5134074d84 171 {
JMF 0:9d5134074d84 172 uint8_t data;
JMF 0:9d5134074d84 173
JMF 0:9d5134074d84 174 data = readRegister(_address, CTRL_REG1);
JMF 0:9d5134074d84 175 data |= BDU_SET;
JMF 0:9d5134074d84 176 writeRegister(_address, CTRL_REG1, data);
JMF 0:9d5134074d84 177
JMF 0:9d5134074d84 178 return true;
JMF 0:9d5134074d84 179 }
JMF 0:9d5134074d84 180
JMF 0:9d5134074d84 181
JMF 0:9d5134074d84 182 int
JMF 0:9d5134074d84 183 HTS221::bduDeactivate(void)
JMF 0:9d5134074d84 184 {
JMF 0:9d5134074d84 185 uint8_t data;
JMF 0:9d5134074d84 186
JMF 0:9d5134074d84 187 data = readRegister(_address, CTRL_REG1);
JMF 0:9d5134074d84 188 data &= ~BDU_SET;
JMF 0:9d5134074d84 189 writeRegister(_address, CTRL_REG1, data);
JMF 0:9d5134074d84 190 return true;
JMF 0:9d5134074d84 191 }
JMF 0:9d5134074d84 192
JMF 0:9d5134074d84 193
JMF 0:9d5134074d84 194 int
JMF 0:9d5134074d84 195 HTS221::readHumidity(void)
JMF 0:9d5134074d84 196 {
JMF 0:9d5134074d84 197 uint8_t data = 0;
JMF 0:9d5134074d84 198 uint16_t h_out = 0;
JMF 0:9d5134074d84 199 double h_temp = 0.0;
JMF 0:9d5134074d84 200 double hum = 0.0;
JMF 0:9d5134074d84 201
JMF 0:9d5134074d84 202 data = readRegister(_address, STATUS_REG);
JMF 0:9d5134074d84 203
JMF 0:9d5134074d84 204 if (data & HUMIDITY_READY) {
JMF 0:9d5134074d84 205 data = readRegister(_address, HUMIDITY_H_REG);
JMF 0:9d5134074d84 206 h_out = data << 8; // MSB
JMF 0:9d5134074d84 207 data = readRegister(_address, HUMIDITY_L_REG);
JMF 0:9d5134074d84 208 h_out |= data; // LSB
JMF 0:9d5134074d84 209
JMF 0:9d5134074d84 210 // Decode Humidity
JMF 0:9d5134074d84 211 hum = ((int16_t)(_h1_rH) - (int16_t)(_h0_rH))/2.0; // remove x2 multiple
JMF 0:9d5134074d84 212
JMF 0:9d5134074d84 213 // Calculate humidity in decimal of grade centigrades i.e. 15.0 = 150.
JMF 0:9d5134074d84 214 h_temp = (((int16_t)h_out - (int16_t)_H0_T0) * hum) / ((int16_t)_H1_T0 - (int16_t)_H0_T0);
JMF 0:9d5134074d84 215 hum = ((int16_t)_h0_rH) / 2.0; // remove x2 multiple
JMF 0:9d5134074d84 216 _humidity = (int16_t)((hum + h_temp)); // provide signed % measurement unit
JMF 0:9d5134074d84 217 }
JMF 0:9d5134074d84 218 return _humidity;
JMF 0:9d5134074d84 219 }
JMF 0:9d5134074d84 220
JMF 0:9d5134074d84 221
JMF 0:9d5134074d84 222
JMF 0:9d5134074d84 223 double
JMF 0:9d5134074d84 224 HTS221::readTemperature(void)
JMF 0:9d5134074d84 225 {
JMF 0:9d5134074d84 226 uint8_t data = 0;
JMF 0:9d5134074d84 227 uint16_t t_out = 0;
JMF 0:9d5134074d84 228 double t_temp = 0.0;
JMF 0:9d5134074d84 229 double deg = 0.0;
JMF 0:9d5134074d84 230
JMF 0:9d5134074d84 231 data = readRegister(_address, STATUS_REG);
JMF 0:9d5134074d84 232
JMF 0:9d5134074d84 233 if (data & TEMPERATURE_READY) {
JMF 0:9d5134074d84 234
JMF 0:9d5134074d84 235 data= readRegister(_address, TEMP_H_REG);
JMF 0:9d5134074d84 236 t_out = data << 8; // MSB
JMF 0:9d5134074d84 237 data = readRegister(_address, TEMP_L_REG);
JMF 0:9d5134074d84 238 t_out |= data; // LSB
JMF 0:9d5134074d84 239
JMF 0:9d5134074d84 240 // Decode Temperature
JMF 0:9d5134074d84 241 deg = ((int16_t)(_T1_degC) - (int16_t)(_T0_degC))/8.0; // remove x8 multiple
JMF 0:9d5134074d84 242
JMF 0:9d5134074d84 243 // Calculate Temperature in decimal of grade centigrades i.e. 15.0 = 150.
JMF 0:9d5134074d84 244 t_temp = (((int16_t)t_out - (int16_t)_T0_OUT) * deg) / ((int16_t)_T1_OUT - (int16_t)_T0_OUT);
JMF 0:9d5134074d84 245 deg = ((int16_t)_T0_degC) / 8.0; // remove x8 multiple
JMF 0:9d5134074d84 246 _temperature = deg + t_temp; // provide signed celsius measurement unit
JMF 0:9d5134074d84 247 }
JMF 0:9d5134074d84 248
JMF 0:9d5134074d84 249 return _temperature;
JMF 0:9d5134074d84 250 }