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@5:f681a1af27c6, 2015-09-17 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Thu Sep 17 00:12:52 2015 -0700
- Revision:
- 5:f681a1af27c6
- Parent:
- 2:fc3132155be8
- Child:
- 6:8121913f61d7
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 | 5:f681a1af27c6 | 11 | int 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 | 5:f681a1af27c6 | 17 | result = __LINE__; |
AzureIoTClient | 2:fc3132155be8 | 18 | } |
AzureIoTClient | 2:fc3132155be8 | 19 | else |
AzureIoTClient | 2:fc3132155be8 | 20 | { |
AzureIoTClient | 2:fc3132155be8 | 21 | (void)printf("setupRealTime NTP begin\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 22 | NTPClient ntp; |
AzureIoTClient | 2:fc3132155be8 | 23 | if (ntp.setTime("0.pool.ntp.org") != 0) |
AzureIoTClient | 2:fc3132155be8 | 24 | { |
AzureIoTClient | 2:fc3132155be8 | 25 | (void)printf("Failed setting time.\r\n"); |
AzureIoTClient | 5:f681a1af27c6 | 26 | result = __LINE__; |
AzureIoTClient | 2:fc3132155be8 | 27 | } |
AzureIoTClient | 2:fc3132155be8 | 28 | else |
AzureIoTClient | 2:fc3132155be8 | 29 | { |
AzureIoTClient | 2:fc3132155be8 | 30 | (void)printf("set time correctly!\r\n"); |
AzureIoTClient | 5:f681a1af27c6 | 31 | result = 0; |
AzureIoTClient | 2:fc3132155be8 | 32 | } |
AzureIoTClient | 2:fc3132155be8 | 33 | (void)printf("setupRealTime NTP end\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 34 | EthernetInterface::disconnect(); |
AzureIoTClient | 2:fc3132155be8 | 35 | } |
AzureIoTClient | 2:fc3132155be8 | 36 | (void)printf("setupRealTime end\r\n"); |
AzureIoTClient | 5:f681a1af27c6 | 37 | |
AzureIoTClient | 5:f681a1af27c6 | 38 | return result; |
AzureIoTClient | 2:fc3132155be8 | 39 | } |
AzureIoTClient | 0:caa8884fe136 | 40 | |
AzureIoTClient | 0:caa8884fe136 | 41 | int main(void) |
AzureIoTClient | 0:caa8884fe136 | 42 | { |
AzureIoTClient | 0:caa8884fe136 | 43 | (void)printf("Initializing mbed specific things...\r\n"); |
AzureIoTClient | 0:caa8884fe136 | 44 | |
AzureIoTClient | 0:caa8884fe136 | 45 | mbed_log_init(); |
AzureIoTClient | 0:caa8884fe136 | 46 | mbedtime_init(); |
AzureIoTClient | 0:caa8884fe136 | 47 | |
AzureIoTClient | 2:fc3132155be8 | 48 | if (EthernetInterface::init()) |
AzureIoTClient | 2:fc3132155be8 | 49 | { |
AzureIoTClient | 2:fc3132155be8 | 50 | (void)printf("Error initializing EthernetInterface.\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 51 | return -1; |
AzureIoTClient | 2:fc3132155be8 | 52 | } |
AzureIoTClient | 2:fc3132155be8 | 53 | |
AzureIoTClient | 2:fc3132155be8 | 54 | if (setupRealTime() != 0) |
AzureIoTClient | 2:fc3132155be8 | 55 | { |
AzureIoTClient | 2:fc3132155be8 | 56 | (void)printf("Failed setting up real time clock\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 57 | return -1; |
AzureIoTClient | 2:fc3132155be8 | 58 | } |
AzureIoTClient | 2:fc3132155be8 | 59 | |
AzureIoTClient | 2:fc3132155be8 | 60 | if (EthernetInterface::connect()) |
AzureIoTClient | 2:fc3132155be8 | 61 | { |
AzureIoTClient | 2:fc3132155be8 | 62 | (void)printf("Error connecting EthernetInterface.\r\n"); |
AzureIoTClient | 2:fc3132155be8 | 63 | return -1; |
AzureIoTClient | 2:fc3132155be8 | 64 | } |
AzureIoTClient | 0:caa8884fe136 | 65 | |
AzureIoTClient | 0:caa8884fe136 | 66 | simplesample_amqp_run(); |
AzureIoTClient | 2:fc3132155be8 | 67 | |
AzureIoTClient | 2:fc3132155be8 | 68 | (void)EthernetInterface::disconnect(); |
AzureIoTClient | 2:fc3132155be8 | 69 | |
AzureIoTClient | 2:fc3132155be8 | 70 | return 0; |
AzureIoTClient | 0:caa8884fe136 | 71 | } |