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