XBee connection examples
Get started with CoAP
Digi XBee3 Cellular LTE-M/NB-IoT Global Smart Modem User Guide
52
n
Method: GET
n
URI: example
n
Given message token: test
1. Click the
Consoles working mode
button
on the toolbar to add a customized packet.
2. From the AT console, click the
Add new packet button
in the Send packets dialog. The
Add new packet
dialog appears.
3. Click the
HEX
tab and type the name of the data packet:
GET_EXAMPLE
.
4. Copy and past the following text into the
HEX
input tab:
44 01 C4 09 74 65 73 74 B7 65 78 61 6D 70 6C 65
This is the CoAP protocol message decomposed by bytes to perform a GET request on an
example URI with a token test.
5. Click
Add packet
.
6. Click the
Open
button
.
7. Click
Send selected packet
. The message is sent to the public CoAP server configured in
. A response appears in the Console log. Blue text is the query, red text is
the response.
The payload is
Get to uri: example
, which specifies that this is a successful CoAP GET to URI end
example, which was specified in the query.
Click the
Close
button to terminate the serial connection.
Example: use Python to generate a CoAP message
This example illustrates how the CoAP protocol can perform GET/POST/PUT/DELETE requests
similarly to the HTTP protocol and how to do this using the XBee Smart Modem. In this example, the
XBee Smart Modem talks to a CoAP Digi Server. You can use this client code to provide an abstract
wrapper to generate a CoAP message that commands the XBee Smart Modem to talk to the remote
CoAP server.
Note
It is crucial to configure the XBee Smart Modem settings. See
and follow
the steps. You can target the IP address to a different CoAP public server.
1. Install Python 2.7. The Installation guide is located at:
2. Download and install the CoAPthon library in the python environment from
.
3. Download these two .txt files:
and
. After you download them, open the
files in a text editor and save them as .py files.
4. In the folder that you place the Coap.py and CoapParser.py files, press
Shift
+
right-click
and
then click
Open command window
.
5. At the command prompt, type
python Coap.py
and press
Enter
to run the program.
6. Type the USB port number that the XBee Smart Modem is connected to and press
Enter
. Only
the port number is required, so if the port is COM19, type 19.