CC3000 Basic Wi-Fi example application for Launchpad

From Texas Instruments Wiki
Jump to: navigation, search


This wiki describes the first-time installation and use of the CC3000 device with the MSP-EXP430G2-Launchpad device.
NoteNote: while this document refers to the MSP-EXP430G2-Launchpad  device specifically, this same information is used to describe the Basic Wi-Fi example application for all of the supported TI platforms. For a list of supported TI platforms please refer to this page

Prerequisites

Hardware

  1. 1x MSP-EXP430G2 Launchpad, order from TI eStore MSP-EXP430G2 Value Line Development Kit
  2. 1x CC3000EM, orderable from the TI eStore
  3. 1x Wi-fi Access Point (will be using TP-Link WR740N)

Software

  1. Download the Patch programmer installer for MSP-EXP430G-Launchpad
  2. Download the MSP-EXP430G2-Launchpad Basic Wi-Fi Application
  3. One of the following evaluation software is required in order to view and compile the patch programmer sources. Alternatively the binary can be used to burn directly to the board(Included in Patch Programmer download)
    • IAR Embedded Workbench v5.51.4 (MSP430) / v6.50.1 (Stellaris).
    • CCSv5.3
  4. (Optional) Hyper Terminal: Such as PuTTY

Assumptions & Knowledge Base

  1. The user should have knowledge of or be familiar with:
  • The CC3000 Host Driver Overview document
  • Network programming
  • Changing WLAN access point (AP) parameters


Environment Setup

Connecting the CC3000 Device to a PC

  1. Connect the CC3000 BoosterPack to the MSP-EXP430G2-Launchpad board.
  2. Connect the USB miniport on the MSP-EXP430G2-Launchpad board to a PC.
  3. Download and install the IAR Embedded Workbench for MSP430 from [1] here.

For more information please refer to the MSP-EXP430G2-WiKi .

Configuring the HyperTerminal

General Notes

The HyperTerminal is the interface through which commands are sent to the CC3000 basic Wi-Fi example application.

The HyperTerminal connects to the MSP-EXP430G2-Launchpad board, as shown in the figure below.  

MSP430G2553-CC3000-Launchpad.jpg



Ensure the MSP430 Launchpad is configured to use the Hardware UART (USCI)

UART Jumper Configuration



The figure below shows the HyperTerminal Computer Management window with the Stellaris application UART selected.
MSP430 Application UART Selected in the Content Management Window.png

Baud Rate Configuration

Configure the baud rate as follows (see also the figure below):

  • Bits per second: 9600
  • Data bits: 8
  • Parity: None
  • Stop bits: 1
  • Flow control: None
Baud Rate Configuration.png

ASCII Settings

Configure the HyperTerminal ASCII settings as follows (see also the figure below):

  • ASCII Sending: Echo typed characters locally selected
  • ASCII Receiving: Wrap lines that exceed terminal width selected
HyperTerminal Settings.png

Configure the ASCII setup of the HyperTerminal as follows (see also the figure below):
  • Echo typed characters locally: Checked
  • Wrap lines that exceed terminal width: Checked
HyperTerminal ASCII Setup.png

If the configuration is correct, powering up the Stellaris Board displays the HyperTerminal string shown in the figure below. Please note that the first digit of the version represents the MCU platform.
The digit "2" is assigned to MSP-EXP430G2-Launchpad.
HyperTerminalLaunchpad14022013.PNG


Evaluation Software User Guide

Running Basic WiFi Application with IAR

Working with IAR Embedded Workbench will require opening the provided workspace, compile and burn it to the board following these instructions:


In order to open a workspace and compile an application by yourself, please follow these steps:

  1. Open the IAR Embedded Workbench.
  2. Select File→Open→Workspace (see the figure below).
    Opening the IAR Embedded Workbench.png

    The Open Workspace dialog box appears.
  3. Open the CC3000 basic Wi-Fi example application (BasicWiFiApplication_workspace.eww) as shown in the figure below.
    Opening the Example Application.png

    At this step, a workspace will be opened:(see the figure below).
    Example Workspace.png

  4. Project overview:
    Projectovervire.png

  5. In the Workspace window, right-click Example Application - Debug to open a menu. From the menu, select Options (see the figure below).
    Select options 25102012.png

  6. Build your workspace as follows:
    1. In the Workspace window, right-click CC3000 Host Driver - Debug to open a menu. From the menu, select Rebuild All to build the CC3000 host driver (see the figure below).
      Building the CC3000 Host Driver.png

    2. In the Workspace window, right-click CC3000Spi - Debug to open a menu. From the menu, select Rebuild All to build the CC3000_Spi (see the figure below).
      Spi-Debug-Rebuild.png

    3. In the Workspace window, right-click HyperTerminalDriver - Debug to open a menu. From the menu, select Rebuild All to build the HyperTerminal driver (see the figure below).
      HyperTerminal-Rebuild.png

    4. In the Workspace window, right-click Demo Application - Debug to open a menu. From the menu, select Rebuild All to build the example application (see the figure below).
      Basic-WiFi-Rebuild.png

  7. To download and debug the CC3000 basic Wi-Fi example application, click the button (see the figure below).
    DownloadAndDebugging251012.jpg

