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
Child:
1:d8d4c57daaad
Initial submission

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:6a929f0d0e58 1 //#define MQTT_DEBUG
JMF 0:6a929f0d0e58 2
JMF 0:6a929f0d0e58 3 #include "mbed.h"
JMF 0:6a929f0d0e58 4 #include "MQTTClient.h"
JMF 0:6a929f0d0e58 5 #include "MQTTFormat.h"
JMF 0:6a929f0d0e58 6
JMF 0:6a929f0d0e58 7 //#include "MQTTEthernet.h"
JMF 0:6a929f0d0e58 8 #include "MQTTWNCInterface.h"
JMF 0:6a929f0d0e58 9 #include "rtos.h"
JMF 0:6a929f0d0e58 10 #include "k64f.h"
JMF 0:6a929f0d0e58 11 #include "HTS221.h"
JMF 0:6a929f0d0e58 12
JMF 0:6a929f0d0e58 13 I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used
JMF 0:6a929f0d0e58 14 MODSERIAL pc(USBTX,USBRX,256,256);
JMF 0:6a929f0d0e58 15
JMF 0:6a929f0d0e58 16 #include "hardware.h"
JMF 0:6a929f0d0e58 17
JMF 0:6a929f0d0e58 18
JMF 0:6a929f0d0e58 19 // connect options for MQTT broker
JMF 0:6a929f0d0e58 20 #define CLIENT "quickstart"
JMF 0:6a929f0d0e58 21 #define URL CLIENT ".messaging.internetofthings.ibmcloud.com"
JMF 0:6a929f0d0e58 22 #define CONFIGTYPE "d:" CLIENT ":MicroZed:%s"
JMF 0:6a929f0d0e58 23
JMF 0:6a929f0d0e58 24 #define PORT 1883 // MQTT broker port number
JMF 0:6a929f0d0e58 25 #define CLIENTID "96430312d8f7" // use MAC address without colons
JMF 0:6a929f0d0e58 26 #define USERNAME "" // not required for demo app
JMF 0:6a929f0d0e58 27 #define PASSWORD "" // not required for demo app
JMF 0:6a929f0d0e58 28 #define PUBLISH_TOPIC "iot-2/evt/status/fmt/json" // MQTT topic
JMF 0:6a929f0d0e58 29 #define SUBSCRIBTOPIC "iot-2/cmd/+/fmt/+"
JMF 0:6a929f0d0e58 30
JMF 0:6a929f0d0e58 31 #define HTS221_STR " Temp is: %0.2f F \n\r Humid is: %02d %%\n\r"
JMF 0:6a929f0d0e58 32
JMF 0:6a929f0d0e58 33 Queue<uint32_t, 6> messageQ;
JMF 0:6a929f0d0e58 34
JMF 0:6a929f0d0e58 35 struct rcvd_errs{
JMF 0:6a929f0d0e58 36 int err;
JMF 0:6a929f0d0e58 37 char *er;
JMF 0:6a929f0d0e58 38 };
JMF 0:6a929f0d0e58 39
JMF 0:6a929f0d0e58 40 rcvd_errs response[] = {
JMF 0:6a929f0d0e58 41 200, "200 OK - Request has succeeded.",
JMF 0:6a929f0d0e58 42 201, "201 Created - Request has been fulfilled and a new resource created.",
JMF 0:6a929f0d0e58 43 202, "202 Accepted - The request has been accepted for processing, but the processing will be completed asynchronously",
JMF 0:6a929f0d0e58 44 204, "204 No Content - The server has fulfilled the request but does not need to return an entity-body.",
JMF 0:6a929f0d0e58 45 400, "400 Bad Request - Bad request (e.g. sending an array when the API is expecting a hash.)",
JMF 0:6a929f0d0e58 46 401, "401 Unauthorized - No valid API key provided.",
JMF 0:6a929f0d0e58 47 403, "403 Forbidden - You tried to access a disabled device, or your API key is not allowed to access that resource, etc.",
JMF 0:6a929f0d0e58 48 404, "404 Not Found - The requested item could not be found.",
JMF 0:6a929f0d0e58 49 405, "405 Method Not Allowed - The HTTP method specified is not allowed.",
JMF 0:6a929f0d0e58 50 415, "415 Unsupported Media Type - The requested media type is currently not supported.",
JMF 0:6a929f0d0e58 51 422, "422 Unprocessable Entity - Can result from sending invalid fields.",
JMF 0:6a929f0d0e58 52 429, "429 Too Many Requests - The user has sent too many requests in a given period of time.",
JMF 0:6a929f0d0e58 53 500, "500 Server errors - Something went wrong in the M2X server",
JMF 0:6a929f0d0e58 54 502, "502 Server errors - Something went wrong in the M2X server",
JMF 0:6a929f0d0e58 55 503, "503 Server errors - Something went wrong in the M2X server",
JMF 0:6a929f0d0e58 56 504, "504 Server errors - Something went wrong in the M2X server",
JMF 0:6a929f0d0e58 57 };
JMF 0:6a929f0d0e58 58 #define RCMAX sizeof(response)/sizeof(rcvd_errs)
JMF 0:6a929f0d0e58 59
JMF 0:6a929f0d0e58 60 char * response_str(int rc) {
JMF 0:6a929f0d0e58 61 static char *unkown = "Unknown error code...";
JMF 0:6a929f0d0e58 62 int i=0;
JMF 0:6a929f0d0e58 63 while( response[i].err != rc && i < RCMAX)
JMF 0:6a929f0d0e58 64 i++;
JMF 0:6a929f0d0e58 65 return (i<RCMAX? response[i].er : unkown);
JMF 0:6a929f0d0e58 66 }
JMF 0:6a929f0d0e58 67
JMF 0:6a929f0d0e58 68 // LED color control function
JMF 0:6a929f0d0e58 69 void controlLED(color_t led_color) {
JMF 0:6a929f0d0e58 70 switch(led_color) {
JMF 0:6a929f0d0e58 71 case red :
JMF 0:6a929f0d0e58 72 greenLED = blueLED = 1;
JMF 0:6a929f0d0e58 73 redLED = 0.7;
JMF 0:6a929f0d0e58 74 break;
JMF 0:6a929f0d0e58 75 case green :
JMF 0:6a929f0d0e58 76 redLED = blueLED = 1;
JMF 0:6a929f0d0e58 77 greenLED = 0.7;
JMF 0:6a929f0d0e58 78 break;
JMF 0:6a929f0d0e58 79 case blue :
JMF 0:6a929f0d0e58 80 redLED = greenLED = 1;
JMF 0:6a929f0d0e58 81 blueLED = 0.7;
JMF 0:6a929f0d0e58 82 break;
JMF 0:6a929f0d0e58 83 case off :
JMF 0:6a929f0d0e58 84 redLED = greenLED = blueLED = 1;
JMF 0:6a929f0d0e58 85 break;
JMF 0:6a929f0d0e58 86 }
JMF 0:6a929f0d0e58 87 }
JMF 0:6a929f0d0e58 88
JMF 0:6a929f0d0e58 89 // Switch 2 interrupt handler
JMF 0:6a929f0d0e58 90 void sw2_ISR(void) {
JMF 0:6a929f0d0e58 91 messageQ.put((uint32_t*)22);
JMF 0:6a929f0d0e58 92 }
JMF 0:6a929f0d0e58 93
JMF 0:6a929f0d0e58 94 // Switch3 interrupt handler
JMF 0:6a929f0d0e58 95 void sw3_ISR(void) {
JMF 0:6a929f0d0e58 96 messageQ.put((uint32_t*)33);
JMF 0:6a929f0d0e58 97 }
JMF 0:6a929f0d0e58 98
JMF 0:6a929f0d0e58 99 // MQTT message arrived callback function
JMF 0:6a929f0d0e58 100 void messageArrived(MQTT::MessageData& md) {
JMF 0:6a929f0d0e58 101 MQTT::Message &message = md.message;
JMF 0:6a929f0d0e58 102 printf("Receiving MQTT message: %.*s\r\n", message.payloadlen, (char*)message.payload);
JMF 0:6a929f0d0e58 103
JMF 0:6a929f0d0e58 104 if (message.payloadlen == 3) {
JMF 0:6a929f0d0e58 105 if (strncmp((char*)message.payload, "red", 3) == 0)
JMF 0:6a929f0d0e58 106 controlLED(red);
JMF 0:6a929f0d0e58 107
JMF 0:6a929f0d0e58 108 else if(strncmp((char*)message.payload, "grn", 3) == 0)
JMF 0:6a929f0d0e58 109 controlLED(green);
JMF 0:6a929f0d0e58 110
JMF 0:6a929f0d0e58 111 else if(strncmp((char*)message.payload, "blu", 3) == 0)
JMF 0:6a929f0d0e58 112 controlLED(blue);
JMF 0:6a929f0d0e58 113
JMF 0:6a929f0d0e58 114 else if(strncmp((char*)message.payload, "off", 3) == 0)
JMF 0:6a929f0d0e58 115 controlLED(off);
JMF 0:6a929f0d0e58 116 }
JMF 0:6a929f0d0e58 117 }
JMF 0:6a929f0d0e58 118
JMF 0:6a929f0d0e58 119 int main() {
JMF 0:6a929f0d0e58 120 int rc, qStart=0, txSel=0, good = 0;
JMF 0:6a929f0d0e58 121 Timer tmr;
JMF 0:6a929f0d0e58 122 char* topic = PUBLISH_TOPIC;
JMF 0:6a929f0d0e58 123 char clientID[100], buf[100], uniqueID[50];
JMF 0:6a929f0d0e58 124
JMF 0:6a929f0d0e58 125 HTS221 hts221;
JMF 0:6a929f0d0e58 126
JMF 0:6a929f0d0e58 127 pc.baud(115200);
JMF 0:6a929f0d0e58 128 rc = hts221.init();
JMF 0:6a929f0d0e58 129 if ( rc ) {
JMF 0:6a929f0d0e58 130 pc.printf(BLU "HTS221 Detected (0x%02X)\n\r",rc);
JMF 0:6a929f0d0e58 131 pc.printf(HTS221_STR, CTOF(hts221.readTemperature()), hts221.readHumidity()/10);
JMF 0:6a929f0d0e58 132 }
JMF 0:6a929f0d0e58 133 else {
JMF 0:6a929f0d0e58 134 pc.printf(RED "HTS221 NOT DETECTED!\n\r");
JMF 0:6a929f0d0e58 135 }
JMF 0:6a929f0d0e58 136
JMF 0:6a929f0d0e58 137
JMF 0:6a929f0d0e58 138 // turn off LED
JMF 0:6a929f0d0e58 139 controlLED(blue);
JMF 0:6a929f0d0e58 140
JMF 0:6a929f0d0e58 141 // set SW2 and SW3 to generate interrupt on falling edge
JMF 0:6a929f0d0e58 142 switch2.fall(&sw2_ISR);
JMF 0:6a929f0d0e58 143 switch3.fall(&sw3_ISR);
JMF 0:6a929f0d0e58 144
JMF 0:6a929f0d0e58 145 // initialize ethernet interface
JMF 0:6a929f0d0e58 146 MQTTwnc ipstack = MQTTwnc();
JMF 0:6a929f0d0e58 147
JMF 0:6a929f0d0e58 148 // get and display client network info
JMF 0:6a929f0d0e58 149 WNCInterface& eth = ipstack.getEth();
JMF 0:6a929f0d0e58 150
JMF 0:6a929f0d0e58 151 // construct the MQTT client
JMF 0:6a929f0d0e58 152 MQTT::Client<MQTTwnc, Countdown> client = MQTT::Client<MQTTwnc, Countdown>(ipstack);
JMF 0:6a929f0d0e58 153
JMF 0:6a929f0d0e58 154 char* hostname = URL;
JMF 0:6a929f0d0e58 155 int port = PORT;
JMF 0:6a929f0d0e58 156 char *tptr = eth.getMACAddress();
JMF 0:6a929f0d0e58 157 strncpy(buf,tptr,strlen(tptr));
JMF 0:6a929f0d0e58 158 for( int x=3, i=2; i<strlen(tptr)-2; x+=3,i++ ){
JMF 0:6a929f0d0e58 159 buf[i] = buf[x];
JMF 0:6a929f0d0e58 160 buf[x]=buf[x+1];
JMF 0:6a929f0d0e58 161 }
JMF 0:6a929f0d0e58 162 sprintf(uniqueID, "Mz-%s-7010", buf);
JMF 0:6a929f0d0e58 163 sprintf(clientID, CONFIGTYPE, uniqueID);
JMF 0:6a929f0d0e58 164 printf("ClientID='%s'\r\n",clientID);
JMF 0:6a929f0d0e58 165
JMF 0:6a929f0d0e58 166 printf(" _____\r\n");
JMF 0:6a929f0d0e58 167 printf(" * *\r\n");
JMF 0:6a929f0d0e58 168 printf(" *____ *____ Bluemix IIoT Demo using\r\n");
JMF 0:6a929f0d0e58 169 printf(" * *===* *==* the AT&T IoT Starter Kit\r\n");
JMF 0:6a929f0d0e58 170 printf(" *___*===*___** AVNET\r\n");
JMF 0:6a929f0d0e58 171 printf(" *======*\r\n");
JMF 0:6a929f0d0e58 172 printf(" *====*\r\n");
JMF 0:6a929f0d0e58 173 printf("\r\n");
JMF 0:6a929f0d0e58 174 printf("This demonstration program operates the same as the original \r\n");
JMF 0:6a929f0d0e58 175 printf("MicroZed IIoT Starter Kit except it only reads from the HTS221 \r\n");
JMF 0:6a929f0d0e58 176 printf("temp sensor (no 31855 currently present and no generated data).\r\n");
JMF 0:6a929f0d0e58 177 printf("\r\n");
JMF 0:6a929f0d0e58 178 printf("Local network info...\r\n");
JMF 0:6a929f0d0e58 179 printf("IP address is %s\r\n", eth.getIPAddress());
JMF 0:6a929f0d0e58 180 printf("MAC address is %s\r\n", eth.getMACAddress());
JMF 0:6a929f0d0e58 181 printf("Gateway address is %s\r\n", eth.getGateway());
JMF 0:6a929f0d0e58 182 printf("Your <uniqueID> is: %s\r\n", uniqueID);
JMF 0:6a929f0d0e58 183 printf("---------------------------------------------------------------\r\n");
JMF 0:6a929f0d0e58 184
JMF 0:6a929f0d0e58 185 MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
JMF 0:6a929f0d0e58 186
JMF 0:6a929f0d0e58 187 int tries;
JMF 0:6a929f0d0e58 188
JMF 0:6a929f0d0e58 189 while( !good ) {
JMF 0:6a929f0d0e58 190 tries=0;
JMF 0:6a929f0d0e58 191 // connect to TCP socket and check return code
JMF 0:6a929f0d0e58 192 tmr.start();
JMF 0:6a929f0d0e58 193 rc = 1;
JMF 0:6a929f0d0e58 194 while( rc && tries < 3) {
JMF 0:6a929f0d0e58 195 printf("\r\n\r\n(%d) Attempting TCP connect to %s:%d: ", tries++, hostname, port);
JMF 0:6a929f0d0e58 196 rc = ipstack.connect(hostname, port);
JMF 0:6a929f0d0e58 197 if( rc ) {
JMF 0:6a929f0d0e58 198 printf("Failed (%d)!\r\n",rc);
JMF 0:6a929f0d0e58 199 while( tmr.read_ms() < 5000 ) ;
JMF 0:6a929f0d0e58 200 tmr.reset();
JMF 0:6a929f0d0e58 201 }
JMF 0:6a929f0d0e58 202 else {
JMF 0:6a929f0d0e58 203 printf("Success!\r\n");
JMF 0:6a929f0d0e58 204 rc = 0;
JMF 0:6a929f0d0e58 205 }
JMF 0:6a929f0d0e58 206 }
JMF 0:6a929f0d0e58 207 if( tries < 3 )
JMF 0:6a929f0d0e58 208 tries = 0;
JMF 0:6a929f0d0e58 209 else
JMF 0:6a929f0d0e58 210 continue;
JMF 0:6a929f0d0e58 211
JMF 0:6a929f0d0e58 212 data.willFlag = 0;
JMF 0:6a929f0d0e58 213 data.MQTTVersion = 3;
JMF 0:6a929f0d0e58 214
JMF 0:6a929f0d0e58 215 data.clientID.cstring = clientID;
JMF 0:6a929f0d0e58 216 // data.username.cstring = USERNAME;
JMF 0:6a929f0d0e58 217 // data.password.cstring = PASSWORD;
JMF 0:6a929f0d0e58 218 data.keepAliveInterval = 10;
JMF 0:6a929f0d0e58 219 data.cleansession = 1;
JMF 0:6a929f0d0e58 220
JMF 0:6a929f0d0e58 221 rc = 1;
JMF 0:6a929f0d0e58 222 tmr.reset();
JMF 0:6a929f0d0e58 223 while( !client.isConnected() && rc && tries < 3) {
JMF 0:6a929f0d0e58 224 printf("(%d) Attempting MQTT connect to %s:%d: ", tries++, hostname, port);
JMF 0:6a929f0d0e58 225 rc = client.connect(data);
JMF 0:6a929f0d0e58 226 if( rc ) {
JMF 0:6a929f0d0e58 227 printf("Failed (%d)!\r\n",rc);
JMF 0:6a929f0d0e58 228 while( tmr.read_ms() < 5000 );
JMF 0:6a929f0d0e58 229 tmr.reset();
JMF 0:6a929f0d0e58 230 }
JMF 0:6a929f0d0e58 231 else
JMF 0:6a929f0d0e58 232 printf("Success!\r\n");
JMF 0:6a929f0d0e58 233 }
JMF 0:6a929f0d0e58 234
JMF 0:6a929f0d0e58 235 if( tries < 3 )
JMF 0:6a929f0d0e58 236 tries = 0;
JMF 0:6a929f0d0e58 237 else
JMF 0:6a929f0d0e58 238 continue;
JMF 0:6a929f0d0e58 239
JMF 0:6a929f0d0e58 240 #if 0
JMF 0:6a929f0d0e58 241 //Only need to subscribe if we are not running quickstart
JMF 0:6a929f0d0e58 242 // subscribe to MQTT topic
JMF 0:6a929f0d0e58 243 tmr.reset();
JMF 0:6a929f0d0e58 244 rc = 1;
JMF 0:6a929f0d0e58 245 while( rc && client.isConnected() && tries < 3) {
JMF 0:6a929f0d0e58 246 printf("(%d) Attempting to subscribing to MQTT topic %s: ", tries, SUBSCRIBTOPIC);
JMF 0:6a929f0d0e58 247 rc = client.subscribe(SUBSCRIBTOPIC, MQTT::QOS0, messageArrived);
JMF 0:6a929f0d0e58 248 if( rc ) {
JMF 0:6a929f0d0e58 249 printf("Failed (%d)!\r\n", rc);
JMF 0:6a929f0d0e58 250 while( tmr.read_ms() < 5000 );
JMF 0:6a929f0d0e58 251 tries++;
JMF 0:6a929f0d0e58 252 tmr.reset();
JMF 0:6a929f0d0e58 253 }
JMF 0:6a929f0d0e58 254 else {
JMF 0:6a929f0d0e58 255 good=1;
JMF 0:6a929f0d0e58 256 printf("Subscribe successful!\r\n");
JMF 0:6a929f0d0e58 257 }
JMF 0:6a929f0d0e58 258 }
JMF 0:6a929f0d0e58 259 #else
JMF 0:6a929f0d0e58 260 good = 1;
JMF 0:6a929f0d0e58 261 #endif
JMF 0:6a929f0d0e58 262 while (!good);
JMF 0:6a929f0d0e58 263 }
JMF 0:6a929f0d0e58 264
JMF 0:6a929f0d0e58 265 MQTT::Message message;
JMF 0:6a929f0d0e58 266 message.qos = MQTT::QOS0;
JMF 0:6a929f0d0e58 267 message.retained = false;
JMF 0:6a929f0d0e58 268 message.dup = false;
JMF 0:6a929f0d0e58 269 message.payload = (void*)buf;
JMF 0:6a929f0d0e58 270
JMF 0:6a929f0d0e58 271 while(true) {
JMF 0:6a929f0d0e58 272 osEvent switchEvent = messageQ.get(100);
JMF 0:6a929f0d0e58 273
JMF 0:6a929f0d0e58 274 if( switchEvent.value.v == 22 ) //switch between sending humidity & temp
JMF 0:6a929f0d0e58 275 txSel = !txSel;
JMF 0:6a929f0d0e58 276
JMF 0:6a929f0d0e58 277 if( switchEvent.value.v == 33) //user wants to run in Quickstart of Demo mode
JMF 0:6a929f0d0e58 278 qStart = !qStart;
JMF 0:6a929f0d0e58 279
JMF 0:6a929f0d0e58 280 memset(buf,0x00,sizeof(buf));
JMF 0:6a929f0d0e58 281 if( txSel ) {
JMF 0:6a929f0d0e58 282 rc = hts221.readHumidity();
JMF 0:6a929f0d0e58 283 sprintf(buf, "{\"d\" : {\"humd\" : \"%2d.%d\" }}", rc/10, rc-((rc/10)*10));
JMF 0:6a929f0d0e58 284 printf("Publishing MQTT message '%s' ", (char*)message.payload);
JMF 0:6a929f0d0e58 285 }
JMF 0:6a929f0d0e58 286 else {
JMF 0:6a929f0d0e58 287 sprintf(buf, "{\"d\" : {\"temp\" : \"%5.1f\" }}", CTOF(hts221.readTemperature()));
JMF 0:6a929f0d0e58 288 printf("Publishing MQTT message '%s' ", (char*)message.payload);
JMF 0:6a929f0d0e58 289 }
JMF 0:6a929f0d0e58 290 message.payloadlen = strlen(buf);
JMF 0:6a929f0d0e58 291 printf("(%d)\r\n",message.payloadlen);
JMF 0:6a929f0d0e58 292 rc = client.publish(topic, message);
JMF 0:6a929f0d0e58 293 if( rc ) {
JMF 0:6a929f0d0e58 294 printf("Publish request failed! (%d)\r\n",rc);
JMF 0:6a929f0d0e58 295 FATAL_WNC_ERROR(resume);
JMF 0:6a929f0d0e58 296 }
JMF 0:6a929f0d0e58 297
JMF 0:6a929f0d0e58 298 client.yield(6000);
JMF 0:6a929f0d0e58 299 }
JMF 0:6a929f0d0e58 300 }