Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions examples/communication/ip/ReceiveIPDataSample/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Introduction
------------
This sample Java application shows how IP data messages are received from
another XBee device connected to the Internet.

The application prints the received IP data to the standard output in ASCII
and hexadecimal formats after the sender IP address.

NOTE: This example uses the Wi-Fi device (WiFiDevice) class, but it can be
applied to other Internet capable XBee device classes such as
CellularDevice.


Files
-----
* com.digi.xbee.api.receiveipdata.MainApp.java:
Main application class. It instantiates a Wi-Fi device and establishes a
serial connection with it.

* com.digi.xbee.api.receiveipdata.MyIPDataReceiveListener.java:
Class that handles the received IP data messages.


Requirements
------------
To run this example you will need:

* At least two XBee Wi-Fi radios in API mode and their corresponding carrier
boards (XBIB or equivalent).
* The XCTU application (available at www.digi.com/xctu).


Example setup
-------------
1) Plug the XBee radios into the XBee adapters and connect them to your
computer's USB or serial ports.

2) Ensure that the modules are in API mode and connected to the same access
point.
For further information on how to perform this task, read the
'Configuring Your XBee Modules' topic of the Getting Started guide.

3) Set the port and baud rate of the receiver XBee radio in the MainApp
class.
If you configured the modules in the previous step with the XCTU, you
will see the port number and baud rate in the 'Port' label of the device
on the left view.


Running the example
-------------------
First, build and launch the application. Then, you need to send a data frame
to the receiver (local) module from another device. Follow the steps below to
do so:

1) Launch the XCTU application.

2) Add the sender (remote) XBee module to the XCTU, specifying its port
settings.

3) Once the module is added, change to the 'Consoles' working mode and
open the serial connection.

4) Create and add a frame using the 'Frames Generator' tool with the
following parameters:

- Protocol: Select the protocol of your device.
- Frame type: 0x20 - TX IPv4
- Frame ID: 01
- IPv4 32-bit dest. address: The IP address ('MY') of the receiver module
in hexadecimal format.
- 16-bit dest. port: The port number ('C0') of the receiver module,
26 16 by default.
- 16-bit source port: 00 00
- Protocol: TCP or UDP.
- Transmit options: 00
- RF data (ASCII): Hello XBee!

5) Send this frame by selecting it and clicking the 'Send selected Frame'
button.

When the IP data frame is sent, verify that a line with the IP address and
the data included in the 'RF data' field is printed out in the console of the
launched application:

From XXX.XXX.XXX.XXX >> 48 65 6C 6C 6F 20 58 42 65 65 21 | Hello XBee!

- Where XXX.XXX.XXX.XXX is the IP address of the remote XBee device that
sent the IP data frame.
50 changes: 50 additions & 0 deletions examples/communication/ip/ReceiveIPDataSample/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.digi.xbee</groupId>
<artifactId>xbjlib-parent</artifactId>
<version>1.1.1</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>receive-ip-data-sample</artifactId>
<packaging>jar</packaging>

<name>Receive IP Data Sample</name>

<properties>
<rxtx.native.libs.dir>rxtx-native-libs</rxtx.native.libs.dir>
</properties>

<build>
<sourceDirectory>src</sourceDirectory>
<directory>../../../target/examples/communication/ip/ReceiveIPDataSample</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec.maven.version}</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Djava.library.path=${project.build.directory}/../../../${rxtx.native.libs.dir}</argument>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>com.digi.xbee.api.receiveipdata.MainApp</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.digi.xbee</groupId>
<artifactId>xbjlib</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2016 Digi International Inc.,
* All rights not expressly granted are reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
* =======================================================================
*/
package com.digi.xbee.api.receiveipdata;

import com.digi.xbee.api.WiFiDevice;
import com.digi.xbee.api.exceptions.XBeeException;

