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