Running Basic WiFi Application with CCS V5

Working with CCS v5 will require opening the provided workspace, compile and burn it to the board following these instructions:

In order to open a workspace and compile an application by yourself, please follow these steps:

1.  Open Code Composer Studio v5.

2.  Set the workspace to ..\ Basic WiFi Application\Basic WiFi Application CCS (see the figure below).

Open workspace.png

 3. Select Project->Import Existing CCS/CCE Eclipse Project as shown in the figure below.

Import.png

  4. Select Browse and open Basic WiFi Application Folder as shown in the figure below.

Open.png

   5. Select Select All and Finish as shown in the figure below.

Select.png


 

   6. At this step a workspace will be created:

 
Created.png

   7. Build your workspace as follows:

   7.1 In the workspace click CC3000 Host Driver and press the hammer icon in order to build.


Cc3000hostDriver.png

    7.2 In the Workspace window, click CC3000 Spi and press the hammer icon in order to build.


Spi.png

    7.3 In the Workspace window, click Hyper Terminal Driver and press the hammer icon in order to build.


Uart.png

    7.4 In the Workspace window, click Basic WiFi Application and press the hammer icon in order to build.


Basic wifi application.png

  8. To download and debug the CC3000 basic Wi-Fi example application, click the button (see the figure below).


Debug.png

Running the Application

Configuring the Basic Wi-Fi Example Application

The example application demonstrates basic WLAN connectivity together with the capability of sending data over the WLAN transport with the help of the standard BSD socket interface.

General Description

Each HyperTerminal command-line interface (CLI) command used in the basic Wi-Fi example application consists of a minimum of 2 bytes opcode. To execute a command, type the command and press Enter. When command execution completes, DONE appears in the HyperTerminal window (see the figure below).
CC3000-HyperterminalCmdExampleLPAD.png
Note: The first operation performed is a first-time configuration (see the section Static IP
Configuration).

Before moving to socket-based operations, additional AP and static IP connections must be configured. The table below lists the supported commands.

The table below lists the supported commands.
Commands for AP Connection and Static IP Configuration v2.png
 


Each command must be typed as an ASCII string in the HyperTerminal (see figure above). To test the basic connectivity of the CC3000 device with the AP, perform the following steps:

  1. To connect to the AP, execute First Time Configuration command (01). If the AP is ready, the device connection is successful.
  2. To configure the IP address of the CC3000 device, execute the IP Configure command (08). This command may define an AP as a default gateway for the CC3000 device.
  3. Connect the PC behind the AP with the same subnet address as that of the AP.
  4. To test connectivity between the CC3000 device and the PC, execute the ping command


Smart Configuration

Example Application Configuration:

  • Execute the SmartConfig command (01) from the HyperTerminal.
     When the device finds an AP, the HyperTerminal displays Smart config DONE and then Done (see the figure below).
SmartConfigLpad14022013.PNG
The example application now reboots the CC3000 device. After the reboot, the CC3000 device tries to connect to the AP detected.
  • Following the reboot and as soon as the CC3000 device connects to the AP, the CC3000 IP address will be displayed (see the figure below).
SmartConfigLpadIpAddr.PNG


