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@7:48019055e3a3, 2016-02-04 (annotated)
- Committer:
- mbed2015
- Date:
- Thu Feb 04 01:50:30 2016 +0000
- Revision:
- 7:48019055e3a3
- Parent:
- 6:f5189d4f109f
?????????????????????????????????????????????????????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed2015 | 7:48019055e3a3 | 1 | // Original: https://developer.mbed.org/users/ban4jp/code/CyaSSL-Twitter-OAuth4Tw/ |
mbed2015 | 7:48019055e3a3 | 2 | |
geodenx | 0:00a2d3570824 | 3 | #include <string.h> |
geodenx | 0:00a2d3570824 | 4 | #include "mbed.h" |
ban4jp | 1:4dfa9d41f414 | 5 | #include "EthernetInterface.h" |
ban4jp | 1:4dfa9d41f414 | 6 | #include "NTPClient.h" |
geodenx | 0:00a2d3570824 | 7 | #include "OAuth4Tw.h" |
mbed2015 | 7:48019055e3a3 | 8 | #include "lwip/dns.h" |
mbed2015 | 7:48019055e3a3 | 9 | |
geodenx | 0:00a2d3570824 | 10 | |
ban4jp | 6:f5189d4f109f | 11 | Serial pc(USBTX, USBRX); |
geodenx | 0:00a2d3570824 | 12 | DigitalOut myled(LED1); |
ban4jp | 1:4dfa9d41f414 | 13 | EthernetInterface eth; |
ban4jp | 1:4dfa9d41f414 | 14 | NTPClient ntp; |
ban4jp | 1:4dfa9d41f414 | 15 | |
mbed2015 | 7:48019055e3a3 | 16 | OAuth4Tw oa4t("f3fcA4S61FcOz0VMLgia9ewn2",// Consumer key |
mbed2015 | 7:48019055e3a3 | 17 | "Djaz2ooEf95b8yr3yE7DWS1XrYuwjBYZdz7QqnDKFTKNdMd8Ml", // Consumer secret |
mbed2015 | 7:48019055e3a3 | 18 | "4044135739-da2aYe6fs6aCcpCKlqagVxM3rjDj5yPUaJaZ7O7", // Access token |
mbed2015 | 7:48019055e3a3 | 19 | "uIrtt88FWWIz2yqpU9AkBeoLEHW5ls5ZdA9SoQvcGY47c");// Access token secret |
mbed2015 | 7:48019055e3a3 | 20 | |
mbed2015 | 7:48019055e3a3 | 21 | |
geodenx | 0:00a2d3570824 | 22 | |
ban4jp | 5:f0c0128cde62 | 23 | #if defined(TARGET_LPC1768) |
ban4jp | 6:f5189d4f109f | 24 | #define RESPONSE_BUFFER_SIZE 512 |
ban4jp | 6:f5189d4f109f | 25 | #elif defined(TARGET_K64F) || defined(TARGET_LPC4088) |
ban4jp | 6:f5189d4f109f | 26 | #define RESPONSE_BUFFER_SIZE 4096 |
ban4jp | 5:f0c0128cde62 | 27 | #else |
ban4jp | 5:f0c0128cde62 | 28 | #error not tested platform. |
ban4jp | 5:f0c0128cde62 | 29 | #endif |
ban4jp | 4:fcadeb9bdcbd | 30 | |
ban4jp | 6:f5189d4f109f | 31 | char response_buffer[RESPONSE_BUFFER_SIZE]; |
ban4jp | 6:f5189d4f109f | 32 | HTTPText response(response_buffer, sizeof(response_buffer)); |
ban4jp | 6:f5189d4f109f | 33 | |
ban4jp | 6:f5189d4f109f | 34 | // prototype |
ban4jp | 6:f5189d4f109f | 35 | void updateTime(); |
ban4jp | 6:f5189d4f109f | 36 | void example_tweet1(); |
ban4jp | 6:f5189d4f109f | 37 | void example_tweet2(); |
ban4jp | 6:f5189d4f109f | 38 | void example_tweet3(); |
ban4jp | 6:f5189d4f109f | 39 | void example_getUserData(); |
mbed2015 | 7:48019055e3a3 | 40 | void mm2(void); |
mbed2015 | 7:48019055e3a3 | 41 | |
mbed2015 | 7:48019055e3a3 | 42 | Ticker mmTicker; |
mbed2015 | 7:48019055e3a3 | 43 | volatile int sum = 0; |
ban4jp | 6:f5189d4f109f | 44 | |
ban4jp | 1:4dfa9d41f414 | 45 | int main() |
ban4jp | 1:4dfa9d41f414 | 46 | { |
ban4jp | 6:f5189d4f109f | 47 | pc.baud(115200); |
ban4jp | 6:f5189d4f109f | 48 | |
mbed2015 | 7:48019055e3a3 | 49 | eth.init(); |
mbed2015 | 7:48019055e3a3 | 50 | // eth.init("172.20.29.40","255.255.255.0","172.20.29.1"); |
mbed2015 | 7:48019055e3a3 | 51 | // printf("Initialized, MAC: %s\n", eth.getMACAddress()); |
mbed2015 | 7:48019055e3a3 | 52 | |
mbed2015 | 7:48019055e3a3 | 53 | // ip_addr_t primaryDnsServer; |
mbed2015 | 7:48019055e3a3 | 54 | // ip4_addr_set_u32(&primaryDnsServer, ipaddr_addr("202.18.66.8")); |
mbed2015 | 7:48019055e3a3 | 55 | // dns_setserver(0, &primaryDnsServer); |
ban4jp | 6:f5189d4f109f | 56 | |
ban4jp | 6:f5189d4f109f | 57 | int ret; |
ban4jp | 6:f5189d4f109f | 58 | while ((ret = eth.connect()) != 0) { |
ban4jp | 6:f5189d4f109f | 59 | printf("Error eth.connect() - ret = %d\n", ret); |
geodenx | 0:00a2d3570824 | 60 | } |
geodenx | 0:00a2d3570824 | 61 | |
ban4jp | 6:f5189d4f109f | 62 | printf("Connected, IP: %s, MASK: %s, GW: %s\n", |
ban4jp | 6:f5189d4f109f | 63 | eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
ban4jp | 6:f5189d4f109f | 64 | |
ban4jp | 6:f5189d4f109f | 65 | // requires accurate time, for OAuth Authorization. |
ban4jp | 6:f5189d4f109f | 66 | updateTime(); |
ban4jp | 6:f5189d4f109f | 67 | |
ban4jp | 6:f5189d4f109f | 68 | |
mbed2015 | 7:48019055e3a3 | 69 | // example_getUserData(); |
mbed2015 | 7:48019055e3a3 | 70 | // printf("\n"); |
mbed2015 | 7:48019055e3a3 | 71 | |
mbed2015 | 7:48019055e3a3 | 72 | myled = 0; |
mbed2015 | 7:48019055e3a3 | 73 | time_t ctTime; |
mbed2015 | 7:48019055e3a3 | 74 | struct tm* lTime; |
mbed2015 | 7:48019055e3a3 | 75 | int hour; |
mbed2015 | 7:48019055e3a3 | 76 | int countmin = 0; |
ban4jp | 6:f5189d4f109f | 77 | |
mbed2015 | 7:48019055e3a3 | 78 | |
mbed2015 | 7:48019055e3a3 | 79 | /*tickerオブジェクトで0.1秒ごとにmm2関数を呼び出す*/ |
mbed2015 | 7:48019055e3a3 | 80 | mmTicker.attach(&mm2, 0.5); |
ban4jp | 6:f5189d4f109f | 81 | |
mbed2015 | 7:48019055e3a3 | 82 | while (1) { |
mbed2015 | 7:48019055e3a3 | 83 | time(&ctTime); |
mbed2015 | 7:48019055e3a3 | 84 | lTime = localtime(&ctTime); |
mbed2015 | 7:48019055e3a3 | 85 | hour = lTime->tm_hour; |
mbed2015 | 7:48019055e3a3 | 86 | countmin = 5; |
mbed2015 | 7:48019055e3a3 | 87 | if (12<=hour&&hour<=13) { |
mbed2015 | 7:48019055e3a3 | 88 | countmin=15; |
mbed2015 | 7:48019055e3a3 | 89 | } |
mbed2015 | 7:48019055e3a3 | 90 | |
mbed2015 | 7:48019055e3a3 | 91 | |
mbed2015 | 7:48019055e3a3 | 92 | // Wait 60*5 seconds for next time. |
mbed2015 | 7:48019055e3a3 | 93 | for (int t=0; t<60*countmin; t++) { |
mbed2015 | 7:48019055e3a3 | 94 | myled = !myled; |
mbed2015 | 7:48019055e3a3 | 95 | wait_ms(1000); |
mbed2015 | 7:48019055e3a3 | 96 | printf("%d\n", sum); |
mbed2015 | 7:48019055e3a3 | 97 | //time(&ctTime); |
mbed2015 | 7:48019055e3a3 | 98 | //lTime = localtime(&ctTime); |
mbed2015 | 7:48019055e3a3 | 99 | //hour = lTime->tm_hour; |
mbed2015 | 7:48019055e3a3 | 100 | //if (12<=hour&&hour<=13) break; |
ban4jp | 6:f5189d4f109f | 101 | } |
mbed2015 | 7:48019055e3a3 | 102 | example_tweet2(); |
ban4jp | 1:4dfa9d41f414 | 103 | } |
mbed2015 | 7:48019055e3a3 | 104 | // mmTicker.detach(); |
ban4jp | 6:f5189d4f109f | 105 | } |
ban4jp | 1:4dfa9d41f414 | 106 | |
ban4jp | 4:fcadeb9bdcbd | 107 | |
ban4jp | 6:f5189d4f109f | 108 | void updateTime() |
ban4jp | 6:f5189d4f109f | 109 | { |
ban4jp | 1:4dfa9d41f414 | 110 | printf("Trying to update time...\n"); |
ban4jp | 1:4dfa9d41f414 | 111 | |
ban4jp | 2:392b8e079c7a | 112 | time_t ctTime; |
ban4jp | 2:392b8e079c7a | 113 | NTPResult result; |
ban4jp | 2:392b8e079c7a | 114 | |
ban4jp | 4:fcadeb9bdcbd | 115 | while (1) { |
mbed2015 | 7:48019055e3a3 | 116 | result = ntp.setTime("ntp.nict.jp"); |
ban4jp | 2:392b8e079c7a | 117 | |
ban4jp | 2:392b8e079c7a | 118 | if (result == NTP_OK) { |
ban4jp | 2:392b8e079c7a | 119 | time(&ctTime); |
ban4jp | 2:392b8e079c7a | 120 | printf("Time is set to (UTC): %s\n", ctime(&ctTime)); |
ban4jp | 2:392b8e079c7a | 121 | break; |
ban4jp | 2:392b8e079c7a | 122 | } |
ban4jp | 2:392b8e079c7a | 123 | |
ban4jp | 2:392b8e079c7a | 124 | switch (result) { |
ban4jp | 2:392b8e079c7a | 125 | case NTP_CONN: ///<Connection error |
ban4jp | 2:392b8e079c7a | 126 | printf("Connection error\n"); |
ban4jp | 2:392b8e079c7a | 127 | break; |
ban4jp | 2:392b8e079c7a | 128 | case NTP_TIMEOUT: ///<Connection timeout |
ban4jp | 2:392b8e079c7a | 129 | printf("Connection timeout\n"); |
ban4jp | 2:392b8e079c7a | 130 | break; |
ban4jp | 2:392b8e079c7a | 131 | case NTP_PRTCL: ///<Protocol error |
ban4jp | 2:392b8e079c7a | 132 | printf("Protocol error\n"); |
ban4jp | 2:392b8e079c7a | 133 | break; |
ban4jp | 2:392b8e079c7a | 134 | case NTP_DNS: ///<Could not resolve name |
ban4jp | 2:392b8e079c7a | 135 | printf("Could not resolve name\n"); |
ban4jp | 2:392b8e079c7a | 136 | break; |
ban4jp | 2:392b8e079c7a | 137 | default: |
ban4jp | 2:392b8e079c7a | 138 | printf("Error result=%d\n", result); |
ban4jp | 6:f5189d4f109f | 139 | break; |
ban4jp | 2:392b8e079c7a | 140 | } |
ban4jp | 2:392b8e079c7a | 141 | |
ban4jp | 2:392b8e079c7a | 142 | wait(5); |
ban4jp | 1:4dfa9d41f414 | 143 | } |
ban4jp | 6:f5189d4f109f | 144 | } |
ban4jp | 1:4dfa9d41f414 | 145 | |
ban4jp | 4:fcadeb9bdcbd | 146 | |
mbed2015 | 7:48019055e3a3 | 147 | |
mbed2015 | 7:48019055e3a3 | 148 | /*センサ安定時間*/ |
mbed2015 | 7:48019055e3a3 | 149 | #define INIT 30.0 |
mbed2015 | 7:48019055e3a3 | 150 | /*ノイズ検出用*/ |
mbed2015 | 7:48019055e3a3 | 151 | #define NOISE 0.1 |
mbed2015 | 7:48019055e3a3 | 152 | /*センサ再読み取り時間*/ |
mbed2015 | 7:48019055e3a3 | 153 | #define DELAY 0.05 |
mbed2015 | 7:48019055e3a3 | 154 | |
mbed2015 | 7:48019055e3a3 | 155 | DigitalIn pA(p19); |
mbed2015 | 7:48019055e3a3 | 156 | DigitalIn pB(p20); |
mbed2015 | 7:48019055e3a3 | 157 | DigitalOut led2(LED2); |
mbed2015 | 7:48019055e3a3 | 158 | |
mbed2015 | 7:48019055e3a3 | 159 | void mm2(void) |
mbed2015 | 7:48019055e3a3 | 160 | { |
mbed2015 | 7:48019055e3a3 | 161 | int nA = pA; |
mbed2015 | 7:48019055e3a3 | 162 | int nB = pB; |
mbed2015 | 7:48019055e3a3 | 163 | static int prevA = 0; |
mbed2015 | 7:48019055e3a3 | 164 | static int prevB = 0; |
mbed2015 | 7:48019055e3a3 | 165 | |
mbed2015 | 7:48019055e3a3 | 166 | int status = 0; |
mbed2015 | 7:48019055e3a3 | 167 | static int prevUpStatus = 0; |
mbed2015 | 7:48019055e3a3 | 168 | |
mbed2015 | 7:48019055e3a3 | 169 | if (prevA == nA) |
mbed2015 | 7:48019055e3a3 | 170 | status = nA; |
mbed2015 | 7:48019055e3a3 | 171 | if (prevB == nB) |
mbed2015 | 7:48019055e3a3 | 172 | status |= (nB << 1); |
mbed2015 | 7:48019055e3a3 | 173 | if (prevUpStatus == 0x03) { |
mbed2015 | 7:48019055e3a3 | 174 | if (status == 0x02) |
mbed2015 | 7:48019055e3a3 | 175 | sum++; |
mbed2015 | 7:48019055e3a3 | 176 | else if (status == 0x01) |
mbed2015 | 7:48019055e3a3 | 177 | sum--; |
mbed2015 | 7:48019055e3a3 | 178 | } |
mbed2015 | 7:48019055e3a3 | 179 | |
mbed2015 | 7:48019055e3a3 | 180 | prevA = nA; |
mbed2015 | 7:48019055e3a3 | 181 | prevB = nB; |
mbed2015 | 7:48019055e3a3 | 182 | |
mbed2015 | 7:48019055e3a3 | 183 | if (status) |
mbed2015 | 7:48019055e3a3 | 184 | prevUpStatus = status; |
mbed2015 | 7:48019055e3a3 | 185 | } |
mbed2015 | 7:48019055e3a3 | 186 | |
mbed2015 | 7:48019055e3a3 | 187 | |
mbed2015 | 7:48019055e3a3 | 188 | void mm(void) { |
mbed2015 | 7:48019055e3a3 | 189 | int a = 0; |
mbed2015 | 7:48019055e3a3 | 190 | int b = 0; |
mbed2015 | 7:48019055e3a3 | 191 | int c = 0; |
mbed2015 | 7:48019055e3a3 | 192 | int d = 0; |
mbed2015 | 7:48019055e3a3 | 193 | int plus = 0; |
mbed2015 | 7:48019055e3a3 | 194 | int minus = 0; |
mbed2015 | 7:48019055e3a3 | 195 | led2 = 0; |
mbed2015 | 7:48019055e3a3 | 196 | |
mbed2015 | 7:48019055e3a3 | 197 | // pc.printf("a=%d b=%d c=%d d=%d\n",a,b,c,d); |
mbed2015 | 7:48019055e3a3 | 198 | |
mbed2015 | 7:48019055e3a3 | 199 | if(pA){ |
mbed2015 | 7:48019055e3a3 | 200 | wait(NOISE); |
mbed2015 | 7:48019055e3a3 | 201 | if(pA){ |
mbed2015 | 7:48019055e3a3 | 202 | a ++; |
mbed2015 | 7:48019055e3a3 | 203 | // pc.printf("a=%d\n",a); |
mbed2015 | 7:48019055e3a3 | 204 | wait(DELAY); |
mbed2015 | 7:48019055e3a3 | 205 | if(pB){ |
mbed2015 | 7:48019055e3a3 | 206 | wait(NOISE); |
mbed2015 | 7:48019055e3a3 | 207 | if(pB){ |
mbed2015 | 7:48019055e3a3 | 208 | b ++; |
mbed2015 | 7:48019055e3a3 | 209 | // pc.printf("b=%d\n",b); |
mbed2015 | 7:48019055e3a3 | 210 | wait(DELAY); |
mbed2015 | 7:48019055e3a3 | 211 | plus ++; |
mbed2015 | 7:48019055e3a3 | 212 | // pc.printf("plus=%d\n",plus); |
mbed2015 | 7:48019055e3a3 | 213 | } |
mbed2015 | 7:48019055e3a3 | 214 | } |
mbed2015 | 7:48019055e3a3 | 215 | } |
mbed2015 | 7:48019055e3a3 | 216 | wait(DELAY); |
mbed2015 | 7:48019055e3a3 | 217 | } |
mbed2015 | 7:48019055e3a3 | 218 | |
mbed2015 | 7:48019055e3a3 | 219 | if(pB){ |
mbed2015 | 7:48019055e3a3 | 220 | wait(NOISE); |
mbed2015 | 7:48019055e3a3 | 221 | if(pB){ |
mbed2015 | 7:48019055e3a3 | 222 | c ++; |
mbed2015 | 7:48019055e3a3 | 223 | // pc.printf("c=%d\n",c); |
mbed2015 | 7:48019055e3a3 | 224 | wait(DELAY); |
mbed2015 | 7:48019055e3a3 | 225 | if(pA){ |
mbed2015 | 7:48019055e3a3 | 226 | wait(NOISE); |
mbed2015 | 7:48019055e3a3 | 227 | if(pA){ |
mbed2015 | 7:48019055e3a3 | 228 | d ++; |
mbed2015 | 7:48019055e3a3 | 229 | // pc.printf("d=%d\n",d); |
mbed2015 | 7:48019055e3a3 | 230 | wait(DELAY); |
mbed2015 | 7:48019055e3a3 | 231 | minus ++; |
mbed2015 | 7:48019055e3a3 | 232 | // pc.printf("minus=%d\n",minus); |
mbed2015 | 7:48019055e3a3 | 233 | |
mbed2015 | 7:48019055e3a3 | 234 | } |
mbed2015 | 7:48019055e3a3 | 235 | } |
mbed2015 | 7:48019055e3a3 | 236 | } |
mbed2015 | 7:48019055e3a3 | 237 | wait(DELAY); |
mbed2015 | 7:48019055e3a3 | 238 | } |
mbed2015 | 7:48019055e3a3 | 239 | sum = plus - minus ; |
mbed2015 | 7:48019055e3a3 | 240 | // pc.printf("sum=%d\n",sum); |
mbed2015 | 7:48019055e3a3 | 241 | } |
mbed2015 | 7:48019055e3a3 | 242 | |
ban4jp | 6:f5189d4f109f | 243 | void example_tweet1() |
ban4jp | 6:f5189d4f109f | 244 | { |
mbed2015 | 7:48019055e3a3 | 245 | const char url[] = "https://api.twitter.com/1.1/statuses/update.json?status=Hello Everybody! Now, the number of people in the co-op - %s"; |
ban4jp | 6:f5189d4f109f | 246 | char url2[128]; |
geodenx | 0:00a2d3570824 | 247 | |
mbed2015 | 7:48019055e3a3 | 248 | |
ban4jp | 6:f5189d4f109f | 249 | time_t ctTime; |
mbed2015 | 7:48019055e3a3 | 250 | |
ban4jp | 6:f5189d4f109f | 251 | time(&ctTime); |
ban4jp | 4:fcadeb9bdcbd | 252 | |
ban4jp | 6:f5189d4f109f | 253 | snprintf(url2, sizeof(url2), url, ctime(&ctTime)); |
ban4jp | 6:f5189d4f109f | 254 | |
ban4jp | 6:f5189d4f109f | 255 | HTTPResult result = oa4t.post(url2, &response); |
ban4jp | 5:f0c0128cde62 | 256 | |
ban4jp | 6:f5189d4f109f | 257 | if (result == HTTP_OK) { |
ban4jp | 6:f5189d4f109f | 258 | printf("POST success.\n%s\n", response_buffer); |
ban4jp | 6:f5189d4f109f | 259 | } else { |
ban4jp | 6:f5189d4f109f | 260 | printf("POST error. (result = %d)\n", result); |
ban4jp | 6:f5189d4f109f | 261 | } |
ban4jp | 6:f5189d4f109f | 262 | } |
ban4jp | 5:f0c0128cde62 | 263 | |
mbed2015 | 7:48019055e3a3 | 264 | void example_tweet2(void) |
ban4jp | 6:f5189d4f109f | 265 | { |
ban4jp | 6:f5189d4f109f | 266 | const char url[] = "https://api.twitter.com/1.1/statuses/update.json"; |
mbed2015 | 7:48019055e3a3 | 267 | wait(INIT); |
ban4jp | 6:f5189d4f109f | 268 | std::vector<std::string> post; |
ban4jp | 6:f5189d4f109f | 269 | post.reserve(1); |
ban4jp | 6:f5189d4f109f | 270 | |
ban4jp | 6:f5189d4f109f | 271 | char status[128]; |
ban4jp | 4:fcadeb9bdcbd | 272 | |
ban4jp | 6:f5189d4f109f | 273 | time_t ctTime; |
ban4jp | 6:f5189d4f109f | 274 | time(&ctTime); |
mbed2015 | 7:48019055e3a3 | 275 | |
mbed2015 | 7:48019055e3a3 | 276 | snprintf(status, sizeof(status), "status=Hello Everybody! Now, the number of people in the co-op - %d %s",sum, ctime(&ctTime)); |
ban4jp | 6:f5189d4f109f | 277 | post.push_back(status); |
ban4jp | 4:fcadeb9bdcbd | 278 | |
ban4jp | 6:f5189d4f109f | 279 | HTTPResult result = oa4t.post(url, &post, &response); |
ban4jp | 4:fcadeb9bdcbd | 280 | |
ban4jp | 6:f5189d4f109f | 281 | if (result == HTTP_OK) { |
ban4jp | 6:f5189d4f109f | 282 | printf("POST success.\n%s\n", response_buffer); |
ban4jp | 6:f5189d4f109f | 283 | } else { |
ban4jp | 6:f5189d4f109f | 284 | printf("POST error. (result = %d)\n", result); |
geodenx | 0:00a2d3570824 | 285 | } |
geodenx | 0:00a2d3570824 | 286 | } |
mbed2015 | 7:48019055e3a3 | 287 | /* |
ban4jp | 6:f5189d4f109f | 288 | void example_tweet3() |
ban4jp | 6:f5189d4f109f | 289 | { |
ban4jp | 6:f5189d4f109f | 290 | const char url[] = "https://api.twitter.com/1.1/statuses/update.json"; |
ban4jp | 6:f5189d4f109f | 291 | |
ban4jp | 6:f5189d4f109f | 292 | std::vector<std::string> post; |
ban4jp | 6:f5189d4f109f | 293 | post.reserve(3); |
ban4jp | 6:f5189d4f109f | 294 | |
ban4jp | 6:f5189d4f109f | 295 | struct tm tmptr; |
ban4jp | 6:f5189d4f109f | 296 | char tmstr[34]; |
ban4jp | 6:f5189d4f109f | 297 | char status[128]; |
ban4jp | 6:f5189d4f109f | 298 | char location_lat[24]; |
ban4jp | 6:f5189d4f109f | 299 | char location_long[24]; |
ban4jp | 6:f5189d4f109f | 300 | |
ban4jp | 6:f5189d4f109f | 301 | time_t ctTime; |
ban4jp | 6:f5189d4f109f | 302 | time(&ctTime); |
ban4jp | 6:f5189d4f109f | 303 | ctTime += 9 * 60 * 60; // Timezone: JST(+9h) |
ban4jp | 6:f5189d4f109f | 304 | localtime_r(&ctTime, &tmptr); |
ban4jp | 6:f5189d4f109f | 305 | |
ban4jp | 6:f5189d4f109f | 306 | // Tweets in Japanese |
ban4jp | 6:f5189d4f109f | 307 | strftime(tmstr, sizeof(tmstr), "%Y年%m月%d日 %H時%M分%S秒", &tmptr); |
ban4jp | 6:f5189d4f109f | 308 | snprintf(status, sizeof(status), "status=ハロー・ワールド! - %s", tmstr); |
ban4jp | 6:f5189d4f109f | 309 | post.push_back(status); |
ban4jp | 6:f5189d4f109f | 310 | |
ban4jp | 6:f5189d4f109f | 311 | // Option: add Location information |
ban4jp | 6:f5189d4f109f | 312 | snprintf(location_lat, sizeof(location_lat), "lat=%f", 35.359577); |
ban4jp | 6:f5189d4f109f | 313 | snprintf(location_long, sizeof(location_long), "long=%f", 138.731414); |
ban4jp | 6:f5189d4f109f | 314 | post.push_back(location_lat); |
ban4jp | 6:f5189d4f109f | 315 | post.push_back(location_long); |
ban4jp | 6:f5189d4f109f | 316 | |
ban4jp | 6:f5189d4f109f | 317 | HTTPResult result = oa4t.post(url, &post, &response); |
ban4jp | 6:f5189d4f109f | 318 | |
ban4jp | 6:f5189d4f109f | 319 | if (result == HTTP_OK) { |
ban4jp | 6:f5189d4f109f | 320 | printf("POST success.\n%s\n", response_buffer); |
ban4jp | 6:f5189d4f109f | 321 | } else { |
ban4jp | 6:f5189d4f109f | 322 | printf("POST error. (result = %d)\n", result); |
ban4jp | 6:f5189d4f109f | 323 | } |
ban4jp | 6:f5189d4f109f | 324 | } |
mbed2015 | 7:48019055e3a3 | 325 | */ |
ban4jp | 6:f5189d4f109f | 326 | |
ban4jp | 6:f5189d4f109f | 327 | void example_getUserData() |
ban4jp | 6:f5189d4f109f | 328 | { |
ban4jp | 6:f5189d4f109f | 329 | const char url[] = "https://api.twitter.com/1.1/users/show.json" |
ban4jp | 6:f5189d4f109f | 330 | "?screen_name=twitter"; |
ban4jp | 6:f5189d4f109f | 331 | |
ban4jp | 6:f5189d4f109f | 332 | HTTPResult result = oa4t.get(url, &response); |
ban4jp | 6:f5189d4f109f | 333 | |
ban4jp | 6:f5189d4f109f | 334 | if (result == HTTP_OK) { |
ban4jp | 6:f5189d4f109f | 335 | printf("GET success.\n%s\n", response_buffer); |
ban4jp | 6:f5189d4f109f | 336 | } else { |
ban4jp | 6:f5189d4f109f | 337 | printf("GET error. (result = %d)\n", result); |
ban4jp | 6:f5189d4f109f | 338 | } |
ban4jp | 6:f5189d4f109f | 339 | } |