<commit_before>Blink on a Mica2 Node
=====================

Running the blink module on real hardware is very similar to running it
in Avrora. Real hardware provides a number of benefits that do not exist in
simulation. These include access to hardware that is not modeled by a
simulator. Not to mention it has the ability to actually run code in a 
deployment!

Running blink on a physical node will require:

- A micro server that loads modules into the deployed sensor network
  using the suite of tools provided with the SOS distribution.

- At least one node with a connection to a micro server.  This node
  is able to receive modules from the micro server (typically over its UART),
  install these modules, and propagate the modules through the network.

- Optionally one or more additional sensor nodes.


Building the Parts
------------------

Building the Blink Module
~~~~~~~~~~~~~~~~~~~~~~~~~
As a first step the blink module needs to be compiled. This is
accomplished by going into the module's directory and building it for the
platform that is going to be used:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/modules/demos/blink/
make mica2
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Building the Blank Kernel
~~~~~~~~~~~~~~~~~~~~~~~~~
Next a clean SOS kernel needs to be compiled.  This kernel is called the
`blank` kernel image.  It is located in `$SOSROOT/config/blank/`.  This kernel is built specifically for the `mica2` target.

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/config/blank/
make mica2
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Building the SOS Server for the PC
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SOS uses a simple PC server to interface with nodes.  This same server
can be used in simulation and real deployments.  The server needs to be
built before it is used for the first time.  This is accomplished using:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_server/bin/
make x86
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Building the SOS Tool
~~~~~~~~~~~~~~~~~~~~~
The SOS tool is a Swiss Army knife of module management in SOS networks.
Among other actions, it is used to insert modules into a network.  This tool
is actually a custom SOS kernel that runs the SOS core in addition to
interfacing with the user.  It is built using: 

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_tool/
make emu
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Running Blink on a Node
-----------------------

Loading Blank Image
~~~~~~~~~~~~~~~~~~~
The following command instructs the make system to load an image onto a
sensor node.  Note that the make system assumes that you have a version of
`uisp` supporting your hardware in the current `PATH`.  For
physical setup a node must be connected to a programming device that is in
turn connected to the PC.  For this example, assume that the programming
device is a `mib510` connected to the PC via `/dev/ttyUSB0`.  Note that
the USB programmers use a separate interface for data communications.  For
this and other hardware, you need to specify the serial port that is
carrying the data.  To program the node use:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/config/blank/
make mica2 install PROG=mib510 PORT=/dev/ttyUSB0
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This single command can be used to both build the blank image and
program it onto the node.

NOTE: *PROG* Different programming hardware uses different ports to communicate
with the hardware.  The most common programming board is the `mib510` that uses 
a USB connector.  The `mib520ca` exposes to ports to the host machine: lower
number port is used for programming the node using `uisp` (via the `make
install` command) and the higher number port is used for data communication
with `sos_tool`.  The `mib510ca` uses a serial interface to connect to the
host machine.  With the `mib510ca` the same port is used for both
programming the node via `uisp` and communicating with data from the node.

NOTE: *PORT* Different operating systems use different naming convention for ports.
The normal naming convention of Linux is used in this documentation. The naming 
convention on Mac OSX follows the convention of Linux closely except we have found
that instead of ''tty'' using ''cu'' works for programming boards. Cygwin follows 
the naming convention of Linux.

Starting the SOS Server
~~~~~~~~~~~~~~~~~~~~~~~
Once the a kernel is installed on a node, the node is ready to accept
connections over its UART.  The `sossrv.exe` program can be started
to interface with it.  From a different terminal use:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_server/bin/
./sossrv.exe -s /dev/ttyUSB1
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Inserting Modules
~~~~~~~~~~~~~~~~~
With the SOS server up and running, modules can now be inserted.  This
is accomplished using the SOS tool:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_tool/
./sos_tool.exe --insmod=../../modules/demos/blink/blink.mlf
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a short wait the module is loaded onto the node and its green LED
should begin to blink. 

Next: link:surge.html[Overview of surge module] <commit_msg>added a note to blink_mica2<commit_after>Blink on a Mica2 Node
=====================