/**
* XBee Java Library Receive IP Data sample application.
*
* <p>This example registers a listener to manage the received IP data.</p>
*
* <p>For a complete description on the example, refer to the 'ReadMe.txt' file
* included in the root directory.</p>
*/
public class MainApp {

/* Constants */

// TODO Replace with the serial port where your receiver module is connected.
private static final String PORT = "COM1";
// TODO Replace with the baud rate of you receiver module.
private static final int BAUD_RATE = 9600;

/**
* Application main method.
*
* @param args Command line arguments.
*/
public static void main(String[] args) {
System.out.println(" +--------------------------------------------+");
System.out.println(" | XBee Java Library Receive IP Data Sample |");
System.out.println(" +--------------------------------------------+\n");

WiFiDevice myDevice = new WiFiDevice(PORT, BAUD_RATE);

try {
myDevice.open();

myDevice.addIPDataListener(new MyIPDataReceiveListener());

System.out.println("\n>> Waiting for data...");

} catch (XBeeException e) {
e.printStackTrace();
myDevice.close();
System.exit(1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2016 Digi International Inc.,
* All rights not expressly granted are reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
* =======================================================================
*/
package com.digi.xbee.api.receiveipdata;

import com.digi.xbee.api.listeners.IIPDataReceiveListener;
import com.digi.xbee.api.models.IPMessage;
import com.digi.xbee.api.utils.HexUtils;

/**
* Class to manage the IP received data that was sent by other modules.
*
* <p>Acts as an IP data listener by implementing the
* {@link IIPDataReceiveListener} interface, and is notified when new IP data
* for the module is received.</p>
*
* @see IIPDataReceiveListener
*
*/
public class MyIPDataReceiveListener implements IIPDataReceiveListener {
/*
* (non-Javadoc)
* @see com.digi.xbee.api.listeners.IIPDataReceiveListener#ipDataReceived(com.digi.xbee.api.models.IPMessage)
*/
@Override
public void ipDataReceived(IPMessage ipMessage) {
System.out.format("From %s >> %s | %s%n", ipMessage.getIPAddress().getHostAddress(),
HexUtils.prettyHexString(HexUtils.byteArrayToHexString(ipMessage.getData())),
ipMessage.getDataString());
}
}
89 changes: 89 additions & 0 deletions examples/communication/ip/SendIPDataSample/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Introduction
------------
This sample Java application shows how to send IP data from an IP device to
another one connected to the Internet using the XBee Java Library.

The application sends IP data to another Wi-Fi device on the network with a
specific IP address and port number.

NOTE: This example uses the Wi-Fi device (WiFiDevice) class, but it can be
applied to other Internet capable XBee device classes such as
CellularDevice.


Files
-----
* com.digi.xbee.api.sendipdata.MainApp.java:
Main application class. It instantiates a Wi-Fi device, establishes a
serial connection with it and sends the IP data to the XBee device with
the IP address and port specified. Finally it prints out the result of the
sent operation.


Requirements
------------
To run this example you will need:

* At least two XBee Wi-Fi radios in API mode and their corresponding carrier
boards (XBIB or equivalent).
* The XCTU application (available at www.digi.com/xctu).


Example setup
-------------
1) Plug the XBee radios into the XBee adapters and connect them to your
computer's USB or serial ports.

2) Ensure that the modules are in API mode and connected to the same access
point.
For further information on how to perform this task, read the
'Configuring Your XBee Modules' topic of the Getting Started guide.

3) Set the port and baud rate of the sender (local) XBee radio in the
MainApp class.
If you configured the modules in the previous step with the XCTU, you
will see the port number and baud rate in the 'Port' label of the device
on the left view.

4) Set the destination IP address and port number in the MainApp class.
You can find them by reading the 'MY' and 'C0' settings of the
destination XBee device with XCTU.
Note that the value of the 'C0' setting has hexadecimal format, so you
have to convert it to decimal before setting it in the MainApp class.


Running the example
-------------------
First, build the application. Then, you need to set up XCTU to see the data
received by the remote XBee device. Follow these steps to do so:

1) Launch the XCTU application.

2) Add the remote XBee module to the XCTU, specifying its port settings.

3) Switch to the 'Consoles' working mode and open the serial connection
so you can see the data when it is received.

Finally, launch the sample application, some IP data is sent to the configured
remote XBee device. When that happens, a line with the result of the operation
is printed to the standard output:

Sending data to XXX.XXX.XXX.XXX:XXXX >> 48 65 6C 6C 6F 20 58 42 65 65 21 | Hello XBee!... Success

- Where XXX.XXX.XXX.XXX is the IP address address of the remote XBee device
and XXXX its port number.

Verify that in the XCTU console a new RX IPv4 frame has been received by the
remote XBee device. Select it and review the details, some of the details
will be similar to:

- Start delimiter: 7E
- Length: Variable
- Frame type: B0 (RX IPv4)
- Source address: The XBee sender's IP address.
- Destination port: The configured port number.
- Source port: A random port chosen by the sender module.
- Protocol: 01 (TCP)
- Status: 00 (Reserved)
- RF data: 48 65 6C 6C 6F 20 58 42 65 65 21
Hello XBee!
50 changes: 50 additions & 0 deletions examples/communication/ip/SendIPDataSample/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.digi.xbee</groupId>
<artifactId>xbjlib-parent</artifactId>
<version>1.1.1</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>send-ip-data-sample</artifactId>
<packaging>jar</packaging>

<name>Send IP Data Sample</name>

<properties>
<rxtx.native.libs.dir>rxtx-native-libs</rxtx.native.libs.dir>
</properties>

<build>
<sourceDirectory>src</sourceDirectory>
<directory>../../../target/examples/communication/ip/SendIPDataSample</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec.maven.version}</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Djava.library.path=${project.build.directory}/../../../${rxtx.native.libs.dir}</argument>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>com.digi.xbee.api.sendipdata.MainApp</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.digi.xbee</groupId>
<artifactId>xbjlib</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
Loading