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 Oct 22 18:33:57 2015 -0700
Revision:
17:3abbcd6aac9f
Child:
22:3acb69edee6b
v1.0.0-preview.4

Who changed what in which revision?

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