A simple IoTHub sample using HTTP as transport

Dependencies:   EthernetInterface NTPClient iothub_client iothub_http_transport mbed-rtos mbed wolfSSL serializer azure_c_shared_utility

This sample showcases the usage of Azure IoT client libraries with the HTTP transport for sending/receiving raw messages from an IoT Hub.

Committer:
AzureIoTClient
Date:
Thu Sep 17 00:14:36 2015 -0700
Revision:
6:c035e0e00f92
Parent:
5:0bec07661dde
Child:
7:b2c9d461ef42
New release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 0:a00ac564e057 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 0:a00ac564e057 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 0:a00ac564e057 3
AzureIoTClient 0:a00ac564e057 4 #include <stdio.h>
AzureIoTClient 0:a00ac564e057 5 #include "EthernetInterface.h"
AzureIoTClient 0:a00ac564e057 6 #include "simplesample_http.h"
AzureIoTClient 3:bca772fcee7e 7 #include "NTPClient.h"
AzureIoTClient 3:bca772fcee7e 8
AzureIoTClient 6:c035e0e00f92 9 int setupRealTime(void)
AzureIoTClient 3:bca772fcee7e 10 {
AzureIoTClient 6:c035e0e00f92 11 (void)printf("setupRealTime begin\r\n");
AzureIoTClient 6:c035e0e00f92 12 if (EthernetInterface::connect())
AzureIoTClient 6:c035e0e00f92 13 {
AzureIoTClient 6:c035e0e00f92 14 (void)printf("Error initializing EthernetInterface.\r\n");
AzureIoTClient 6:c035e0e00f92 15 result = __LINE__;
AzureIoTClient 6:c035e0e00f92 16 }
AzureIoTClient 6:c035e0e00f92 17 else
AzureIoTClient 6:c035e0e00f92 18 {
AzureIoTClient 6:c035e0e00f92 19 (void)printf("setupRealTime NTP begin\r\n");
AzureIoTClient 6:c035e0e00f92 20 NTPClient ntp;
AzureIoTClient 6:c035e0e00f92 21 if (ntp.setTime("0.pool.ntp.org") != 0)
AzureIoTClient 6:c035e0e00f92 22 {
AzureIoTClient 6:c035e0e00f92 23 (void)printf("Failed setting time.\r\n");
AzureIoTClient 6:c035e0e00f92 24 result = __LINE__;
AzureIoTClient 6:c035e0e00f92 25 }
AzureIoTClient 6:c035e0e00f92 26 else
AzureIoTClient 6:c035e0e00f92 27 {
AzureIoTClient 6:c035e0e00f92 28 (void)printf("set time correctly!\r\n");
AzureIoTClient 6:c035e0e00f92 29 result = 0;
AzureIoTClient 6:c035e0e00f92 30 }
AzureIoTClient 6:c035e0e00f92 31 (void)printf("setupRealTime NTP end\r\n");
AzureIoTClient 6:c035e0e00f92 32 EthernetInterface::disconnect();
AzureIoTClient 6:c035e0e00f92 33 }
AzureIoTClient 6:c035e0e00f92 34 (void)printf("setupRealTime end\r\n");
AzureIoTClient 6:c035e0e00f92 35
AzureIoTClient 6:c035e0e00f92 36 return result;
AzureIoTClient 3:bca772fcee7e 37 }
AzureIoTClient 0:a00ac564e057 38
AzureIoTClient 0:a00ac564e057 39 int main(void)
AzureIoTClient 0:a00ac564e057 40 {
AzureIoTClient 0:a00ac564e057 41 (void)printf("Initializing mbed specific things...\r\n");
AzureIoTClient 0:a00ac564e057 42
AzureIoTClient 3:bca772fcee7e 43 if (EthernetInterface::init())
AzureIoTClient 0:a00ac564e057 44 {
AzureIoTClient 0:a00ac564e057 45 (void)printf("Error initializing EthernetInterface.\r\n");
AzureIoTClient 0:a00ac564e057 46 return -1;
AzureIoTClient 0:a00ac564e057 47 }
AzureIoTClient 0:a00ac564e057 48
AzureIoTClient 3:bca772fcee7e 49 if (setupRealTime() != 0)
AzureIoTClient 3:bca772fcee7e 50 {
AzureIoTClient 3:bca772fcee7e 51 (void)printf("Failed setting up real time clock\r\n");
AzureIoTClient 3:bca772fcee7e 52 return -1;
AzureIoTClient 3:bca772fcee7e 53 }
AzureIoTClient 3:bca772fcee7e 54
AzureIoTClient 3:bca772fcee7e 55 simplesample_http_run();
AzureIoTClient 3:bca772fcee7e 56
AzureIoTClient 3:bca772fcee7e 57 return 0;
AzureIoTClient 0:a00ac564e057 58 }