* switch from mbed to mbed-src, which works better with my board * list APs and their RSSI * read CC3000 firmware version
Dependencies: cc3000_hostdriver_mbedsocket mbed-src
Fork of cc3000_hello_world_demo_sparkfun by
main.cpp@0:db8738fc21e8, 2013-10-06 (annotated)
- Committer:
- Kojto
- Date:
- Sun Oct 06 16:29:29 2013 +0000
- Revision:
- 0:db8738fc21e8
- Child:
- 1:c3a27e2adf93
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 0:db8738fc21e8 | 1 | /* mbed Microcontroller Library |
Kojto | 0:db8738fc21e8 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Kojto | 0:db8738fc21e8 | 3 | * |
Kojto | 0:db8738fc21e8 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Kojto | 0:db8738fc21e8 | 5 | * you may not use this file except in compliance with the License. |
Kojto | 0:db8738fc21e8 | 6 | * You may obtain a copy of the License at |
Kojto | 0:db8738fc21e8 | 7 | * |
Kojto | 0:db8738fc21e8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Kojto | 0:db8738fc21e8 | 9 | * |
Kojto | 0:db8738fc21e8 | 10 | * Unless required by applicable law or agreed to in writing, software |
Kojto | 0:db8738fc21e8 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Kojto | 0:db8738fc21e8 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Kojto | 0:db8738fc21e8 | 13 | * See the License for the specific language governing permissions and |
Kojto | 0:db8738fc21e8 | 14 | * limitations under the License. |
Kojto | 0:db8738fc21e8 | 15 | */ |
Kojto | 0:db8738fc21e8 | 16 | #include "mbed.h" |
Kojto | 0:db8738fc21e8 | 17 | #include "cc3000.h" |
Kojto | 0:db8738fc21e8 | 18 | #include "main.h" |
Kojto | 0:db8738fc21e8 | 19 | |
Kojto | 0:db8738fc21e8 | 20 | using namespace mbed_cc3000; |
Kojto | 0:db8738fc21e8 | 21 | |
Kojto | 0:db8738fc21e8 | 22 | tUserFS user_info; |
Kojto | 0:db8738fc21e8 | 23 | |
Kojto | 0:db8738fc21e8 | 24 | /* cc3000 module declaration specific for user's board. Check also init() */ |
Kojto | 0:db8738fc21e8 | 25 | #if (MY_BOARD == WIGO) |
Kojto | 0:db8738fc21e8 | 26 | cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), PORTA_IRQn); |
Kojto | 0:db8738fc21e8 | 27 | Serial pc(USBTX, USBRX); |
Kojto | 0:db8738fc21e8 | 28 | #elif (MY_BOARD == WIFI_DIPCORTEX) |
Kojto | 0:db8738fc21e8 | 29 | cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), PIN_INT0_IRQn); |
Kojto | 0:db8738fc21e8 | 30 | Serial pc(UART_TX, UART_RX); |
Kojto | 0:db8738fc21e8 | 31 | #else |
Kojto | 0:db8738fc21e8 | 32 | |
Kojto | 0:db8738fc21e8 | 33 | #endif |
Kojto | 0:db8738fc21e8 | 34 | |
Kojto | 0:db8738fc21e8 | 35 | /** |
Kojto | 0:db8738fc21e8 | 36 | * \brief Print cc3000 information |
Kojto | 0:db8738fc21e8 | 37 | * \param none |
Kojto | 0:db8738fc21e8 | 38 | * \return none |
Kojto | 0:db8738fc21e8 | 39 | */ |
Kojto | 0:db8738fc21e8 | 40 | void print_cc3000_info() { |
Kojto | 0:db8738fc21e8 | 41 | uint8_t myMAC[8]; |
Kojto | 0:db8738fc21e8 | 42 | |
Kojto | 0:db8738fc21e8 | 43 | printf("MAC address + cc3000 info \r\n"); |
Kojto | 0:db8738fc21e8 | 44 | wifi.get_user_file_info((uint8_t *)&user_info, sizeof(user_info)); |
Kojto | 0:db8738fc21e8 | 45 | wifi.get_mac_address(myMAC); |
Kojto | 0:db8738fc21e8 | 46 | printf(" MAC address %02x:%02x:%02x:%02x:%02x:%02x \r\n \r\n", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]); |
Kojto | 0:db8738fc21e8 | 47 | |
Kojto | 0:db8738fc21e8 | 48 | printf(" FTC %i \r\n",user_info.FTC); |
Kojto | 0:db8738fc21e8 | 49 | printf(" PP_version %i.%i \r\n",user_info.PP_version[0], user_info.PP_version[1]); |
Kojto | 0:db8738fc21e8 | 50 | printf(" SERV_PACK %i.%i \r\n",user_info.SERV_PACK[0], user_info.SERV_PACK[1]); |
Kojto | 0:db8738fc21e8 | 51 | printf(" DRV_VER %i.%i.%i \r\n",user_info.DRV_VER[0], user_info.DRV_VER[1], user_info.DRV_VER[2]); |
Kojto | 0:db8738fc21e8 | 52 | printf(" FW_VER %i.%i.%i \r\n",user_info.FW_VER[0], user_info.FW_VER[1], user_info.FW_VER[2]); |
Kojto | 0:db8738fc21e8 | 53 | } |
Kojto | 0:db8738fc21e8 | 54 | |
Kojto | 0:db8738fc21e8 | 55 | /** |
Kojto | 0:db8738fc21e8 | 56 | * \brief Connect to SSID with a timeout |
Kojto | 0:db8738fc21e8 | 57 | * \param ssid Name of SSID |
Kojto | 0:db8738fc21e8 | 58 | * \param key Password |
Kojto | 0:db8738fc21e8 | 59 | * \param sec_mode Security mode |
Kojto | 0:db8738fc21e8 | 60 | * \return none |
Kojto | 0:db8738fc21e8 | 61 | */ |
Kojto | 0:db8738fc21e8 | 62 | void connect_to_ssid(char *ssid, char *key, unsigned char sec_mode) { |
Kojto | 0:db8738fc21e8 | 63 | printf("Connecting to SSID: %s. Timeout is 10s.\n",ssid); |
Kojto | 0:db8738fc21e8 | 64 | if (wifi.connect_to_AP((uint8_t *)ssid, (uint8_t *)key, sec_mode) == true) { |
Kojto | 0:db8738fc21e8 | 65 | printf(" Connected\n"); |
Kojto | 0:db8738fc21e8 | 66 | } else { |
Kojto | 0:db8738fc21e8 | 67 | printf(" Connection timed-out (error). Please restart.\n"); |
Kojto | 0:db8738fc21e8 | 68 | while(1); |
Kojto | 0:db8738fc21e8 | 69 | } |
Kojto | 0:db8738fc21e8 | 70 | } |
Kojto | 0:db8738fc21e8 | 71 | |
Kojto | 0:db8738fc21e8 | 72 | /** |
Kojto | 0:db8738fc21e8 | 73 | * \brief Connect to SSID without security |
Kojto | 0:db8738fc21e8 | 74 | * \param ssid Name of SSID |
Kojto | 0:db8738fc21e8 | 75 | * \return none |
Kojto | 0:db8738fc21e8 | 76 | */ |
Kojto | 0:db8738fc21e8 | 77 | void connect_to_ssid(char *ssid) { |
Kojto | 0:db8738fc21e8 | 78 | wifi.connect_open((uint8_t *)ssid); |
Kojto | 0:db8738fc21e8 | 79 | } |
Kojto | 0:db8738fc21e8 | 80 | |
Kojto | 0:db8738fc21e8 | 81 | |
Kojto | 0:db8738fc21e8 | 82 | /** |
Kojto | 0:db8738fc21e8 | 83 | * \brief Hello World |
Kojto | 0:db8738fc21e8 | 84 | * \param none |
Kojto | 0:db8738fc21e8 | 85 | * \return int |
Kojto | 0:db8738fc21e8 | 86 | */ |
Kojto | 0:db8738fc21e8 | 87 | int main() { |
Kojto | 0:db8738fc21e8 | 88 | init(); /* board dependent init */ |
Kojto | 0:db8738fc21e8 | 89 | pc.baud(115200); |
Kojto | 0:db8738fc21e8 | 90 | |
Kojto | 0:db8738fc21e8 | 91 | wifi.start(0); |
Kojto | 0:db8738fc21e8 | 92 | printf("cc3000 Hello World demo. \r\n"); |
Kojto | 0:db8738fc21e8 | 93 | print_cc3000_info(); |
Kojto | 0:db8738fc21e8 | 94 | |
Kojto | 0:db8738fc21e8 | 95 | printf("Attempting SSID Connection. \r\n"); |
Kojto | 0:db8738fc21e8 | 96 | wifi._wlan.ioctl_set_connection_policy(0, 0, 0); |
Kojto | 0:db8738fc21e8 | 97 | #ifndef CC3000_TINY_DRIVER |
Kojto | 0:db8738fc21e8 | 98 | #ifdef AP_KEY |
Kojto | 0:db8738fc21e8 | 99 | connect_to_ssid(SSID, AP_KEY, AP_SECURITY); |
Kojto | 0:db8738fc21e8 | 100 | #else |
Kojto | 0:db8738fc21e8 | 101 | connect_to_ssid(SSID); |
Kojto | 0:db8738fc21e8 | 102 | #endif |
Kojto | 0:db8738fc21e8 | 103 | #else |
Kojto | 0:db8738fc21e8 | 104 | connect_to_ssid(SSID); |
Kojto | 0:db8738fc21e8 | 105 | #endif |
Kojto | 0:db8738fc21e8 | 106 | printf("DHCP request \r\n"); |
Kojto | 0:db8738fc21e8 | 107 | while (wifi.is_dhcp_configured() == false) { |
Kojto | 0:db8738fc21e8 | 108 | wait_ms(500); |
Kojto | 0:db8738fc21e8 | 109 | printf(" Waiting for dhcp to be set. \r\n"); |
Kojto | 0:db8738fc21e8 | 110 | } |
Kojto | 0:db8738fc21e8 | 111 | |
Kojto | 0:db8738fc21e8 | 112 | tNetappIpconfigRetArgs ipinfo2; |
Kojto | 0:db8738fc21e8 | 113 | wifi.get_ip_config(&ipinfo2); // data is returned in the ipinfo2 structure |
Kojto | 0:db8738fc21e8 | 114 | printf("DHCP assigned IP Address = %d.%d.%d.%d \r\n", ipinfo2.aucIP[3], ipinfo2.aucIP[2], ipinfo2.aucIP[1], ipinfo2.aucIP[0]); |
Kojto | 0:db8738fc21e8 | 115 | printf("\r\ncc3000 connected to the Internet. Demo completed. \r\n\r\n"); |
Kojto | 0:db8738fc21e8 | 116 | |
Kojto | 0:db8738fc21e8 | 117 | wifi.disconnect(); |
Kojto | 0:db8738fc21e8 | 118 | } |
Kojto | 0:db8738fc21e8 | 119 |