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.
Fork of SimpleNTP by
Diff: main.cpp
- Revision:
- 2:68ae27667d82
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Aug 01 01:22:01 2017 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+#include "EthernetInterface.h"
+#include "RealTimeClock.h"
+#include "SimpleNTP.h"
+
+EthernetInterface ether;
+RealTimeClock rtc;
+DigitalOut led[]= {LED1, LED2, LED3, LED4};
+
+void setTime()
+{
+ ether.init();
+ ether.connect();
+ led[1]= 1;
+ wait(2);
+
+ SimpleNTP sntp;
+ SimpleNTP::Result resultNTP;
+ resultNTP= sntp.setNTPServer("ntp.sanoh.com");
+ led[2]= 1;
+ if(resultNTP == SimpleNTP::SUCCESS) {
+ led[0]= 0;
+ wait(2);
+ long timeEpoch= sntp.getNetworkTime();
+ if(rtc.setRealTime(timeEpoch))
+ led[1]= 0;
+ }
+ if(sntp.close() == SimpleNTP::SUCCESS)
+ led[2]= 0;
+ return;
+}
+int main()
+{
+ led[0]= 1;
+ setTime();
+ while(1) {
+ led[3]= !led[3];
+ wait(0.2);
+ }
+}
