A: Develop and Test Applications

In this section, you will learn how to develop applications in the Legato development environment, install them onto your mangOH Red, and test that they run.

Legato provides two interfaces for developing applications:

CLI  Command Line Interpreter in a terminal window.

Developer Studio  A GUI (Graphical User Interface) development environment.

This section describes development using CLI.

Note:   You will be updating application source code in this section. Use whichever editor you prefer  these instructions do not refer to a specific editor.

Note:   This tutorial touches on the basics of using the Legato development environment. After completing the examples in this chapter, see http://legato.io/legato-docs/latest/mangOH_developers.html for detailed references, forums, etc.

A.1 Develop using the CLI  Command Line Interpreter

A.1.1 Configure the Dev Machine’s Terminal Windows for Development

To use the CLI in a terminal window to compile and build applications, you must configure the window to work with Legato tools.

Each time you open a new terminal window, do the following:

1.Configure the window:

$ cfglegato 

41112261_Develop00273.jpg

 

Note:   One thing the command does is check to see which toolchains you have on your development machine and warn you about any that are missing. Since you have loaded only the wp85 toolchain, warnings appear about the others. You can ignore these messages.

2.Confirm that the environment was set correctly:

$ echo $LEGATO_ROOT 

41112261_Develop00276.jpg

 

If a directory path appears, the command worked. If no value was returned, there was a problem with the command  make sure that you entered the alias correctly, using the actual directory name that you used to install Legato.

A.1.2 Update an Installed Application

As you saw when you set up your AirVantage account, one of the mangOH platform applications loaded on your device in Build / Install mangOH Distribution  Detailed Steps was redSensorToCloud. This application reports sensor readings to the cloud (e.g. AirVantage) every two minutes.

In this section you will increase the reporting frequency of the redSensorToCloud application and install the new version on the mangOH Red.

To update redSensorToCloud:

1.On the dev machine, open a new terminal window.

2.Configure the window for development:

$ cfglegato 

3.Change directory to the folder containing the application’s source code:

$ cd $MANGOH_ROOT/apps/RedSensorToCloud 

4.The source code components for this application are in two sub-folders  avPublisherComponent and sensorsComponent. The code that controls the publishing frequency is in avPublisherComponent  change directory to that folder:

$ cd avPublisherComponent 

5.Open and edit avPublisher.c (the source code file) with your preferred editor  two values must be updated to adjust the reporting frequency:

a.Search for the variable declaration for MaxIntervalBetweenPublish.

static const int MaxIntervalBetweenPublish = 120;

b.Change the interval value to 30  This increases the reporting frequency to at least once every 30 seconds from once every 120 seconds.

c.Search for the variable declaration for TimeToStale.

static const int TimeToStale = 60; 

d.Change the stale value to 30  This decreases the length of time a sensor reading is considered to be ’current’ before a new sensor reading must be taken.

e.Save your changes and exit the editor.

At this point, you have modified the redSensorToCloud application’s source code. Now you have to build (compile) it.

This application was created as part of the mangOH Red platform; to rebuild the application, you will rebuild the whole platform. This method is suggested when applications may interact with each other. If only one application is rebuilt, it may not work properly with other applications that it depends on (or that depend on it).

To rebuild the mangOH Red platform, including redSensorToCloud with your changes, and install it onto your mangOH Red:

1.Build and install the mangOH Red platform (use ’make’ to build for all devices, or use the correct device-specific parameter for your module  see Section C.3 mangOH Platform ’make’ parameters for details):

$ cd $MANGOH_ROOT 

$ make red_wp76xx     (Or use "make" with no parameters to build all platforms.)

41112261_Develop00279.jpg

 

Note:   This may take several minutes to run.

Note:   This ’make’ command uses the Makefile in $LEGATO_ROOT to build the entire system.

2.Verify that the update files were created for the mangOH distributions you built by checking their time stamps:

