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:26:54 2015 -0700
Revision:
7:b2c9d461ef42
Parent:
6:c035e0e00f92
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 7:b2c9d461ef42 11 int result;
AzureIoTClient 7:b2c9d461ef42 12
AzureIoTClient 6:c035e0e00f92 13 (void)printf("setupRealTime begin\r\n");
AzureIoTClient 6:c035e0e00f92 14 if (EthernetInterface::connect())
AzureIoTClient 6:c035e0e00f92 15 {
AzureIoTClient 6:c035e0e00f92 16 (void)printf("Error initializing EthernetInterface.\r\n");
AzureIoTClient 6:c035e0e00f92 17 result = __LINE__;
AzureIoTClient 6:c035e0e00f92 18 }
AzureIoTClient 6:c035e0e00f92 19 else
AzureIoTClient 6:c035e0e00f92 20 {
AzureIoTClient 6:c035e0e00f92 21 (void)printf("setupRealTime NTP begin\r\n");
AzureIoTClient 6:c035e0e00f92 22 NTPClient ntp;
AzureIoTClient 6:c035e0e00f92 23 if (ntp.setTime("0.pool.ntp.org") != 0)
AzureIoTClient 6:c035e0e00f92 24 {
AzureIoTClient 6:c035e0e00f92 25 (void)printf("Failed setting time.\r\n");
AzureIoTClient 6:c035e0e00f92 26 result = __LINE__;
AzureIoTClient 6:c035e0e00f92 27 }
AzureIoTClient 6:c035e0e00f92 28 else
AzureIoTClient 6:c035e0e00f92 29 {
AzureIoTClient 6:c035e0e00f92 30 (void)printf("set time correctly!\r\n");
AzureIoTClient 6:c035e0e00f92 31 result = 0;
AzureIoTClient 6:c035e0e00f92 32 }
AzureIoTClient 6:c035e0e00f92 33 (void)printf("setupRealTime NTP end\r\n");
AzureIoTClient 6:c035e0e00f92 34 EthernetInterface::disconnect();
AzureIoTClient 6:c035e0e00f92 35 }
AzureIoTClient 6:c035e0e00f92 36 (void)printf("setupRealTime end\r\n");
AzureIoTClient 6:c035e0e00f92 37
AzureIoTClient 6:c035e0e00f92 38 return result;
AzureIoTClient 3:bca772fcee7e 39 }
AzureIoTClient 0:a00ac564e057 40
AzureIoTClient 0:a00ac564e057 41 int main(void)
AzureIoTClient 0:a00ac564e057 42 {
AzureIoTClient 0:a00ac564e057 43 (void)printf("Initializing mbed specific things...\r\n");
AzureIoTClient 0:a00ac564e057 44
AzureIoTClient 3:bca772fcee7e 45 if (EthernetInterface::init())
AzureIoTClient 0:a00ac564e057 46 {
AzureIoTClient 0:a00ac564e057 47 (void)printf("Error initializing EthernetInterface.\r\n");
AzureIoTClient 0:a00ac564e057 48 return -1;
AzureIoTClient 0:a00ac564e057 49 }
AzureIoTClient 0:a00ac564e057 50
AzureIoTClient 3:bca772fcee7e 51 if (setupRealTime() != 0)
AzureIoTClient 3:bca772fcee7e 52 {
AzureIoTClient 3:bca772fcee7e 53 (void)printf("Failed setting up real time clock\r\n");
AzureIoTClient 3:bca772fcee7e 54 return -1;
AzureIoTClient 3:bca772fcee7e 55 }
AzureIoTClient 3:bca772fcee7e 56
AzureIoTClient 3:bca772fcee7e 57 simplesample_http_run();
AzureIoTClient 3:bca772fcee7e 58
AzureIoTClient 3:bca772fcee7e 59 return 0;
AzureIoTClient 0:a00ac564e057 60 }