The AWP Toolkit: Building the sample agent

The AWP Toolkit is described and can be downloaded from here.  It includes documentation and C source for the Axeda Wireless Protocol as well as a sample agent.  In this tutorial, we'll build the protocol library and sample device application from the source.

The first step is to download and unpack the toolkit.  You'll see the API documentation, as well as another compressed archive (lib) containing the source files. Refer to the Resource Library for additional documentation, including the AWP Toolkit Reference and the Axeda Wireless Protocol Technical Reference.

Unpack the C source libraries (AWPToolkit-[revision#].tar.gz file) and open up the src directory:

Building the toolkit and sample agent requires a C++ compiler.  The toolkit provides files to support for three kinds of compiler:

  • M2MToolkit.dsw, a project file for Visual Studio 6 which can be used for versions of Visual Studio earlier than Visual Studio 2008;
  • M2mToolkit_vc2008.sln, a project file for Visual Studio 2008 which can be also be used for Visual Studio 2010;
  • Makefile for building the library and sample agent using gcc (i.e., on Unix systems)

Building the toolkit in Visual Studio

All releases of Visual Studio from VS 6 on are supported, and all editions including Visual Studio Express.  The instructions that follow might be slightly different depending on your version of Visual Studio.

The Visual Studio terminology may not be obvious if you have not used it before.  We have grouped the "solution" into six "projects" represented by the six folders within the src folder.  In older releases of Visual Studio, a solution was referred to as a "workspace".  Two of the six projects, agent and awpsim, represent different sample executables.

The first thing to do is to start Visual Studio and open the correct solution file for your version.  Go to File --> Open --> Project / Solution and open either M2MToolkit.dsw or M2mToolkit_vc2008.sln.

If you are running VS 6 or VS2008, the solution will open immediately.  Otherwise, the "Visual Studio Conversion Wizard" will open in order to convert the solution to your version of Visual Studio -- you can go ahead and do that, accepting the defaults from the wizard.  You can ignore the warnings generated by the wizard.

One small detail:  since the solution has two executables, you have to tell Visual Studio which one you want to run.  Take a look at the Solution Explorer.  (If it's not open, open it with control-alt-L.)  It will look like one of these screenshots:

Make sure the agent project is bolded

We'll try out the agent first, so make sure it's the agent which is bolded.  If it's not, right click on it and select 'Set as StartUp Project'.

Before you run the agent, you need edit the agent to specify your model and asset.  Open up the agent project and double-click on the source file, agent.c:

Locate the agent source file

In the agent.c source, locate main() and the line:

ret = M2M_Context_setDevice(m2mContext, "user_domain_model",
"asset1", "myCompany", timeout);

(I've wrapped the line to fit this page.)  Change "user_domain_model" to your model, which is based on your email address.  It will have the form "bob_acme_com_model".  Also, change "myCompany" to "Root::Default Organization".  The line will look something like this:

ret = M2M_Context_setDevice(m2mContext, "bob_acme_com_model",
"asset1", "Root::Default Organization", timeout);

The next step is to build the solution.  Select 'Build Solution' from the Debug menu.  This will generate a considerable number of messages in the output window as each individual file is compiled and the projects are built.  You should see the message:

========== Build: 6 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

in the output window.  (The output window will open automatically if for some reason it is closed when you start the build.)

You're now ready to run the agent.  Just select 'Start Debugging' from the Debug menu and a console window will open and start displaying diagnostic output:

The numbers by default will increment up to 1000 or if you uncomment the //double value = (double)(rand()%100); line, your values will be randomized.

You can stop the agent by clicking the [X] close button at the upper right of the window.

To see what you just did, you can use the Get Started application, or log in to the platform.  Skip to "Verifying the data sent by the agent", below, for details.

Building the toolkit on a Unix system

If you're not already there, go to the src directory.

Make the changes explained above to cutomize agent.c for your model and organization.

Type make.

Type ./agent to run the agent.  You will see the same list of random temperatures shown above for the Visual Studio output.

Verifying the data sent by the agent

Log in to the platform and click on the service tab.  You will see a list of your assets:

List of your assets

Click on the text "asset1" and you will drill down to a summary of asset1.  On that screen, click on the "Historical" link at the top right of the Data pane:

The data pane

You will see the data that was sent by the agent, latest first:

A list of data values, most recent first