$ ls -al build/update_files/* 

41112261_Develop00282.jpg

 

3.Make sure the mangOH board is powered on and is connected to your dev machine  the board is connected if you receive ping responses:

$ ping 192.168.2.2 

Press Ctrl+C to return to the command prompt.

4.Install the mangOH Red platform specific to the CF3 module on your mangOH board:

$ update ~/mangOH/build/update_files/red/<updatefile> 192.168.2.2 

If the applications install successfully, the last message shown will be "SUCCESS      Done".

Note:   If the CF3 module has any problems starting the mangOH Red platform applications, it automatically reboots and restores to its original state (prior to the instsys command). If this happens, the CF3 module will not be reachable while it is rebooting.

41112261_Develop00285.jpg

 

5.After the installation is done, open a terminal window and connect to the mangOH Red:

$ ssh root@192.168.2.2 

6.By default, redSensorToCloud is installed but not started. Start the application to send data to AirVantage:

# app start redSensorToCloud 

Note:   redSensorToCloud automatically opens a data connection, so you do not need to use "cm data connect".

In your AirVantage account, you will start to see sensor reports appearing on your new schedule  on the Timeline screen you can compare the timestamp intervals for new reports compared to reports received before you made your changes as shown in the following figure. (To see new reports received while this screen is being viewed, click the Sync. status icon.)

timestamps_2.png

 

7.When you’re ready to stop sending data:

# app stop redSensorToCloud 

Note:   redSensorToCloud automatically closes the data connection, so you do not need to use "cm data connect -1".

A.1.3 Update and Install a New Application

When you installed Legato, sample application files were also stored. In this section, you will build and then install the "hello world" application on the mangOH Red’s CF3 module.

Build (compile) an application on the dev machine and install it on the CF3 module:

1.On the dev machine, open a new terminal window.

2.Configure the window for development:

$ cfglegato 

3.Change directory to the sample application directory for Hello World:

$ cd $LEGATO_ROOT/apps/sample/helloWorld 

4.Compile the application. (Valid module series are listed in the $LEGATO_ROOT/Makefile  wp750x, wp85, wp76xx, wp77xx)

$ make wp76xx     (Or use "make" with no parameters to build all distributions.)

Note:   This ’make’ command uses the Makefile in the current directory to build only the sample application. It does not build the entire system like the ’make’ command in Update an Installed Application.

5.Verify that the update file helloWorld.wp76xx.update was created:

$ ls -al 

41112261_Develop00290.jpg

 

6.Install the application on the mangOH Red’s CF3 module:

$ update helloWorld.wp76xx.update 192.168.2.2 

41112261_Develop00293.jpg

 

Note:   This application will remain on the CF3 module until you either specifically remove it, or until the next time you reinstall the system on the CF3 module.

Log in to the mangOH Red’s CF3 module and run the application:

1.Set up a window to show the application’s output (the "Hello World" application writes to a log file) as follows:

a.Open a new terminal window (referred to as LOG_TERM in this procedure).

b.Connect to the mangOH Red:

$ ssh root@192.168.2.2 

c.Watch the log file and show when a message from "hello world" appears:

# logread -f | grep "Hello" 

Note:   Nothing will appear to happen until you run the Hello World application in the next step. Leave this command running until after you see the Hello World output, then you can press Ctrl+C to cancel it and return to the command prompt.

2.Run the application:

a.Open another terminal window to run the application.

b.Connect to the mangOH Red:

$ ssh root@192.168.2.2 

c.Check that the application is installed:

# app status 

41112261_Develop00296.jpg

 

The "hello world" application should appear in the list with a status of ’running’. The application was built to run automatically; when you write your own applications, you can make them install without running, if you prefer.

d.Stop the application (so you can restart it and see the output):

# app stop helloWorld 

e.Run the application and see that it outputs a "Hello, world." message to the LOG_TERM terminal window:

# app start helloWorld 

41112261_Develop00299.jpg

 

41112261_Develop00302.jpg

 

f.(Optional) If you want to see information about the application, enter the following command:

# app info helloWorld 

41112261_Develop00305.jpg

 

g.In the LOG_TERM terminal window, press Ctrl+C to return to the command prompt.

You have now successfully compiled a working application, and installed, stopped, and run it on the module.

Note:   To learn more about the Legato development environment, visit http://legato.io/legato-docs/latest/.