A First Application
This section refers to the following sample application(s):
00-hello
The
SmartMesh library
implements the full run-time environment for your application. For your application to start running, it needs to do at least the following:- Implement the function p2_init(). This function is called by the
SmartMesh library
and is the entry point for your application. It is called before the uC/OS-II operating system has been started, i.e. while you can create tasks in this function, you cannot, for example, post or pend semaphores. - Create a channel to receive notifications from the local interface of the
SmartMesh network stack
. You need to register the message typeDN_MSG_TYPE_NET_NOTIF
to this channel. This is the message type the stack uses to publish notifications. - Optionally, you can choose to open the CLI port if your application will receive command from a user, or print on the CLI port.
The 00-hello
Sample Application
To be able to see the "Hello, World!" message, connect a terminal client (such as PuTTY or TeraTerm) to the CLI serial interface of your device.
Refer to the SmartMesh IP Tools Guide for information about the different serial ports.
When the mote boots, you see the following on your terminal client:
> Hello, World!
The
SmartMesh library
implements a base command line interface, by default. You can typehelp
to see the default CLI commands:> Hello, World! > > help help <command> Commands: mtrace mset mget minfo mlog mfs mseti mgeti mshow mxtal mhwlog >
By convention, all default CLI commands start with the letter "m", for "mote".
You can issue the command minfo
to obtain general information about the state of the device:
> minfo Net stack v1.2.1.3 state: Idle mac: 00:17:0d:00:00:38:0f:47 moteid: 0 netid: 423 blSwVer: 13 ldrSwVer: 1.0.3.12 UTC time: 0:0 reset st: 200
You can use the command mset
to configure a number of elements of the
SmartMesh network stack
. For example, change the Network ID of the mote through the following command:> mset netid 477
This setting is stored in non-volatile memory. After a reboot of the device, you can verify that the setting is still present.
> Hello, World! > mget netid netid = 477
Refer to the SmartMesh IP Mote CLI Guide for a description of these commands.
Implementation Details
The 00-hello
sample application initializes the CLI Module, before printing "Hello, World!" over it. Initialization involves:
- opening the CLI module by calling
dnm_ucli_openPort()
; - raising the default access level to
DN_CLI_ACCESS_USER
so the user can issue CLI commands such asmset
; - create a channel to receive CLI notifications;
- initialize the CLI Module.
- continuously call the (blocking)
dnm_loc_processNotifications()
to process received CLI command.
These operations are so common that we built the simple cli_task
Helper Module.
The 00-hello_common
sample application is equivalent to 00-hello
, but using this helper module (see Helper Modules)