cc3000 twitter demo, uses supertweet services. Set your account there and then fill a user and a secret inside the demo.
Dependencies: HTTPClient NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed
Uses http://www.supertweet.net/, please register there and fill user and secret inside the application.
main.cpp@4:450623485778, 2014-06-03 (annotated)
- Committer:
- Kojto
- Date:
- Tue Jun 03 09:30:35 2014 +0000
- Revision:
- 4:450623485778
- Parent:
- 3:1fbe23ea24c1
update mbed lib to r84
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Kojto | 0:5aa9273cb749 | 1 | /* mbed Microcontroller Library |
| Kojto | 0:5aa9273cb749 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| Kojto | 0:5aa9273cb749 | 3 | * |
| Kojto | 0:5aa9273cb749 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| Kojto | 0:5aa9273cb749 | 5 | * you may not use this file except in compliance with the License. |
| Kojto | 0:5aa9273cb749 | 6 | * You may obtain a copy of the License at |
| Kojto | 0:5aa9273cb749 | 7 | * |
| Kojto | 0:5aa9273cb749 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Kojto | 0:5aa9273cb749 | 9 | * |
| Kojto | 0:5aa9273cb749 | 10 | * Unless required by applicable law or agreed to in writing, software |
| Kojto | 0:5aa9273cb749 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| Kojto | 0:5aa9273cb749 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| Kojto | 0:5aa9273cb749 | 13 | * See the License for the specific language governing permissions and |
| Kojto | 0:5aa9273cb749 | 14 | * limitations under the License. |
| Kojto | 0:5aa9273cb749 | 15 | */ |
| Kojto | 0:5aa9273cb749 | 16 | #include "mbed.h" |
| Kojto | 0:5aa9273cb749 | 17 | #include "cc3000.h" |
| Kojto | 0:5aa9273cb749 | 18 | #include "main.h" |
| Kojto | 0:5aa9273cb749 | 19 | #include "HTTPClient.h" |
| Kojto | 0:5aa9273cb749 | 20 | |
| Kojto | 0:5aa9273cb749 | 21 | using namespace mbed_cc3000; |
| Kojto | 0:5aa9273cb749 | 22 | |
| Kojto | 0:5aa9273cb749 | 23 | /* cc3000 module declaration specific for user's board. Check also init() */ |
| Kojto | 0:5aa9273cb749 | 24 | #if (MY_BOARD == WIGO) |
| Kojto | 3:1fbe23ea24c1 | 25 | cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false); |
| Kojto | 0:5aa9273cb749 | 26 | Serial pc(USBTX, USBRX); |
| Kojto | 0:5aa9273cb749 | 27 | #elif (MY_BOARD == WIFI_DIPCORTEX) |
| Kojto | 3:1fbe23ea24c1 | 28 | cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false); |
| Kojto | 0:5aa9273cb749 | 29 | Serial pc(UART_TX, UART_RX); |
| Kojto | 3:1fbe23ea24c1 | 30 | #elif (MY_BOARD == MBED_BOARD_EXAMPLE) |
| Kojto | 3:1fbe23ea24c1 | 31 | cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false); |
| Kojto | 3:1fbe23ea24c1 | 32 | Serial pc(USBTX, USBRX); |
| Kojto | 0:5aa9273cb749 | 33 | #else |
| Kojto | 0:5aa9273cb749 | 34 | |
| Kojto | 0:5aa9273cb749 | 35 | #endif |
| Kojto | 0:5aa9273cb749 | 36 | |
| Kojto | 0:5aa9273cb749 | 37 | HTTPClient twitter; |
| Kojto | 0:5aa9273cb749 | 38 | char str[512]; |
| Kojto | 0:5aa9273cb749 | 39 | |
| Kojto | 0:5aa9273cb749 | 40 | /** |
| Kojto | 1:f35cc7e300f7 | 41 | * \brief Twitter demo |
| Kojto | 0:5aa9273cb749 | 42 | * \param none |
| Kojto | 0:5aa9273cb749 | 43 | * \return int |
| Kojto | 0:5aa9273cb749 | 44 | */ |
| Kojto | 0:5aa9273cb749 | 45 | int main() { |
| Kojto | 0:5aa9273cb749 | 46 | init(); /* board dependent init */ |
| Kojto | 0:5aa9273cb749 | 47 | pc.baud(115200); |
| Kojto | 0:5aa9273cb749 | 48 | |
| Kojto | 1:f35cc7e300f7 | 49 | printf("cc3000 twitter demo. \r\n"); |
| Kojto | 3:1fbe23ea24c1 | 50 | wifi.init(); |
| Kojto | 3:1fbe23ea24c1 | 51 | if (wifi.connect() == -1) { |
| Kojto | 3:1fbe23ea24c1 | 52 | printf("Failed to connect. Please verify connection details and try again. \r\n"); |
| Kojto | 0:5aa9273cb749 | 53 | } else { |
| Kojto | 3:1fbe23ea24c1 | 54 | printf("IP address: %s \r\n", wifi.getIPAddress()); |
| Kojto | 0:5aa9273cb749 | 55 | } |
| Kojto | 3:1fbe23ea24c1 | 56 | |
| Kojto | 0:5aa9273cb749 | 57 | //POST data |
| Kojto | 0:5aa9273cb749 | 58 | HTTPMap map; |
| Kojto | 0:5aa9273cb749 | 59 | HTTPText inText(str, 512); |
| Kojto | 0:5aa9273cb749 | 60 | map.put("status", "I am tweeting from mbed with cc3000."); |
| Kojto | 1:f35cc7e300f7 | 61 | |
| Kojto | 1:f35cc7e300f7 | 62 | printf("\r\nTrying to post data...\r\n"); |
| Kojto | 0:5aa9273cb749 | 63 | twitter.basicAuth("username", "secret"); //We use basic authentication, replace with you account's parameters |
| Kojto | 0:5aa9273cb749 | 64 | int ret = twitter.post("http://api.supertweet.net/1.1/statuses/update.json", map, &inText); |
| Kojto | 0:5aa9273cb749 | 65 | if (!ret) |
| Kojto | 0:5aa9273cb749 | 66 | { |
| Kojto | 1:f35cc7e300f7 | 67 | printf("Executed POST successfully - read %d characters\r\n", strlen(str)); |
| Kojto | 1:f35cc7e300f7 | 68 | printf("Result: %s \r\n", str); |
| Kojto | 0:5aa9273cb749 | 69 | } |
| Kojto | 0:5aa9273cb749 | 70 | else |
| Kojto | 0:5aa9273cb749 | 71 | { |
| Kojto | 1:f35cc7e300f7 | 72 | printf("Error - ret = %d - HTTP return code = %d \r\n", ret, twitter.getHTTPResponseCode()); |
| Kojto | 0:5aa9273cb749 | 73 | } |
| Kojto | 1:f35cc7e300f7 | 74 | |
| Kojto | 1:f35cc7e300f7 | 75 | printf("Twitter demo completed.\r\n"); |
| Kojto | 0:5aa9273cb749 | 76 | } |