Interacting with Waspmote

Receiving XBee frames with Waspmote Gateway

Waspmote Gateway

This device allows to collect data which flows through the sensor network into a PC or device with a standard USB port. Waspmote Gateway will act as a "data bridge or access point" between the sensor network and the receiving equipment. This receiving equipment will be responsible for storing and using the data received depending on the specific needs of the application.

The receiving equipment can be a PC with Linux, Windows or Mac-OS, or any device compatible with standard USB connectivity. The gateway offers a male USB A connector, so the receiving device has to have a female USB A connector.

Once the Gateway is correctly installed, a new communication serial port connecting directly to the XBee module's UART appears in the receiving equipment, which allows the XBee to communicate directly with the device, being able to both receive data packets from the sensor network as well as modify and/or consult the XBee's configuration parameters.

Another important function worth pointing out is the possibility of updating or changing the XBee module's firmware.

LEDs

Four indicator LEDs are included in the Gateway:

  • USB power LED: indicates that the board is powered through the USB port

  • RX LED: indicates that the board is receiving data from the USB port

  • TX LED: Indicates that the board is sending data to the USB port

  • I/O 5 configurable LED: associate

The configurable LED connected to the XBee's I/O 5 pin can be configured either as the XBee's digital output or as the XBee's indicator of association to the sensor network.

Buttons

  • Reset: allows the XBee module to be reset

  • I/O - 0: button connected to the XBee's I/O pin 0

  • I/O - 1: button connected to the XBee's I/O pin 1

  • RTS - I/O - 6: button connected to the XBee's I/O pin 6

All the buttons connect each one of its corresponding data lines with GND with when pressed. None of these have pull-up resistance so it may be necessary to activate any of the XBee's internal pull-up resistances depending on the required use.

Linux receiver

When using Linux it is possible to use various applications to capture the input from the serial port. Libelium recommends to use the 'Cutecom' application.

Once the application is launched, the speed and the USB where Waspmote has been connected must be configured.

The speed that must be selected is 115200 bps which is the standard speed set up for Waspmote.

The USB where Waspmote has been connected must be added the first time this application is run, adding USB0, USB1, etc (up to the USB number of each computer) according to where Waspmote has been connected. For this, the 'Device' window must be modified so that if Waspmote is connected to USB0, this window contains '/dev/ttyUSB0'.

Once these parameters are configured, capture is started by pressing the 'Open Device' button.

Linux Sniffer

As well as using the terminal to see the sensor information, an application which allows this captured data to be dumped to a file or passed to another program to be used or checked has been developed.

File: "sniffer.c"

Compilation on Linux:

gcc sniffer.c -o sniffer

Examples of use:

  • Seeing received data: ./sniffer USB0

  • Dumping of received data to a file: ./sniffer USB0 >> data.txt

  • Passing received values to another program: ./sniffer USB0 | program

The speed used for the example is 19200 bps. The final speed will depend on the speed the XBee module has been configured with (default value 115200).

Code:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <termios.h> /* Terminal control library (POSIX) */

#define MAX 100

main(int argc, char *argv[])
{
    int sd=3;
    char *serialPort="";
    
char *serialPort0 = "/dev/ttyS0";
char *serialPort1 = "/dev/ttyS1";
char *USBserialPort0 = "/dev/ttyUSB0";
char *USBserialPort1 = "/dev/ttyUSBS1";
char valor[MAX] = \"\";
char c;
char *val;
struct termios opciones;
int num;
char *s0 = "S0";
char *s1 = "S1";
char *u0 = "USB0";
char *u1 = "USB1";

if(argc!=2)
{
    fprintf(stderr,"Usage: %s [port]\nValid ports: (S0, S1, USB0, USB1)\n",argv[0], serial-Port);
    exit(0);
}

if (!strcmp(argv[1], s0))
{
    fprintf(stderr,"ttyS0 chosen\n...");
    serialPort = serialPort0;
}

if (!strcmp(argv[1], s1))
{
    fprintf(stderr,"ttyS1 chosen\n...");
    serialPort = serialPort1;
}
if (!strcmp(argv[1], u0))
{
    fprintf(stderr,"ttyUSB0 chosen\n...");
    serialPort = USBserialPort0;
}
if (!strcmp(argv[1], u1))
{
    fprintf(stderr,"ttyUSB1 chosen\n...");
    serialPort=USBserialPort1;
}
if (!strcmp(serialPort, ""))
{
    fprintf(stderr, "Choose a valid port (S0, S1, USB0, USB1)\n", serialPort);
    exit(0);
}

if ((sd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY)) == -1)
{
    fprintf(stderr,"Unable to open the serial port %s - \n", serialPort);
    exit(-1);
}
else
{
    if (!sd)
    {
        sd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY);
    }
    //fprintf(stderr,"Serial Port open at: %i\n", sd);
    fcntl(sd, F_SETFL, 0);
}
    tcgetattr(sd, &opciones);
    cfsetispeed(&opciones, B19200);
    cfsetospeed(&opciones, B19200);
    opciones.c_cflag |= (CLOCAL | CREAD);
    /*No parity*/
    
    opciones.c_cflag &= ~PARENB;
    opciones.c_cflag &= ~CSTOPB;
    opciones.c_cflag &= ~CSIZE;
    opciones.c_cflag |= CS8;
    /*raw input:
     * making the applycation ready to receive*/
    opciones.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
    /*Ignore parity errors*/
    opciones.c_iflag |= ~(INPCK | ISTRIP | PARMRK);
    opciones.c_iflag |= IGNPAR;
    opciones.c_iflag &= ~(IXON | IXOFF | IXANY | IGNCR | IGNBRK);
    opciones.c_iflag |= BRKINT;
    /*raw output
     * making the applycation ready to transmit*/
    opciones.c_oflag &= ~OPOST;
    /*aply*/
    tcsetattr(sd, TCSANOW, &opciones);
    int j = 0;
    while(1)
    {
        read(sd, &c, 1);
        valor[j] = c;
        j++;
        
        // We start filling the string until the end of line char arrives
        // or we reach the end of the string. Then we write it on the screen.
        
        if ((c=='\n') || (j==(MAX-1)))
        {
            int x;
            for (x=0; x\<j; x++)
            {
                write(2, &valor[x], 1);
                valor[x] = '\0';
            }
            j = 0;
        }
    }
    close(sd);
}

The code can be downloaded from: http://www.libelium.com/development/waspmote

Windows receiver

If Windows is used, the application 'Hyperterminal' can be used to capture the output of the serial port.

This application can be found installed by default in 'Start/Programs/Accessories/Communication', but if it is not available it can be downloaded from: http://hyperterminal-private-edition-htpe.en.softonic.com/

Once this application is launched the connection must be configured. The first step is to give it a name:

The next step is to specify the port on which Waspmote has been connected, in this case the system recognizes it as 'COM9', (this will vary on each computer):

The next step is to specify the speed and configuration parameters:

Once these steps have been performed connection with Waspmote has been established, and listening to the serial port begins.

Mac-OS receiver

If Mac OS X is used (version later than 10.3.9) the application 'ZTERM' can be used to capture the serial port output. This application can be downloaded from: http://homepage.mac.com/dalverson/zterm/

This application is configured automatically, establishing the USB on which Waspmote has been connected and the speed.

The following image shows this application capturing Waspmote's output, while the example code 'Waspmote Accelerator Basic Example' is run.

Last updated