Running the blink module on real hardware is very similar to running it
in Avrora. Real hardware provides a number of benefits that do not exist in
simulation. These include access to hardware that is not modeled by a
simulator. Not to mention it has the ability to actually run code in a 
deployment!

Running blink on a physical node will require:

- A micro server that loads modules into the deployed sensor network
  using the suite of tools provided with the SOS distribution.

- At least one node with a connection to a micro server.  This node
  is able to receive modules from the micro server (typically over its UART),
  install these modules, and propagate the modules through the network.

- Optionally one or more additional sensor nodes.


Building the Parts
------------------

Building the Blink Module
~~~~~~~~~~~~~~~~~~~~~~~~~
As a first step the blink module needs to be compiled. This is
accomplished by going into the module's directory and building it for the
platform that is going to be used:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/modules/demos/blink/
make mica2
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Building the Blank Kernel
~~~~~~~~~~~~~~~~~~~~~~~~~
Next a clean SOS kernel needs to be compiled.  This kernel is called the
`blank` kernel image.  It is located in `$SOSROOT/config/blank/`.  This kernel is built specifically for the `mica2` target.

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/config/blank/
make mica2
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Building the SOS Server for the PC
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SOS uses a simple PC server to interface with nodes.  This same server
can be used in simulation and real deployments.  The server needs to be
built before it is used for the first time.  This is accomplished using:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_server/bin/
make x86
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Building the SOS Tool
~~~~~~~~~~~~~~~~~~~~~
The SOS tool is a Swiss Army knife of module management in SOS networks.
Among other actions, it is used to insert modules into a network.  This tool
is actually a custom SOS kernel that runs the SOS core in addition to
interfacing with the user.  It is built using: 

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_tool/
make emu
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Running Blink on a Node
-----------------------

Loading Blank Image
~~~~~~~~~~~~~~~~~~~
The following command instructs the make system to load an image onto a
sensor node.  Note that the make system assumes that you have a version of
`uisp` supporting your hardware in the current `PATH`.  For
physical setup a node must be connected to a programming device that is in
turn connected to the PC.  For this example, assume that the programming
device is a `mib510` connected to the PC via `/dev/ttyUSB0`.  Note that
the USB programmers use a separate interface for data communications.  For
this and other hardware, you need to specify the serial port that is
carrying the data.  To program the node use:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/config/blank/
make mica2 install PROG=mib510 PORT=/dev/ttyUSB0
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This single command can be used to both build the blank image and
program it onto the node.

NOTE: *PROG* Different programming hardware uses different ports to communicate
with the hardware.  The most common programming board is the `mib510` that uses 
a USB connector.  The `mib520ca` exposes to ports to the host machine: lower
number port is used for programming the node using `uisp` (via the `make
install` command) and the higher number port is used for data communication
with `sos_tool`.  The `mib510ca` uses a serial interface to connect to the
host machine.  With the `mib510ca` the same port is used for both
programming the node via `uisp` and communicating with data from the node.

NOTE: *PORT* Different operating systems use different naming convention for ports.
The normal naming convention of Linux is used in this documentation. The naming 
convention on Mac OSX follows the convention of Linux closely except we have found
that instead of ''tty'' using ''cu'' works for programming boards. Cygwin follows 
the naming convention of Linux.

Starting the SOS Server
~~~~~~~~~~~~~~~~~~~~~~~
Once the a kernel is installed on a node, the node is ready to accept
connections over its UART.  The `sossrv.exe` program can be started
to interface with it.  From a different terminal use:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_server/bin/
./sossrv.exe -s /dev/ttyUSB1
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

NOTE: The port to install blank and the port to use for sos server are different 
even though the board it connected to a single port on the CPU. 

Inserting Modules
~~~~~~~~~~~~~~~~~
With the SOS server up and running, modules can now be inserted.  This
is accomplished using the SOS tool:

[c]
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $SOSROOT/tools/sos_tool/
./sos_tool.exe --insmod=../../modules/demos/blink/blink.mlf
code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a short wait the module is loaded onto the node and its green LED
should begin to blink. 

Next: link:surge.html[Overview of surge module] 
{'fraction_non_alphanumeric': 0.18249465166031067, 'fraction_numerical': 0.005301832387684866, 'mean_word_length': 4.614621409921671, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2824146', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2633, 'n_words': 1483}