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: EthernetNetIf NTPClient_NetServices TextLCD mbed
Revision 1:5f287a9e95c8, committed 2011-06-14
- Comitter:
- kagamikan
- Date:
- Tue Jun 14 09:25:04 2011 +0000
- Parent:
- 0:2e771f40cf84
- Commit message:
- add NTP time setting (contributed by T.Myojo)
Changed in this revision
| NTPClient.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2e771f40cf84 -r 5f287a9e95c8 NTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NTPClient.lib Tue Jun 14 09:25:04 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/NTPClient/#7c3f1199256a
diff -r 2e771f40cf84 -r 5f287a9e95c8 main.cpp
--- a/main.cpp Sat Jun 11 16:19:38 2011 +0000
+++ b/main.cpp Tue Jun 14 09:25:04 2011 +0000
@@ -7,19 +7,24 @@
#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"
-#include "TextLCD.h" // Orange Board
+#include "NTPClient.h"
+#include "TextLCD.h"
Serial pc(USBTX, USBRX); // tx, rx
TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
EthernetNetIf eth;
+NTPClient ntp;
int main() {
+
+ // Tweet informations
char message[64], name[32], twID[32], twPW[32];
sprintf(message, "hogehogefugafuga");
- sprintf(name, "INPUT_YOUR_NAME"); // ex) @kagamikan
- sprintf(twID, "INPUT_YOUR_ID"); // ex) udenokai
- sprintf(twPW, "INPUT_YOUR_PASSWORD"); // ex) hoge
+ sprintf(name, "hoge"); // ex) @kagamikan
+ sprintf(twID, "fuga"); // ex) udenokai
+ sprintf(twPW, "piyo"); // ex) hoge
+ // Setup IP Network
pc.printf("\r\nSetting up...\r\n");
lcd.printf("Setting up...");
EthernetErr ethErr = eth.setup();
@@ -33,12 +38,21 @@
lcd.cls();
lcd.printf("IP Address:\n%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
- time_t sec = time(NULL);
+ // Setting time with NTP
+ Host server(IpAddr(), 123, "ntp.nict.jp");
+ ntp.setTime(server);
+ time_t ctTime;
+ ctTime = time(NULL);
+ ctTime += 32400; //set jst time
+
+ // Building the tweet
char tweet[128], ts[32];
- strftime(ts, 32, "%I:%M %p\n", localtime(&sec));
- sprintf(tweet, "%s (%s's mbed at %s UTC) #udenokai", message, name, ts);
+ strftime(ts, 32, "%I:%M %p\n", localtime(&ctTime));
+ sprintf(tweet, "%s (%s's mbed at %s JST) #udenokai", message, name, ts);
+ pc.printf(tweet);
- HTTPClient twitter;
+ // Sending the tweet
+ HTTPClient twitter;
HTTPMap msg;
msg["status"] = tweet;
twitter.basicAuth(twID, twPW);
@@ -52,5 +66,6 @@
lcd.cls();
lcd.printf("\nTweet failed (%d)", r);
}
+
return 0;
}
\ No newline at end of file