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
main.cpp
00001 /* 00002 * UDENOKAI #5 SAMPLE PROGRAM: Tweeting with mbed! 00003 * 00004 * Using SuperTweet.Net API Proxy (setup required). 00005 * Based on cookbook/Twitter 00006 */ 00007 #include "mbed.h" 00008 #include "EthernetNetIf.h" 00009 #include "HTTPClient.h" 00010 #include "TextLCD.h" // Orange Board 00011 00012 //tuika 00013 #include "NTPClient.h" 00014 00015 00016 Serial pc(USBTX, USBRX); // tx, rx 00017 TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 00018 EthernetNetIf eth; 00019 NTPClient ntp; 00020 00021 int main() { 00022 char message[64], name[32], twID[32], twPW[32]; 00023 sprintf(message, "hogehogefugafuga"); 00024 sprintf(name, "@hoge"); // ex) @kagamikan 00025 sprintf(twID, "foo"); // ex) udenokai 00026 sprintf(twPW, "boo"); // ex) hoge 00027 time_t ctTime; 00028 00029 pc.printf("\r\nSetting up...\r\n"); 00030 lcd.printf("Setting up..."); 00031 EthernetErr ethErr = eth.setup(); 00032 if(ethErr) { 00033 printf("Error %d in setup.\n", ethErr); 00034 lcd.printf("\nError %d in setup.", ethErr); 00035 return -1; 00036 } 00037 IpAddr ip = eth.getIp(); 00038 pc.printf("\r\nSetup OK\r\n"); 00039 lcd.cls(); 00040 lcd.printf("IP Address:\n%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); 00041 00042 time_t sec = time(NULL); 00043 char tweet[128], ts[32]; 00044 00045 00046 00047 //kokowotuika 00048 Host server(IpAddr(), 123, "ntp.nict.jp"); 00049 ntp.setTime(server); 00050 ctTime = time(NULL); 00051 ctTime += 32400; //set jst time 00052 00053 //localtime no hikisuu wo henkou 00054 strftime(ts, 32, "%I:%M %p\n", localtime(&ctTime)); 00055 00056 00057 00058 sprintf(tweet, "%s (%s's mbed at %s JST) #udenokai", message, name, ts); 00059 pc.printf( "%s (%s's mbed at %s JST) #udenokai", message, name , ts); //console nimo tui-to naiyou wo dasu 00060 00061 HTTPClient twitter; 00062 HTTPMap msg; 00063 msg["status"] = tweet; 00064 twitter.basicAuth(twID, twPW); 00065 HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL); 00066 if(r == HTTP_OK) { 00067 pc.printf("Tweet success!\n"); 00068 lcd.cls(); 00069 lcd.printf("\nTweet success!"); 00070 } else { 00071 pc.printf("Tweet failed (Code:%d)\n", r); 00072 lcd.cls(); 00073 lcd.printf("\nTweet failed (%d)", r); 00074 } 00075 00076 00077 return 0; 00078 }
Generated on Mon Jul 18 2022 01:40:28 by
1.7.2