Statistics
| Branch: | Tag: | Revision:

mongoose / examples / CC3200 / ccs / README.md @ eaef5bd1

History | View | Annotate | Download (4.51 KB)

1
# Code Composer Studio example projects
2

    
3
To run them you will need:
4
 - [CC3200-LAUNCHXL](http://www.ti.com/tool/cc3200-launchxl) dev board.
5
 - [CC3200SDK 1.2.0](http://www.ti.com/tool/cc3200sdk) installed in `TI_PRODUCTS_DIR/CC3200SDK_1.2.0` (typically `C:\ti\CC3200SDK_1.2.0` on Windows, `/home/USER/ti/CC3200SDK_1.2.0` on Linux).
6
 - The latest CC3200SDK-SERVICEPACK should also be installed and flashed to the device
7
 - Code Composer Studio 6 IDE
8
 - Mongoose source code. Either clone the [Git repo](https://github.com/cesanta/mongoose.git) or download the [ZIP archive](https://github.com/cesanta/mongoose/archive/master.zip).
9

    
10
## Mongoose - The library project
11
This project produces `Mongoose.lib` - a static library meant to be used by other projects.
12
Feel free to use it as a dependency for your own projects or just copy `mongoose.c` and `mongoose.h`.
13
Note that by default a lot of features are enabled, including file serving (which we use in our examples).
14
You can trim a lot of fat by turning various build options off.
15
A minimal HTTP serving configuration is about 25 K (compiled for ARM® Cortex®M4 with GCC 4.9 with size optimization on).
16

    
17
## MG_hello - A simple demo
18
MG_hello project is a simple web server that serves files from the SimpleLink file system and allows them to be uploaded.
19
This project depends on the Mongoose library project, make sure you import them both.
20
When importing, ensure the “copy project to workspace” checkbox is *unchecked*, otherwise file references will be broken.
21

    
22
When built and run on the device, by default, the example will set up a Wi-Fi network called “Mongoose” (no password).
23

    
24
Assuming everything works, you should see the following output in CIO:
25

    
26
```
27
main                 Hello, world!
28
mg_init              MG task running
29
mg_init              Starting NWP...
30
mg_init              NWP started
31
wifi_setup_ap        WiFi: AP Mongoose configured
32
```
33

    
34
Note: If the demo does not proceed past “Starting NWP…”, please reset the board (possibly related to [this](https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/p/499123/1806610#1806610) and our [workaround](https://github.com/cesanta/mongoose/commit/848c884fff80de03051344e230392a68d4b51b84) is not always effective).
35

    
36
And after connecting to Wi-Fi network Mongoose, the following page on http://192.168.4.1/:
37

    
38
<img src="upload_form.png" width="364" height="239">
39

    
40
Pick a small file (say favicon.ico) and upload.
41
You should get “Ok, favicon.ico - 16958 bytes.” and it will be served back to you ([link](http://192.168.4.1/)).
42
If you upload index.html, it will be served instead of the form (but the form will be accessible at [/upload](http://192.168.4.1/upload)).
43

    
44
## MG_sensor_demo - A more elaborate demo project
45

    
46
This demo shows the use of [timers](https://docs.cesanta.com/mongoose/latest/#/c-api/net.h/mg_set_timer/) and serving a WebSocket data stream to (potentially) multiple subscribers.
47
Data from the on-board temperature sensors and accelerometer is streamed to any clients connected over WebSocket, which allows building of responsive, near-real time dashboards.
48

    
49
The main [event handler function](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L81) in main.c does everything MG_hello’s function does, but also handles the websocket connection event - when `MG_EV_WEBSOCKET_HANDSHAKE_DONE` arrives, it switches the event handler to a different one - data_conn_handler (defined [here](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/data.c#L144) in data.c). Doing this is not required, but it keeps the code modular and function size manageable.
50

    
51
Data acquisition is performed at regular intervals by a timer. Mongoose timers are not very accurate (remember - everything is executed in single thread), but good enough for this case.The timer is first set [in mg_init()](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L200), and the `MG_EV_TIMER` event is handled [in the main handler](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L123). Mongoose timers must be re-armed manually.
52

    
53
To try this demo from Code Composer Studio IDE, follow the steps above for MG_hello. Same as for MG_hello, you will only see an upload for initially. Please upload `main.js` and `index.html` from the [slfs directory](https://github.com/cesanta/mongoose/tree/master/examples/CC3200/slfs) and reload the page. You should see something like this:
54

    
55
<img src="sensor_demo.png" width="770" height="856">
56

    
57
[This short video](https://youtu.be/T0aFUKIBZxk) shows the demo in action.