Remote monitoring IoTHub device sample Added real SHTx sensor to get temperature and humidity Added new command to set temperature scale change Removed "mock" commands to set temperature and humidity values It's configured to work on FRDM-K64F board
Dependencies: EthernetInterface NTPClient SHTx iothub_amqp_transport iothub_client mbed-rtos mbed proton-c-mbed serializer wolfSSL
Fork of remote_monitoring by
Diff: main.cpp
- Revision:
- 2:90e50410da9b
- Parent:
- 0:422f22f60a44
- Child:
- 5:0ac6b44084ed
--- a/main.cpp Wed Sep 16 21:46:20 2015 +0000 +++ b/main.cpp Wed Sep 16 22:43:16 2015 -0700 @@ -6,22 +6,58 @@ #include "mbed/logging.h" #include "mbed/mbedtime.h" #include "asset_monitoring.h" +#include "NTPClient.h" + +void setupRealTime(void) +{ + (void)printf("setupRealTime begin\r\n"); + if (EthernetInterface::connect()) + { + (void)printf("Error initializing EthernetInterface.\r\n"); + } + else + { + (void)printf("setupRealTime NTP begin\r\n"); + NTPClient ntp; + if (ntp.setTime("0.pool.ntp.org") != 0) + { + (void)printf("Failed setting time.\r\n"); + } + else + { + (void)printf("set time correctly!\r\n"); + } + (void)printf("setupRealTime NTP end\r\n"); + EthernetInterface::disconnect(); + } + (void)printf("setupRealTime end\r\n"); +} int main(void) { (void)printf("Initializing mbed specific things...\r\n"); - mbed_log_init(); - mbedtime_init(); + if (EthernetInterface::init()) + { + (void)printf("Error initializing EthernetInterface.\r\n"); + return -1; + } - EthernetInterface eth; - if (eth.init() || eth.connect()) - { - (void)printf("Error initializing EthernetInterface.\r\n"); - return -1; - } + if (setupRealTime() != 0) + { + (void)printf("Failed setting up real time clock\r\n"); + return -1; + } + + if (EthernetInterface::connect()) + { + (void)printf("Error connecting EthernetInterface.\r\n"); + return -1; + } asset_monitoring_run(); + (void)EthernetInterface::disconnect(); + return 0; }