I had the chance to play a bit with the CC3000 Boosterpack which can be used together with the MSP-EXP430G2 Launchpad, and it seems like a very interesting device. It enables WiFi/Internet connection for microcontrollers with small memory size. The CC3000 works such as network processor running a TCP/IP stack which basically does the whole stuffs related to the WiFi/Internet connection, and users need only to implement the application on the host microcontroller. A very nice thing from the software point of view which I found also is that the host source code uses similar API to the BSD socket which is basically the standard API for socket programming .
One of the basic example provided for this kit is called the Basic WiFi example, where basically the MSP-EXP430G2 Launchpad kit is connected via USB to a PC and receives command to execute some basic functionalities such as connecting to a WiFi Access Point, opening a UDP socket, sending and receiving data via the UDP socket, etc. It is basically a nice example to get started working with the platform, however I find it a bit hard to test the example since you need to work with hyperterminal and type in the command code manually. Therefore I decided to write a python based script tool running on the PC which can be used as a host for the CC3000 Basic WiFi example, and it can be found here.
NOTE: For this guide, I am using the release version v.0.1.0 which can be downloaded as ZIP file at this link. You need also to have Python 2.7 and pyserial installed on your computer to be able to run the script. Installing Python 2.7 should be straight forward since you need only to download the executable installation file. For installing pyscripter, please refer to the this guide.
CC3000 Basic WiFi Host Operation
The CC3000 Basic WiFi Host python script works basically in two modes: interactive console mode (invoked by “-c” or “–console” command line parameter) and scripter mode (invoked by “-f FILE” or “–file FILE” command line parameter). Only one of the two modes can be selected at one time.
Interactive Console Mode
The interactive console mode is invoked when the BasicWiFiHost.py script file is executed with “-c” or “–console” parameter. In this mode the user works interactively with a console to give several command one after another. The following screenshot shows how the interactive console mode looks like:
As shown above, in the console mode the user is asked to give a command by typing in the command number (between 0-11) and then pressing the enter key. If necessary, the console will also ask for the command parameter (e.g. SSID name for “Connect to AP” command). Each given command will be translated to the Basic WiFi command format and sent out to the Launchpad via USB serial line. The console with wait for the reply before the user will be then asked for the next command.
Scripter Mode
The interactive console mode is invoked when the BasicWiFiHost.py script file is executed with “-f FILENAME” or “–file FILENAME” parameter, where FILENAME is the name of input text file containing the list of pre-defined commands to be executed by the Basic WiFi Host script. The following screenshot shows how the scripter mode looks like:
The supported commands in scripter mode are listed as follows:
- SMART_CFG
- CONNECT <SSID_NAME>
- SOCK_OPEN
- SEND <DEST_IP_ADDR> <DEST_PORT> <DATA>
- RECEIVE
- SOCK_CLOSE
- DISCONNECT
- DEL_POLICY
- MDNS_ADV
- DELAY <DELAY_TIME_IN_MS>
- PRINT_STATUS
- SHUT_DOWN
- RESTART
Beside the commands above, it is also possible to write comment as a line preceded by a double slash (“//“). The SHUT_DOWN and RESTART command will only work with some changes in the Basic WiFi firmware to test the current consumption of the CC3000 in shutdown mode which will be covered in my next post.
Testing The CC3000 Basic WiFi Host Script
The CC3000 Basic WiFi Host Script is tested with the following hardware setup:
The Basic WiFi Host is delivered with a basic UDP communication example which can be found under CC3kBasicWifiHost\example\BasicUDPComm folder. The demo can be run by doing the following steps:
- Attach the CC3000BOOST boosterpack to the MSP-EXP430G2 (with MSP430G2553 on-board), and connect the USB cable to the Host Laptop.
- Update the CC3000 firmware using the CC3000 Patch Programmer Utility. I am using driver version 2.13.7.15 with the MSP-EXP430G2 and CC3000BOOST.
- Download the Basic WiFi Application firmware source code from this link (for this test, I am using v1.12). There is a small bug in the code which makes the firmware to forward the incoming message from WiFi with wrong buffer size (it always to send the whole RX buffer). To fix this, open basic_wifi_application.c file, and in the DemoHandleUartCommand() function, change the handling of UART_COMMAND_RCV_DATA as follows:
void DemoHandleUartCommand(unsigned char *usBuffer) { .................. switch(usBuffer[1]) { .................. // Handle receive data command case UART_COMMAND_RCV_DATA: .................. else { // Send data to UART... //DispatcherUartSendPacket(pucCC3000_Rx_Buffer, CC3000_APP_BUFFER_SIZE); DispatcherUartSendPacket(pucCC3000_Rx_Buffer, iReturnValue); } break; .................. } .................. }
- Compile and flash the firmware to the MSP430G2553 flash memory on the MSP-EXP430G2 Launchpad.
- Install Python 2.7.x to both Host Laptop and Test Laptop. In practical, both laptop can be implemented as only one laptop/PC. For Host Laptop which acts as the Basic WiFi Host, it is also necessary to install pyserial.
- Make sure that the security feature on the TP-Link WiFi router is disabled and connect the Test Laptop to the WiFi router. Retrieve the IP address of the Test Laptop e.g. by executing ipconfig command in Windows command line console (in this test, the Test Laptop receives IP address 192.168.1.100 via DHCP after being connected to the WiFi router).
- Open the simple_udp_server.py file under CC3kBasicWifiHost\example\BasicUDPComm folder with a text editor program and edit the HOST_IP variable with the WiFi interface IP address (192.168.1.100 for this example) and also UDP_PORT variables if necessary (default value is port 30000; make sure that the UDP port is not used on the Test Laptop). Then execute run_udp_server.bat on the Test Laptop to run the python script file. This script is basically a simple UDP echo server which will send back the incoming data preceded by a big capital letter ‘R’.
- In the same folder, open the basic_udp_comm_script.txt file which will be used as the input file for running the Basic WiFi Host in scripter mode. Modify the SSID_NAME parameter as CONNECT command parameter if necessary (it is ASTDemoTP for this example), and also make sure that the parameters for SEND_DATA command: DEST_IP_ADDR parameter which shall match the HOST_IP variable of simple_udp_server.py running on the Test Laptop, i.e. the IP address of the Test Laptop – 192.168.1.100 for this example; DEST_PORT: shall match UDP_PORT variable of simple_udp_server.py – 30000 for this example; DATA: string to be sent to the destination, shall not be longer than 7 bytes (since the UDP server will send back ‘R’+DATA).
- Open the basic_udp_comm.bat file and change the “-p” parameter with the corresponding COM PORT number assignment of MSP-EXP430G2 Launchpad’s UART back channel on Host Laptop. Execute the basic_udp_comm.bat batch file to run the Basic WiFi Host script in scripter mode. The script shall start the Basic WiFi Host in scripter mode, and at the beginning it will ask the user to reset the MSP-EXP430G2 (can be simply done by pushing S1 RESET button on the MSP-EXP430G2 Launchpad) so it can receive for the first line from the Basic WiFi application running on the Launchpad with the format “Example App: driver version x.yy.zz.uu”. The result shall be the same as the one shown in the “Interactive Mode” section above.
- The Basic WiFi Host shall show that process of connecting to AP, opening socket, sending data (“MYDATA”), receiving data (“RMYDATA”), closing socket, and finally disconnecting from the AP. On the Test Laptop, the following message shall appear:
Some explanations regarding the output text shown by the Basic WiFi Host script:
- Lines which are started with [T] refer to the reply string from the Basic WiFi firmware running on the MSP-EXP430G2 Launchpad.
- Lines which are started withe [LINE] (only in scripter mode) refer to the content of the input script file commands/comments.
- Lines which are started with [DBG] refer to some debug output which can be ignored.
- The rest of output are generated by the Basic WiFi Host script to show how the script runs the process.
.can i run the same application for tivac TM4C123GH6PM
THANKS IN ADVANCE
Hi,
Excellent !!!
I have one query.
As i use cc3000 + MSP430G2 launchpad ,i cant send more than 7 bytes ?Whats this limitatation?
Howcan i send more data byte?
Please suggest solution.
Regards,
Rahul Shah