This is made by seminal03_SIT_mechanical_engineering. This quotes ban4jp"CyaSSL_Twitter-OAuth4Tw".
Dependencies: EthernetInterface HTTPClient-wolfSSL NTPClient OAuth4Tw mbed-rtos mbed wolfSSL
Fork of CyaSSL-Twitter-OAuth4Tw by
main.cpp@1:4dfa9d41f414, 2014-12-14 (annotated)
- Committer:
- ban4jp
- Date:
- Sun Dec 14 08:08:14 2014 +0000
- Revision:
- 1:4dfa9d41f414
- Parent:
- 0:00a2d3570824
- Child:
- 2:392b8e079c7a
Twitter client that can be directly tweet. (Intermediate server is not required.)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
geodenx | 0:00a2d3570824 | 1 | #include <string.h> |
geodenx | 0:00a2d3570824 | 2 | #include "mbed.h" |
ban4jp | 1:4dfa9d41f414 | 3 | #include "EthernetInterface.h" |
ban4jp | 1:4dfa9d41f414 | 4 | #include "NTPClient.h" |
geodenx | 0:00a2d3570824 | 5 | #include "OAuth4Tw.h" |
geodenx | 0:00a2d3570824 | 6 | |
geodenx | 0:00a2d3570824 | 7 | DigitalOut myled(LED1); |
ban4jp | 1:4dfa9d41f414 | 8 | EthernetInterface eth; |
ban4jp | 1:4dfa9d41f414 | 9 | NTPClient ntp; |
ban4jp | 1:4dfa9d41f414 | 10 | |
ban4jp | 1:4dfa9d41f414 | 11 | OAuth4Tw oa4t("XXXXXXXXXXXXXXXXXXXXXXXXX", // Consumer key |
ban4jp | 1:4dfa9d41f414 | 12 | "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // Consumer secret |
ban4jp | 1:4dfa9d41f414 | 13 | "000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Access token |
ban4jp | 1:4dfa9d41f414 | 14 | "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // Access token secret |
geodenx | 0:00a2d3570824 | 15 | |
ban4jp | 1:4dfa9d41f414 | 16 | int main() |
ban4jp | 1:4dfa9d41f414 | 17 | { |
ban4jp | 1:4dfa9d41f414 | 18 | int ret = eth.init(); //Use DHCP |
ban4jp | 1:4dfa9d41f414 | 19 | if (!ret) { |
ban4jp | 1:4dfa9d41f414 | 20 | printf("Initialized, MAC: %s\n", eth.getMACAddress()); |
ban4jp | 1:4dfa9d41f414 | 21 | } else { |
ban4jp | 1:4dfa9d41f414 | 22 | printf("Error eth.init() - ret = %d\n", ret); |
geodenx | 0:00a2d3570824 | 23 | return -1; |
geodenx | 0:00a2d3570824 | 24 | } |
geodenx | 0:00a2d3570824 | 25 | |
ban4jp | 1:4dfa9d41f414 | 26 | ret = eth.connect(); |
ban4jp | 1:4dfa9d41f414 | 27 | if (!ret) { |
ban4jp | 1:4dfa9d41f414 | 28 | printf("Connected, IP: %s, MASK: %s, GW: %s\n", |
ban4jp | 1:4dfa9d41f414 | 29 | eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
ban4jp | 1:4dfa9d41f414 | 30 | } else { |
ban4jp | 1:4dfa9d41f414 | 31 | printf("Error eth.connect() - ret = %d\n", ret); |
ban4jp | 1:4dfa9d41f414 | 32 | return -1; |
ban4jp | 1:4dfa9d41f414 | 33 | } |
ban4jp | 1:4dfa9d41f414 | 34 | |
ban4jp | 1:4dfa9d41f414 | 35 | printf("Trying to update time...\n"); |
ban4jp | 1:4dfa9d41f414 | 36 | |
ban4jp | 1:4dfa9d41f414 | 37 | //ret = ntp.setTime("pool.ntp.org"); |
ban4jp | 1:4dfa9d41f414 | 38 | ret = ntp.setTime("ntp.nict.jp"); |
ban4jp | 1:4dfa9d41f414 | 39 | if (!ret) { |
ban4jp | 1:4dfa9d41f414 | 40 | time_t ctTime = time(NULL); |
ban4jp | 1:4dfa9d41f414 | 41 | printf("Time is set to (UTC): %s\n", ctime(&ctTime)); |
ban4jp | 1:4dfa9d41f414 | 42 | } else { |
ban4jp | 1:4dfa9d41f414 | 43 | printf("Error\n"); |
ban4jp | 1:4dfa9d41f414 | 44 | } |
ban4jp | 1:4dfa9d41f414 | 45 | |
ban4jp | 1:4dfa9d41f414 | 46 | std::string uri = "https://api.twitter.com/1.1/statuses/update.json"; |
geodenx | 0:00a2d3570824 | 47 | uri += "?status="; |
geodenx | 0:00a2d3570824 | 48 | uri += OAuth4Tw::url_escape("Hello World!"); |
geodenx | 0:00a2d3570824 | 49 | std::string postarg; |
geodenx | 0:00a2d3570824 | 50 | std::string postres = oa4t.post(uri.c_str(), postarg); |
geodenx | 0:00a2d3570824 | 51 | printf("postres: %s\n", postres.c_str()); |
geodenx | 0:00a2d3570824 | 52 | |
geodenx | 0:00a2d3570824 | 53 | while (1) { |
geodenx | 0:00a2d3570824 | 54 | myled = 1; |
geodenx | 0:00a2d3570824 | 55 | wait(0.2); |
geodenx | 0:00a2d3570824 | 56 | myled = 0; |
geodenx | 0:00a2d3570824 | 57 | wait(0.2); |
geodenx | 0:00a2d3570824 | 58 | } |
geodenx | 0:00a2d3570824 | 59 | } |