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: HTTPClient NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "mbed.h" 00017 #include "cc3000.h" 00018 #include "main.h" 00019 #include "HTTPClient.h" 00020 00021 using namespace mbed_cc3000; 00022 00023 /* cc3000 module declaration specific for user's board. Check also init() */ 00024 #if (MY_BOARD == WIGO) 00025 cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false); 00026 Serial pc(USBTX, USBRX); 00027 #elif (MY_BOARD == WIFI_DIPCORTEX) 00028 cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false); 00029 Serial pc(UART_TX, UART_RX); 00030 #elif (MY_BOARD == MBED_BOARD_EXAMPLE) 00031 cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false); 00032 Serial pc(USBTX, USBRX); 00033 #else 00034 00035 #endif 00036 00037 HTTPClient twitter; 00038 char str[512]; 00039 00040 /** 00041 * \brief Twitter demo 00042 * \param none 00043 * \return int 00044 */ 00045 int main() { 00046 init(); /* board dependent init */ 00047 pc.baud(115200); 00048 00049 printf("cc3000 twitter demo. \r\n"); 00050 wifi.init(); 00051 if (wifi.connect() == -1) { 00052 printf("Failed to connect. Please verify connection details and try again. \r\n"); 00053 } else { 00054 printf("IP address: %s \r\n", wifi.getIPAddress()); 00055 } 00056 00057 //POST data 00058 HTTPMap map; 00059 HTTPText inText(str, 512); 00060 map.put("status", "I am tweeting from mbed with cc3000."); 00061 00062 printf("\r\nTrying to post data...\r\n"); 00063 twitter.basicAuth("username", "secret"); //We use basic authentication, replace with you account's parameters 00064 int ret = twitter.post("http://api.supertweet.net/1.1/statuses/update.json", map, &inText); 00065 if (!ret) 00066 { 00067 printf("Executed POST successfully - read %d characters\r\n", strlen(str)); 00068 printf("Result: %s \r\n", str); 00069 } 00070 else 00071 { 00072 printf("Error - ret = %d - HTTP return code = %d \r\n", ret, twitter.getHTTPResponseCode()); 00073 } 00074 00075 printf("Twitter demo completed.\r\n"); 00076 }
Generated on Sat Jul 16 2022 01:56:19 by
1.7.2