This is the initial version of the IIoT quickstart program implemented on the AT&T IoT kit.

Dependencies:   WNCInterface mbed-rtos mbed

IBM Watson IoT Platform Quickstart program using the AT&T/Avnet IoT Starter Kit

Using the AT&T Cellular IoT Starter Kit from Avnet the this program publishes temperature and/or humidity to the IBM Watson IoT Platform Quickstart site. The user can switch between temperature or humidity. The user can select which data series to display by selecting the event at the bottom of the display.

NOTE: This doc is specific to using the AT&T Cellular IoT Starter Kit which contains a FRDM-K64F from NXP. Ensure that the mbed online compiler has the platform set to FRDM-K64F.

1. Launch mbed online compiler in your browser

2. In a seperate browser Tab, goto the Avnet BluemixQS site and select the Import into Compiler button in the upper right portion of the window.

3. With the example program imported into you work-space, you have all the components needed. Simply execute the Compile button.

Expected execution outcome

Once the program is compiled and downloaded to the IoT Kit, perform the following steps:

1. Using a terminal program such as Hyperterm or Putty, connect to the Kit (select comm parameters of 115200-N81)

2. Press the `reset` button, then you should see the program start running! When it runs, the output will look similar to:

Sample Ouput

HTS221 Detected (0xBC)
  Temp  is: 89.66 F 
  Humid is: 08 %
      _____
     *     *
    *____   *____             Bluemix Quick Start example
   * *===*   *==*             using the AT&T IoT Starter Kit
  *___*===*___**  AVNET
       *======*
        *====*

This demonstration program operates the same as the original 
MicroZed IIoT Starter Kit except it only reads from the HTS221 
temp sensor (no 31855 currently present and no generated data).

Local network info...
IP address is 10.61.23.226
MAC address is 11:02:72:14:95:91
Gateway address is 10.61.23.225
Your <uniqueID> is: IoT-11027214-2016

To run the demo, go to 'https://quickstart.internetofthings.ibmcloud.com/#/'
and enter 'IoT-11027214-2016' as your device ID.  The temperature data will then be displayed
as it is received. You can switch between temperature and humidity by depressing SW2.
---------------------------------------------------------------


(0) Attempting TCP connect to quickstart.messaging.internetofthings.ibmcloud.com:1883:  Success!
(0) Attempting MQTT connect to quickstart.messaging.internetofthings.ibmcloud.com:1883: Success!
Publishing MQTT message '{"d" : {"temp" : " 90.2" }}' (27)

3. Once the program is running, go to https://quickstart.internetofthings.ibmcloud.com/# and enter your device ID (this is IoT-11027214-2016 in the above sample output) and select the GO button. As data is received it will automatically graphed and displayed below the graph. If you want to switch and display humidity rather than temperature (temperature is the default), depress SW2 on the FRDM-K64F board and select humid in the data under the graph.

License

This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Committer:
JMF
Date:
Wed Sep 28 00:56:47 2016 +0000
Revision:
0:6a929f0d0e58
Initial submission

Who changed what in which revision?

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