Nifty bio photo

Nifty

Nifty Testing Framework

Github

Tutorial 1: Starting Cooja

Starting Cooja

Nifty provides the nifty_cooja module to give you access to Cooja's functionality. You can start the simulator with the following command:

1> nifty_cooja:start("$CONTIKI/tools/cooja",
                     "path/to/simfile.csc", []).

The first parameter should point to the directory containing Cooja. This is typically in the tools/cooja directory of your Contiki distribution. The second parameter should point to the simulation you want to start Cooja with. In order to be able to control Cooja from Erlang, make sure to have the Socket Control plugin enabled in the used simulation. The return value is either a simulation handler in case of success, or fail if something went wrong. The handler is used to communicate with Cooja and is used for almost all functions in nifty_cooja

The optional third parameter is a list of options. The currently supported opions are debug and gui. debug will print additional debugging information, like the Cooja command line output. gui will run Cooja with the gui allowing you to observe and manipulate the simulation by hand.

Important!

Currently Cooja requires a ScriptRunner plugin in nogui mode. In order to use the Socket Control plugin you need to run Cooja in GUI mode:

1> nifty_cooja:start("$CONTIKI/tools/cooja",
                     "path/to/simfile.csc", [gui]).

State

You can get the state of Cooja by running:

2> nifty_cooja:state().

which will return {running, Handler}, not_running, ok, or fail. ok and fail is returned once! after Cooja has been exited (or crashed), while the other two indicate a running or not running simulator. {running, Handler} also gives you the handler to the currently running Cooja simulation.

Shuting Cooja Down

The currently running Cooja simulation can be shut down with:

3> nifty_cooja:exit().

This will return not_running, ok, or fail, depending on the state of Cooja and the return value.

Next Tutorial