Example: Use Python To Generate A Coap Message - Digi XBee 3 Cellular LTE-M User Manual

Smart modem
Table of Contents

Advertisement

Examples: IOT protocols with transparent mode
Method: GET
n
URI: example
n
Given message token: test
n
1. Click the Consoles working mode button
2. From the AT console, click the Add new packet button
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
Configure the
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
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: python.org/downloads/.
2. Download and install the CoAPthon library in the python environment from
pypi.python.org/pypi/CoAPthon.
3. Download these two .txt files:
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.
Digi XBee® 3 Cellular LTE-M/NB-IoT Global Smart Modem User Guide
.
device. A response appears in the Console log. Blue text is the query, red text is
Coap.txt
and CoapParser.txt. After you download them, open the
on the toolbar to add a customized packet.
in the Send packets dialog. The
Configure the device
Get started with CoAP
and follow
69

Advertisement

Table of Contents
loading

This manual is also suitable for:

Xbee 3 cellular nb-iot

Table of Contents