Please Note: For the Basic WiFi Application the following parameters need to be set in the iOS\Android application:

  • Device name: home_assistant
  • AES encryption key: leave it blank. (MSP-EXP430G2-Launchpad SmartConfig  doesn't support encryption mode.)


For more detailed description on how to perform this step, you may refer to the CC3000 Smart Configuration  wiki page


For programmers:

/* The function triggers a smart configuration process on CC3000 it exists upon completion of the process. */
 
void wlan_first_time_config_start(void);


 From the CC3000 Basic Wi-Fi Example application code:

StartSmartConfig();


Static IP Configuration

The example application supports the configuration of the CC3000 device with a static IP.

To configure the device IP, execute the command 08XXYYZZUUAABBCCDD where:

  • XXYYZZUU is an IP address assigned to the CC3000 device in hexadecimal form. For example, if the required address is 192.168.39.10, the hexadecimal value is c0a8270a. Lower case only is supported.
  • AABBCCDD is an IP address of the default gateway in hexadecimal form as well (which can be an IP address of the AP). The example application assumes that the network mask is 255.255.255.0.

To test connectivity, execute the ping command.


In order to configure DHCP, execute the command with zero value for all fields.


For programmers:

/* aucIP specifies the static IP for configuration. In case of dynamic address, set this value to 0. */
/* aucSubnetMask specifies the static subnet mask address. In case of dynamic address, set this value to 0. */
/* aucDefaultGateway specifies the static Gateway address. In case of dynamic address, set this value to 0. */
/* aucDNSServer specifies the static DNS server address. In case of dynamic address, set this value to 0. */
 
long netapp_dhcp ( unsigned long * aucIP, unsigned long * aucSubnetMask, unsigned long * aucDefaultGateway, unsigned long * aucDNSServer );

 From the CC3000 Basic Wi-Fi Example application code:

netapp_dhcp((unsigned long *)pucIP_Addr, (unsigned long *)pucSubnetMask, (unsigned long *)pucIP_DefaultGWAddr, (unsigned long *)pucDNS);
  where all the parameters are taken from the UART command that was applied.


Open UDP Socket

To open a UDP socket, execute the Socket Open command (03).


For programmers:

/* domain selects the protocol family which will be used for communication. AF_INET is supported. */
/* type specifies the communication semantics. SOCK_STREAM and SOCK_DGRAM, SOCK_RAW are supported. */
/* protocol specifies a particular protocol to be used with the socket. IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are supported. */
/* On success the return value is the socket handle that is used for consequent socket operations. On error, -1 is returned. */
 
int socket ( long domain , long type , long protocol );


From the CC3000 Basic Wi-Fi Example application code:

ulSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

 


Send Data

Please Note: MSP-EXP430G2-Lauchpad supports MAX UDP payload = 8 bytes

To transmit a data packet:

  1. Execute the Socket Open command (03) as described in the section "Open Socket".
  2. Execute the sendto command (04AAX…Y02BCDEFGHIKLMN)

where:

  • AA is the hexadecimal presentation of the length of data. For example, to send 5 bytes, type 05.
  • The field following AA is data. For example, to send the string 12345, type 12345.
  • BCDE is the hexadecimal presentation of the destination port.
  • FGHIKLMN is the hexadecimal presentation of the destination IP address.


For programmers:

/* sd specifies the socket handle. */
/* buf points to a buffer containing the message to be sent. */
/* len specifies the message size in bytes. Range: 1-1460 bytes . */
/* flags specifies the type of message transmission. On this version, this parameter is not supported. */
/* On success the return value is the number of transmitted bytes. On error, -1 is returned. */
 
int sendto ( long sd , const void * buf , long len , long flags , const sockaddr * to , socklen_t tolen );

From the CC3000 Basic Wi-Fi Example application code:
sendto ( ulSocket , pcData , ulDataLength , 0 , &tSocketAddr , sizeof(sockaddr) );

Where all the parameters are taken from the UART command that was applied.


Receive Data

Please Note: MSP-EXP430G2-Lauchpad supports MAX UDP payload = 8 bytes


  1. Execute the Socket Open command (03) as described in Section 6.4, Open Socket.
  2. Execute the bind command (06XXYY) where XXYY is the port in hexadecimal form. For example, if a port is 51000, the value typed is c738.
  3. Execute the Receive Data command (05). The HyperTerminal displays the received data.


For programmers:

/* sd specifies the socket handle. */
/* buf points to the buffer where the message should be stored. */
/* len specifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-1460 bytes. */
/* flag specifies the type of message reception. On this version, this parameter is not supported. */
/* len specifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-1460 bytes. */
/* from is a pointer to an address structure indicating the source address: sockaddr. */
/* On success the return return the number of bytes received. On error, -1 is returned. 0 if timeout occurred. */
 
int recvfrom ( long sd , void * buf , long len , long flags , sockaddr * from , socklen_t * fromlen );

From the CC3000 Basic Wi-Fi Example application code:

recvfrom ( ulSocket , pucCC3000_Rx_Buffer , CC3000_RX_BUFFER_SIZE , 0 , &tSocketAddr, &tRxPacketLength );

Where all the parameters are taken from the UART command that was applied.

Close Socket

To close a UDP socket, execute the Socket Close command (07).

For programmers:

/* sd specifies the socket handle . */
/* On success, zero is returned. On error, -1 is returned. */
 
closesocket ( long sd );

From the CC3000 Basic Wi-Fi Example application code:

closesocket( ulSocket );
Where ulSocket specifies the socket handle we request to close.


Connect to AP

Note: The Connect-to-AP command is for advanced users. 

To connect to the AP manually (that is, not during the simple configuration process), execute the command 02XA...D where:

  • X is the SSID name length in hexadecimal presentation.
  • A...D is the SSID name length.


For programmers:

/* sec_type - selects the security options: WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2. */
/* ssid specifies the SSID of the AP, up to 32 bytes and is ASCII. */
/* ssid_len specifies the length of the SSID. */
/* bssid specifies the SSID, up to 6 bytes. */
/* key specifies the key, up to 16 bytes. */
/* key_len specifies the key length. */
/* sec_type selects the security options: WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2. */
/* On success, zero is returned. On error, negative is returned. Note that even though a zero is returned on success to trigger connection operation, it does not mean that CCC3000 is already connected.
   An asynchronous "Connected" event is generated upon the finish of connection process. */
 
long wlan_connect ( unsigned long ulSecType , char * ssid , long ssid_len , unsigned char * bssid , unsigned char * key , long key_len );

From the CC3000 Basic Wi-Fi Example application code:

wlan_connect( 0 , pcSsid , ulSsidLen , NULL , NULL , 0 ) ;

Where all the parameters are taken from the UART command that was applied.



Disconnect from AP

To disconnect the CC3000 device from the AP, execute the CC3000 Disconnect command (09).

Note: By default, the CC3000 device tries to reconnect to the AP automatically as programmed by the Simple Configuration process within the Example Application. To disconnect without reconnecting, the user
 must remove the policy as described in the section ''Delete Policy''. 

For programmers:

/* On success the return value is 0. For any other value returned other - already disconnected. */
 
long wlan_disconnect ( void );


From the CC3000 Basic Wi-Fi Example application code:
wlan_disconnect();

Delete Policy

Note: The Delete Policy command (0a) is for advanced users. 

To delete the policy of automatic connection to the AP (as programmed by the Simple Configuration process), execute the CC3000 Delete Policy command (0a). After the following reset, automatic reconnection to the AP is not attempted.


For programmers:

/* should_connect_to_open_ap specifies if to connect to any available AP. enable =1 , disable = 0. */
/* should_use_fast_connect specifies if to connect to the last connected AP or not. enable =1 , disable = 0 . */
/* auto_start specifies if to perform auto connect after reset and periodically reconnect if needed. enable =1 , disable = 0. */
/* On success zero is returned. On error, -1 is returned. */
 
long wlan_ioctl_set_connection_policy ( unsigned long should_connect_to_open_ap , unsigned long should_use_fast_connect , unsigned long ulUseProfiles ) ;

From the CC3000 Basic Wi-Fi Example application code:

wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);

Where the first parameter dissable connection the any available AP, the second parameter dissable fast connect and the last parameter dissable auto connect after reset.

Send mDNS Advertizement

Note: The Send mDNS Advertizement command (0b) is for advanced users. 

This command sending mDNS Query packet with the data predefined in Basic WiFi application.

For programmers:

/**
 * \Set CC3000 in mDNS advertiser mode in order to advertise itself
 *
 * This function is used to make the CC3000 seen by mDNS browsers
 * \param[in] mdnsEnabled flag to enable/disable the mDNS feature
 * \param[in] deviceServiceName the service name as part of the published canonical domain
 name
 * \param[in] deviceServiceNameLength the length of the service name
 * \return On success, zero is returned, return SOC_ERROR if socket was not opened successfully,
 * or if an error occurred.
 *
 * \sa
 * \note
 * \warning
 */
int mdnsAdvertiser(unsigned short mdnsEnabled,
 char * deviceServiceName,
 unsigned short deviceServiceNameLength)
 


For more information please refer to our CC3000 mDNS wiki page.

Additional Resources

Related WiKi pages

Site Map