Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface NTPClient SHTx iothub_amqp_transport iothub_client mbed-rtos mbed proton-c-mbed serializer wolfSSL
Fork of remote_monitoring by
main.cpp@18:99b21c7c3599, 2015-09-30 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Wed Sep 30 00:09:59 2015 +0000
- Revision:
- 18:99b21c7c3599
- Parent:
- 15:4a41d2a27a8c
Updated dependencies for new mbed snapshot
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| AzureIoTClient | 0:422f22f60a44 | 1 | // Copyright (c) Microsoft. All rights reserved. |
| AzureIoTClient | 0:422f22f60a44 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| AzureIoTClient | 0:422f22f60a44 | 3 | |
| AzureIoTClient | 0:422f22f60a44 | 4 | #include <stdio.h> |
| AzureIoTClient | 0:422f22f60a44 | 5 | #include "EthernetInterface.h" |
| AzureIoTClient | 0:422f22f60a44 | 6 | #include "mbed/logging.h" |
| AzureIoTClient | 0:422f22f60a44 | 7 | #include "mbed/mbedtime.h" |
| AzureIoTClient | 9:a43d30a74a1b | 8 | #include "remote_monitoring.h" |
| AzureIoTClient | 2:90e50410da9b | 9 | #include "NTPClient.h" |
| AzureIoTClient | 2:90e50410da9b | 10 | |
| AzureIoTClient | 5:0ac6b44084ed | 11 | int setupRealTime(void) |
| AzureIoTClient | 2:90e50410da9b | 12 | { |
| AzureIoTClient | 6:066c3ca4df78 | 13 | int result; |
| AzureIoTClient | 6:066c3ca4df78 | 14 | |
| AzureIoTClient | 2:90e50410da9b | 15 | (void)printf("setupRealTime begin\r\n"); |
| AzureIoTClient | 2:90e50410da9b | 16 | if (EthernetInterface::connect()) |
| AzureIoTClient | 2:90e50410da9b | 17 | { |
| AzureIoTClient | 2:90e50410da9b | 18 | (void)printf("Error initializing EthernetInterface.\r\n"); |
| AzureIoTClient | 5:0ac6b44084ed | 19 | result = __LINE__; |
| AzureIoTClient | 2:90e50410da9b | 20 | } |
| AzureIoTClient | 2:90e50410da9b | 21 | else |
| AzureIoTClient | 2:90e50410da9b | 22 | { |
| AzureIoTClient | 2:90e50410da9b | 23 | (void)printf("setupRealTime NTP begin\r\n"); |
| AzureIoTClient | 2:90e50410da9b | 24 | NTPClient ntp; |
| AzureIoTClient | 2:90e50410da9b | 25 | if (ntp.setTime("0.pool.ntp.org") != 0) |
| AzureIoTClient | 2:90e50410da9b | 26 | { |
| AzureIoTClient | 2:90e50410da9b | 27 | (void)printf("Failed setting time.\r\n"); |
| AzureIoTClient | 5:0ac6b44084ed | 28 | result = __LINE__; |
| AzureIoTClient | 2:90e50410da9b | 29 | } |
| AzureIoTClient | 2:90e50410da9b | 30 | else |
| AzureIoTClient | 2:90e50410da9b | 31 | { |
| AzureIoTClient | 2:90e50410da9b | 32 | (void)printf("set time correctly!\r\n"); |
| AzureIoTClient | 5:0ac6b44084ed | 33 | result = 0; |
| AzureIoTClient | 2:90e50410da9b | 34 | } |
| AzureIoTClient | 2:90e50410da9b | 35 | (void)printf("setupRealTime NTP end\r\n"); |
| AzureIoTClient | 2:90e50410da9b | 36 | EthernetInterface::disconnect(); |
| AzureIoTClient | 2:90e50410da9b | 37 | } |
| AzureIoTClient | 2:90e50410da9b | 38 | (void)printf("setupRealTime end\r\n"); |
| AzureIoTClient | 5:0ac6b44084ed | 39 | |
| AzureIoTClient | 5:0ac6b44084ed | 40 | return result; |
| AzureIoTClient | 2:90e50410da9b | 41 | } |
| AzureIoTClient | 0:422f22f60a44 | 42 | |
| AzureIoTClient | 0:422f22f60a44 | 43 | int main(void) |
| AzureIoTClient | 0:422f22f60a44 | 44 | { |
| AzureIoTClient | 0:422f22f60a44 | 45 | (void)printf("Initializing mbed specific things...\r\n"); |
| AzureIoTClient | 0:422f22f60a44 | 46 | |
| AzureIoTClient | 15:4a41d2a27a8c | 47 | /* These are needed in order to initialize the time provider for Proton-C */ |
| AzureIoTClient | 15:4a41d2a27a8c | 48 | mbed_log_init(); |
| AzureIoTClient | 15:4a41d2a27a8c | 49 | mbedtime_init(); |
| AzureIoTClient | 15:4a41d2a27a8c | 50 | |
| AzureIoTClient | 2:90e50410da9b | 51 | if (EthernetInterface::init()) |
| AzureIoTClient | 2:90e50410da9b | 52 | { |
| AzureIoTClient | 2:90e50410da9b | 53 | (void)printf("Error initializing EthernetInterface.\r\n"); |
| AzureIoTClient | 2:90e50410da9b | 54 | return -1; |
| AzureIoTClient | 2:90e50410da9b | 55 | } |
| AzureIoTClient | 0:422f22f60a44 | 56 | |
| AzureIoTClient | 2:90e50410da9b | 57 | if (setupRealTime() != 0) |
| AzureIoTClient | 2:90e50410da9b | 58 | { |
| AzureIoTClient | 2:90e50410da9b | 59 | (void)printf("Failed setting up real time clock\r\n"); |
| AzureIoTClient | 2:90e50410da9b | 60 | return -1; |
| AzureIoTClient | 2:90e50410da9b | 61 | } |
| AzureIoTClient | 2:90e50410da9b | 62 | |
| AzureIoTClient | 2:90e50410da9b | 63 | if (EthernetInterface::connect()) |
| AzureIoTClient | 2:90e50410da9b | 64 | { |
| AzureIoTClient | 2:90e50410da9b | 65 | (void)printf("Error connecting EthernetInterface.\r\n"); |
| AzureIoTClient | 2:90e50410da9b | 66 | return -1; |
| AzureIoTClient | 2:90e50410da9b | 67 | } |
| AzureIoTClient | 0:422f22f60a44 | 68 | |
| AzureIoTClient | 9:a43d30a74a1b | 69 | remote_monitoring_run(); |
| AzureIoTClient | 0:422f22f60a44 | 70 | |
| AzureIoTClient | 2:90e50410da9b | 71 | (void)EthernetInterface::disconnect(); |
| AzureIoTClient | 2:90e50410da9b | 72 | |
| AzureIoTClient | 0:422f22f60a44 | 73 | return 0; |
| AzureIoTClient | 0:422f22f60a44 | 74 | } |
