Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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.
Revision 0:6a929f0d0e58, committed 2016-09-28
- Comitter:
- JMF
- Date:
- Wed Sep 28 00:56:47 2016 +0000
- Child:
- 1:d8d4c57daaad
- Commit message:
- Initial submission
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HTS221.cpp Wed Sep 28 00:56:47 2016 +0000
@@ -0,0 +1,240 @@
+/* ===================================================================
+Copyright © 2016, AVNET Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You 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.
+
+======================================================================== */
+
+#include "HTS221.h"
+
+
+// ------------------------------------------------------------------------------
+//jmf -- define I2C pins and functions to read & write to I2C device
+
+#include <string>
+#include "mbed.h"
+#include "hardware.h"
+
+// Read a single unsigned char from addressToRead and return it as a unsigned char
+unsigned char HTS221::readRegister(unsigned char slaveAddress, unsigned char ToRead)
+{
+ char data = ToRead;
+
+ //i2c.write(slaveAddress, &data, 1, 0);
+ i2c.write(slaveAddress, &data, 1, 1); //by Stefan
+ i2c.read(slaveAddress, &data, 1, 0);
+ return data;
+}
+
+// Writes a single unsigned char (dataToWrite) into regToWrite
+int HTS221::writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite)
+{
+ const char data[] = {regToWrite, dataToWrite};
+
+ return i2c.write(slaveAddress,data,2,0);
+}
+
+
+//jmf end
+// ------------------------------------------------------------------------------
+
+HTS221::HTS221(void) : _address(HTS221_ADDRESS) {
+ _temperature = 0;
+ _humidity = 0;
+}
+
+
+int HTS221::init(void) {
+ uint8_t data;
+
+ data = readRegister(_address, WHO_AM_I);
+ if (data == WHO_AM_I_RETURN){
+ if (activate()){
+ storeCalibration();
+ return data;
+ }
+ }
+
+ return 0;
+}
+
+int HTS221::storeCalibration(void) {
+ uint8_t data;
+ uint16_t tmp;
+
+ for (int reg=CALIB_START; reg<=CALIB_END; reg++) {
+ if ((reg!=CALIB_START+8) && (reg!=CALIB_START+9) && (reg!=CALIB_START+4)) {
+
+ data = readRegister(HTS221_ADDRESS, reg);
+
+ switch (reg) {
+ case CALIB_START:
+ _h0_rH = data;
+ break;
+ case CALIB_START+1:
+ _h1_rH = data;
+ break;
+ case CALIB_START+2:
+ _T0_degC = data;
+ break;
+ case CALIB_START+3:
+ _T1_degC = data;
+ break;
+
+ case CALIB_START+5:
+ tmp = _T0_degC;
+ _T0_degC = (data&0x3)<<8;
+ _T0_degC |= tmp;
+
+ tmp = _T1_degC;
+ _T1_degC = ((data&0xC)>>2)<<8;
+ _T1_degC |= tmp;
+ break;
+ case CALIB_START+6:
+ _H0_T0 = data;
+ break;
+ case CALIB_START+7:
+ _H0_T0 |= data<<8;
+ break;
+ case CALIB_START+0xA:
+ _H1_T0 = data;
+ break;
+ case CALIB_START+0xB:
+ _H1_T0 |= data <<8;
+ break;
+ case CALIB_START+0xC:
+ _T0_OUT = data;
+ break;
+ case CALIB_START+0xD:
+ _T0_OUT |= data << 8;
+ break;
+ case CALIB_START+0xE:
+ _T1_OUT = data;
+ break;
+ case CALIB_START+0xF:
+ _T1_OUT |= data << 8;
+ break;
+
+
+ case CALIB_START+8:
+ case CALIB_START+9:
+ case CALIB_START+4:
+ //DO NOTHING
+ break;
+
+ // to cover any possible error
+ default:
+ return false;
+ } /* switch */
+ } /* if */
+ } /* for */
+ return true;
+}
+
+
+int HTS221::activate(void) {
+ uint8_t data;
+
+ data = readRegister(_address, CTRL_REG1);
+ data |= POWER_UP;
+ data |= ODR0_SET;
+ writeRegister(_address, CTRL_REG1, data);
+
+ return true;
+}
+
+
+int HTS221::deactivate(void) {
+ uint8_t data;
+
+ data = readRegister(_address, CTRL_REG1);
+ data &= ~POWER_UP;
+ writeRegister(_address, CTRL_REG1, data);
+ return true;
+}
+
+
+int HTS221::bduActivate(void) {
+ uint8_t data;
+
+ data = readRegister(_address, CTRL_REG1);
+ data |= BDU_SET;
+ writeRegister(_address, CTRL_REG1, data);
+
+ return true;
+}
+
+
+int HTS221::bduDeactivate(void) {
+ uint8_t data;
+
+ data = readRegister(_address, CTRL_REG1);
+ data &= ~BDU_SET;
+ writeRegister(_address, CTRL_REG1, data);
+ return true;
+}
+
+
+int HTS221::readHumidity(void) {
+ uint8_t data = 0;
+ uint16_t h_out = 0;
+ double h_temp = 0.0;
+ double hum = 0.0;
+
+ data = readRegister(_address, STATUS_REG);
+
+ if (data & HUMIDITY_READY) {
+ data = readRegister(_address, HUMIDITY_H_REG);
+ h_out = data << 8; // MSB
+ data = readRegister(_address, HUMIDITY_L_REG);
+ h_out |= data; // LSB
+
+ // Decode Humidity
+ hum = ((int16_t)(_h1_rH) - (int16_t)(_h0_rH))/2.0; // remove x2 multiple
+
+ // Calculate humidity in decimal of grade centigrades i.e. 15.0 = 150.
+ h_temp = (((int16_t)h_out - (int16_t)_H0_T0) * hum) / ((int16_t)_H1_T0 - (int16_t)_H0_T0);
+ hum = ((int16_t)_h0_rH) / 2.0; // remove x2 multiple
+ _humidity = (int16_t)((hum + h_temp)); // provide signed % measurement unit
+ }
+ return _humidity;
+}
+
+
+
+double HTS221::readTemperature(void) {
+ uint8_t data = 0;
+ uint16_t t_out = 0;
+ double t_temp = 0.0;
+ double deg = 0.0;
+
+ data = readRegister(_address, STATUS_REG);
+
+ if (data & TEMPERATURE_READY) {
+
+ data= readRegister(_address, TEMP_H_REG);
+ t_out = data << 8; // MSB
+ data = readRegister(_address, TEMP_L_REG);
+ t_out |= data; // LSB
+
+ // Decode Temperature
+ deg = ((int16_t)(_T1_degC) - (int16_t)(_T0_degC))/8.0; // remove x8 multiple
+
+ // Calculate Temperature in decimal of grade centigrades i.e. 15.0 = 150.
+ t_temp = (((int16_t)t_out - (int16_t)_T0_OUT) * deg) / ((int16_t)_T1_OUT - (int16_t)_T0_OUT);
+ deg = ((int16_t)_T0_degC) / 8.0; // remove x8 multiple
+ _temperature = deg + t_temp; // provide signed celsius measurement unit
+ }
+
+ return _temperature;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HTS221.h Wed Sep 28 00:56:47 2016 +0000
@@ -0,0 +1,108 @@
+/* ===================================================================
+Copyright © 2016, AVNET Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You 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.
+
+======================================================================== */
+
+#ifndef HTS221_H_
+#define HTS221_H_
+
+class HTS221 {
+public:
+ HTS221(void);
+ int init(void);
+ int activate(void);
+ int deactivate(void);
+
+ int bduActivate(void);
+ int bduDeactivate(void);
+
+ int readHumidity(void);
+ double readTemperature(void);
+private:
+ int storeCalibration(void);
+ unsigned char _h0_rH, _h1_rH;
+ unsigned int _T0_degC, _T1_degC;
+ unsigned int _H0_T0, _H1_T0;
+ unsigned int _T0_OUT, _T1_OUT;
+ double _temperature;
+ int _humidity;
+ unsigned char _address;
+
+ unsigned char readRegister(unsigned char slaveAddress, unsigned char regToRead);
+ int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite);
+};
+
+#define HTS221_ADDRESS 0xBF
+
+//Define a few of the registers that we will be accessing on the HTS221
+#define WHO_AM_I 0x0F
+#define WHO_AM_I_RETURN 0xBC //This read-only register contains the device identifier, set to BCh
+
+#define AVERAGE_REG 0x10 // To configure humidity/temperature average.
+#define AVERAGE_DEFAULT 0x1B
+
+/*
+ * [7] PD: power down control
+ * (0: power-down mode; 1: active mode)
+ *
+ * [6:3] Reserved
+ *
+ * [2] BDU: block data update
+ * (0: continuous update; 1: output registers not updated until MSB and LSB reading)
+The BDU bit is used to inhibit the output register update between the reading of the upper
+and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are
+updated continuously. If it is not certain whether the read will be faster than output data rate,
+it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper)
+register part, the content of that output register is not updated until the upper (lower) part is
+read also.
+ *
+ * [1:0] ODR1, ODR0: output data rate selection (see table 17)
+ */
+#define CTRL_REG1 0x20
+#define POWER_UP 0x80
+#define BDU_SET 0x4
+#define ODR0_SET 0x1 // setting sensor reading period 1Hz
+
+#define CTRL_REG2 0x21
+#define CTRL_REG3 0x22
+#define REG_DEFAULT 0x00
+
+#define STATUS_REG 0x27
+#define TEMPERATURE_READY 0x1
+#define HUMIDITY_READY 0x2
+
+#define HUMIDITY_L_REG 0x28
+#define HUMIDITY_H_REG 0x29
+#define TEMP_L_REG 0x2A
+#define TEMP_H_REG 0x2B
+/*
+ * calibration registry should be read for temperature and humidity calculation.
+ * Before the first calculation of temperature and humidity,
+ * the master reads out the calibration coefficients.
+ * will do at init phase
+ */
+#define CALIB_START 0x30
+#define CALIB_END 0x3F
+/*
+#define CALIB_T0_DEGC_X8 0x32
+#define CALIB_T1_DEGC_X8 0x33
+#define CALIB_T1_T0_MSB 0x35
+#define CALIB_T0_OUT_L 0x3C
+#define CALIB_T0_OUT_H 0x3D
+#define CALIB_T1_OUT_L 0x3E
+#define CALIB_T1_OUT_H 0x3F
+ */
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTT-JMF.lib Wed Sep 28 00:56:47 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/JMF/code/MQTT-JMF/#21d6fba046df
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WNCInterface.lib Wed Sep 28 00:56:47 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Avnet/code/WNCInterface/#7cda15f762fe
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hardware.h Wed Sep 28 00:56:47 2016 +0000 @@ -0,0 +1,57 @@ +/* =================================================================== +Copyright © 2016, AVNET Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You 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. + +======================================================================== */ + +#ifndef Hardware_H_ +#define Hardware_H_ +#include "MODSERIAL.h" + +extern I2C i2c; //SDA, SCL -- define the I2C pins being used +extern MODSERIAL pc; // tx, rx with default tx, rx buffer sizes + +// comment out the following line if color is not supported on the terminal +#define USE_COLOR +#ifdef USE_COLOR + #define BLK "\033[30m" + #define RED "\033[31m" + #define GRN "\033[32m" + #define YEL "\033[33m" + #define BLU "\033[34m" + #define MAG "\033[35m" + #define CYN "\033[36m" + #define WHT "\033[37m" + #define DEF "\033[39m" +#else + #define BLK + #define RED + #define GRN + #define YEL + #define BLU + #define MAG + #define CYN + #define WHT + #define DEF +#endif + +#define CTOF(x) ((x)*1.8+32) + +#ifdef _ULINK_PRINT +#include "itm_output.h" +#else +#define PRINTF printf +#define PUTS puts +#endif +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/k64f.h Wed Sep 28 00:56:47 2016 +0000
@@ -0,0 +1,15 @@
+#ifndef K64F_H_
+#define K64F_H_
+
+typedef enum color {off, red, green, blue} color_t;
+
+//Serial pc(USBTX, USBRX);
+DigitalOut redLED(LED_RED);
+DigitalOut greenLED(LED_GREEN);
+DigitalOut blueLED(LED_BLUE);
+InterruptIn switch2(SW2);
+InterruptIn switch3(SW3);
+
+#endif // K64F.H
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Sep 28 00:56:47 2016 +0000
@@ -0,0 +1,300 @@
+//#define MQTT_DEBUG
+
+#include "mbed.h"
+#include "MQTTClient.h"
+#include "MQTTFormat.h"
+
+//#include "MQTTEthernet.h"
+#include "MQTTWNCInterface.h"
+#include "rtos.h"
+#include "k64f.h"
+#include "HTS221.h"
+
+I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used
+MODSERIAL pc(USBTX,USBRX,256,256);
+
+#include "hardware.h"
+
+
+// connect options for MQTT broker
+#define CLIENT "quickstart"
+#define URL CLIENT ".messaging.internetofthings.ibmcloud.com"
+#define CONFIGTYPE "d:" CLIENT ":MicroZed:%s"
+
+#define PORT 1883 // MQTT broker port number
+#define CLIENTID "96430312d8f7" // use MAC address without colons
+#define USERNAME "" // not required for demo app
+#define PASSWORD "" // not required for demo app
+#define PUBLISH_TOPIC "iot-2/evt/status/fmt/json" // MQTT topic
+#define SUBSCRIBTOPIC "iot-2/cmd/+/fmt/+"
+
+#define HTS221_STR " Temp is: %0.2f F \n\r Humid is: %02d %%\n\r"
+
+Queue<uint32_t, 6> messageQ;
+
+struct rcvd_errs{
+ int err;
+ char *er;
+ };
+
+rcvd_errs response[] = {
+ 200, "200 OK - Request has succeeded.",
+ 201, "201 Created - Request has been fulfilled and a new resource created.",
+ 202, "202 Accepted - The request has been accepted for processing, but the processing will be completed asynchronously",
+ 204, "204 No Content - The server has fulfilled the request but does not need to return an entity-body.",
+ 400, "400 Bad Request - Bad request (e.g. sending an array when the API is expecting a hash.)",
+ 401, "401 Unauthorized - No valid API key provided.",
+ 403, "403 Forbidden - You tried to access a disabled device, or your API key is not allowed to access that resource, etc.",
+ 404, "404 Not Found - The requested item could not be found.",
+ 405, "405 Method Not Allowed - The HTTP method specified is not allowed.",
+ 415, "415 Unsupported Media Type - The requested media type is currently not supported.",
+ 422, "422 Unprocessable Entity - Can result from sending invalid fields.",
+ 429, "429 Too Many Requests - The user has sent too many requests in a given period of time.",
+ 500, "500 Server errors - Something went wrong in the M2X server",
+ 502, "502 Server errors - Something went wrong in the M2X server",
+ 503, "503 Server errors - Something went wrong in the M2X server",
+ 504, "504 Server errors - Something went wrong in the M2X server",
+ };
+#define RCMAX sizeof(response)/sizeof(rcvd_errs)
+
+char * response_str(int rc) {
+ static char *unkown = "Unknown error code...";
+ int i=0;
+ while( response[i].err != rc && i < RCMAX)
+ i++;
+ return (i<RCMAX? response[i].er : unkown);
+}
+
+// LED color control function
+void controlLED(color_t led_color) {
+ switch(led_color) {
+ case red :
+ greenLED = blueLED = 1;
+ redLED = 0.7;
+ break;
+ case green :
+ redLED = blueLED = 1;
+ greenLED = 0.7;
+ break;
+ case blue :
+ redLED = greenLED = 1;
+ blueLED = 0.7;
+ break;
+ case off :
+ redLED = greenLED = blueLED = 1;
+ break;
+ }
+}
+
+// Switch 2 interrupt handler
+void sw2_ISR(void) {
+ messageQ.put((uint32_t*)22);
+}
+
+// Switch3 interrupt handler
+void sw3_ISR(void) {
+ messageQ.put((uint32_t*)33);
+}
+
+// MQTT message arrived callback function
+void messageArrived(MQTT::MessageData& md) {
+ MQTT::Message &message = md.message;
+ printf("Receiving MQTT message: %.*s\r\n", message.payloadlen, (char*)message.payload);
+
+ if (message.payloadlen == 3) {
+ if (strncmp((char*)message.payload, "red", 3) == 0)
+ controlLED(red);
+
+ else if(strncmp((char*)message.payload, "grn", 3) == 0)
+ controlLED(green);
+
+ else if(strncmp((char*)message.payload, "blu", 3) == 0)
+ controlLED(blue);
+
+ else if(strncmp((char*)message.payload, "off", 3) == 0)
+ controlLED(off);
+ }
+}
+
+int main() {
+ int rc, qStart=0, txSel=0, good = 0;
+ Timer tmr;
+ char* topic = PUBLISH_TOPIC;
+ char clientID[100], buf[100], uniqueID[50];
+
+ HTS221 hts221;
+
+ pc.baud(115200);
+ rc = hts221.init();
+ if ( rc ) {
+ pc.printf(BLU "HTS221 Detected (0x%02X)\n\r",rc);
+ pc.printf(HTS221_STR, CTOF(hts221.readTemperature()), hts221.readHumidity()/10);
+ }
+ else {
+ pc.printf(RED "HTS221 NOT DETECTED!\n\r");
+ }
+
+
+ // turn off LED
+ controlLED(blue);
+
+ // set SW2 and SW3 to generate interrupt on falling edge
+ switch2.fall(&sw2_ISR);
+ switch3.fall(&sw3_ISR);
+
+ // initialize ethernet interface
+ MQTTwnc ipstack = MQTTwnc();
+
+ // get and display client network info
+ WNCInterface& eth = ipstack.getEth();
+
+ // construct the MQTT client
+ MQTT::Client<MQTTwnc, Countdown> client = MQTT::Client<MQTTwnc, Countdown>(ipstack);
+
+ char* hostname = URL;
+ int port = PORT;
+ char *tptr = eth.getMACAddress();
+ strncpy(buf,tptr,strlen(tptr));
+ for( int x=3, i=2; i<strlen(tptr)-2; x+=3,i++ ){
+ buf[i] = buf[x];
+ buf[x]=buf[x+1];
+ }
+ sprintf(uniqueID, "Mz-%s-7010", buf);
+ sprintf(clientID, CONFIGTYPE, uniqueID);
+ printf("ClientID='%s'\r\n",clientID);
+
+ printf(" _____\r\n");
+ printf(" * *\r\n");
+ printf(" *____ *____ Bluemix IIoT Demo using\r\n");
+ printf(" * *===* *==* the AT&T IoT Starter Kit\r\n");
+ printf(" *___*===*___** AVNET\r\n");
+ printf(" *======*\r\n");
+ printf(" *====*\r\n");
+ printf("\r\n");
+ printf("This demonstration program operates the same as the original \r\n");
+ printf("MicroZed IIoT Starter Kit except it only reads from the HTS221 \r\n");
+ printf("temp sensor (no 31855 currently present and no generated data).\r\n");
+ printf("\r\n");
+ printf("Local network info...\r\n");
+ printf("IP address is %s\r\n", eth.getIPAddress());
+ printf("MAC address is %s\r\n", eth.getMACAddress());
+ printf("Gateway address is %s\r\n", eth.getGateway());
+ printf("Your <uniqueID> is: %s\r\n", uniqueID);
+ printf("---------------------------------------------------------------\r\n");
+
+ MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
+
+ int tries;
+
+ while( !good ) {
+ tries=0;
+ // connect to TCP socket and check return code
+ tmr.start();
+ rc = 1;
+ while( rc && tries < 3) {
+ printf("\r\n\r\n(%d) Attempting TCP connect to %s:%d: ", tries++, hostname, port);
+ rc = ipstack.connect(hostname, port);
+ if( rc ) {
+ printf("Failed (%d)!\r\n",rc);
+ while( tmr.read_ms() < 5000 ) ;
+ tmr.reset();
+ }
+ else {
+ printf("Success!\r\n");
+ rc = 0;
+ }
+ }
+ if( tries < 3 )
+ tries = 0;
+ else
+ continue;
+
+ data.willFlag = 0;
+ data.MQTTVersion = 3;
+
+ data.clientID.cstring = clientID;
+ // data.username.cstring = USERNAME;
+ // data.password.cstring = PASSWORD;
+ data.keepAliveInterval = 10;
+ data.cleansession = 1;
+
+ rc = 1;
+ tmr.reset();
+ while( !client.isConnected() && rc && tries < 3) {
+ printf("(%d) Attempting MQTT connect to %s:%d: ", tries++, hostname, port);
+ rc = client.connect(data);
+ if( rc ) {
+ printf("Failed (%d)!\r\n",rc);
+ while( tmr.read_ms() < 5000 );
+ tmr.reset();
+ }
+ else
+ printf("Success!\r\n");
+ }
+
+ if( tries < 3 )
+ tries = 0;
+ else
+ continue;
+
+#if 0
+//Only need to subscribe if we are not running quickstart
+ // subscribe to MQTT topic
+ tmr.reset();
+ rc = 1;
+ while( rc && client.isConnected() && tries < 3) {
+ printf("(%d) Attempting to subscribing to MQTT topic %s: ", tries, SUBSCRIBTOPIC);
+ rc = client.subscribe(SUBSCRIBTOPIC, MQTT::QOS0, messageArrived);
+ if( rc ) {
+ printf("Failed (%d)!\r\n", rc);
+ while( tmr.read_ms() < 5000 );
+ tries++;
+ tmr.reset();
+ }
+ else {
+ good=1;
+ printf("Subscribe successful!\r\n");
+ }
+ }
+#else
+ good = 1;
+#endif
+ while (!good);
+ }
+
+ MQTT::Message message;
+ message.qos = MQTT::QOS0;
+ message.retained = false;
+ message.dup = false;
+ message.payload = (void*)buf;
+
+ while(true) {
+ osEvent switchEvent = messageQ.get(100);
+
+ if( switchEvent.value.v == 22 ) //switch between sending humidity & temp
+ txSel = !txSel;
+
+ if( switchEvent.value.v == 33) //user wants to run in Quickstart of Demo mode
+ qStart = !qStart;
+
+ memset(buf,0x00,sizeof(buf));
+ if( txSel ) {
+ rc = hts221.readHumidity();
+ sprintf(buf, "{\"d\" : {\"humd\" : \"%2d.%d\" }}", rc/10, rc-((rc/10)*10));
+ printf("Publishing MQTT message '%s' ", (char*)message.payload);
+ }
+ else {
+ sprintf(buf, "{\"d\" : {\"temp\" : \"%5.1f\" }}", CTOF(hts221.readTemperature()));
+ printf("Publishing MQTT message '%s' ", (char*)message.payload);
+ }
+ message.payloadlen = strlen(buf);
+ printf("(%d)\r\n",message.payloadlen);
+ rc = client.publish(topic, message);
+ if( rc ) {
+ printf("Publish request failed! (%d)\r\n",rc);
+ FATAL_WNC_ERROR(resume);
+ }
+
+ client.yield(6000);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Sep 28 00:56:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#3da5f554d8bf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 28 00:56:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85 \ No newline at end of file