A simple IoTHub sample using AMQP as transport
Dependencies: EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed azure_c_shared_utility serializer wolfSSL azure_uamqp_c
This sample showcases the usage of Azure IoT client libraries with the AMQP transport for sending/receiving raw messages from an IoT Hub.
main.cpp@2:fc3132155be8, 2015-09-16 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Wed Sep 16 22:43:21 2015 -0700
- Revision:
- 2:fc3132155be8
- Parent:
- 0:caa8884fe136
- Child:
- 5:f681a1af27c6
New release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 0:caa8884fe136 | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 0:caa8884fe136 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 0:caa8884fe136 | 3 | |
AzureIoTClient | 0:caa8884fe136 | 4 | #include <stdio.h> |
AzureIoTClient | 0:caa8884fe136 | 5 | #include "EthernetInterface.h" |
AzureIoTClient | 0:caa8884fe136 | 6 | #include "mbed/logging.h" |
AzureIoTClient | 0:caa8884fe136 | 7 | #include "mbed/mbedtime.h" |
AzureIoTClient | 0:caa8884fe136 | 8 | #include "simplesample_amqp.h" |
AzureIoTClient | 2:fc3132155be8 | 9 | #include "NTPClient.h" |
AzureIoTClient | 2:fc3132155be8 | 10 | |
AzureIoTClient | 2:fc3132155be8 | 11 | void setupRealTime(void) |
AzureIoTClient | 2:fc3132155be8 | 12 | { |
AzureIoTClient | 2:fc3132155be8 | 13 | (void)printf("setupRealTime begin\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 14 | if (EthernetInterface::connect()) |
AzureIoTClient | 2:fc3132155be8 | 15 | { |
AzureIoTClient | 2:fc3132155be8 | 16 | (void)printf("Error initializing EthernetInterface.\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 17 | } |
AzureIoTClient | 2:fc3132155be8 | 18 | else |
AzureIoTClient | 2:fc3132155be8 | 19 | { |
AzureIoTClient | 2:fc3132155be8 | 20 | (void)printf("setupRealTime NTP begin\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 21 | NTPClient ntp; |
AzureIoTClient | 2:fc3132155be8 | 22 | if (ntp.setTime("0.pool.ntp.org") != 0) |
AzureIoTClient | 2:fc3132155be8 | 23 | { |
AzureIoTClient | 2:fc3132155be8 | 24 | (void)printf("Failed setting time.\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 25 | } |
AzureIoTClient | 2:fc3132155be8 | 26 | else |
AzureIoTClient | 2:fc3132155be8 | 27 | { |
AzureIoTClient | 2:fc3132155be8 | 28 | (void)printf("set time correctly!\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 29 | } |
AzureIoTClient | 2:fc3132155be8 | 30 | (void)printf("setupRealTime NTP end\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 31 | EthernetInterface::disconnect(); |
AzureIoTClient | 2:fc3132155be8 | 32 | } |
AzureIoTClient | 2:fc3132155be8 | 33 | (void)printf("setupRealTime end\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 34 | } |
AzureIoTClient | 0:caa8884fe136 | 35 | |
AzureIoTClient | 0:caa8884fe136 | 36 | int main(void) |
AzureIoTClient | 0:caa8884fe136 | 37 | { |
AzureIoTClient | 0:caa8884fe136 | 38 | (void)printf("Initializing mbed specific things...\r\n"); |
AzureIoTClient | 0:caa8884fe136 | 39 | |
AzureIoTClient | 0:caa8884fe136 | 40 | mbed_log_init(); |
AzureIoTClient | 0:caa8884fe136 | 41 | mbedtime_init(); |
AzureIoTClient | 0:caa8884fe136 | 42 | |
AzureIoTClient | 2:fc3132155be8 | 43 | if (EthernetInterface::init()) |
AzureIoTClient | 2:fc3132155be8 | 44 | { |
AzureIoTClient | 2:fc3132155be8 | 45 | (void)printf("Error initializing EthernetInterface.\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 46 | return -1; |
AzureIoTClient | 2:fc3132155be8 | 47 | } |
AzureIoTClient | 2:fc3132155be8 | 48 | |
AzureIoTClient | 2:fc3132155be8 | 49 | if (setupRealTime() != 0) |
AzureIoTClient | 2:fc3132155be8 | 50 | { |
AzureIoTClient | 2:fc3132155be8 | 51 | (void)printf("Failed setting up real time clock\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 52 | return -1; |
AzureIoTClient | 2:fc3132155be8 | 53 | } |
AzureIoTClient | 2:fc3132155be8 | 54 | |
AzureIoTClient | 2:fc3132155be8 | 55 | if (EthernetInterface::connect()) |
AzureIoTClient | 2:fc3132155be8 | 56 | { |
AzureIoTClient | 2:fc3132155be8 | 57 | (void)printf("Error connecting EthernetInterface.\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 58 | return -1; |
AzureIoTClient | 2:fc3132155be8 | 59 | } |
AzureIoTClient | 0:caa8884fe136 | 60 | |
AzureIoTClient | 0:caa8884fe136 | 61 | simplesample_amqp_run(); |
AzureIoTClient | 2:fc3132155be8 | 62 | |
AzureIoTClient | 2:fc3132155be8 | 63 | (void)EthernetInterface::disconnect(); |
AzureIoTClient | 2:fc3132155be8 | 64 | |
AzureIoTClient | 2:fc3132155be8 | 65 | return 0; |
AzureIoTClient | 0:caa8884fe136 | 66 | } |