Digi XB3-C-A2-UT series User Manual page 37

Smart modem
Table of Contents

Advertisement

Getting started with the XBee Smart Modem Development Kit
# If the RECV call returns 0 bytes, the socket has closed
if (len(data) == 0):
print("ERROR - socket has closed.
return 1
else:
print("Received {} bytes from client via socket.".format(len(data)))
print("Sending payload to modem...")
bytes_wr = ser.write(data)
print("Wrote {} bytes to modem".format(bytes_wr))
def main():
setup()
# Setup the serial port and socket
global clisock, svrsock
if (not clisock):
print("Awaiting ACCEPT on server sock...")
(clisock,cliaddr) = svrsock.accept()
print("Connection accepted on socket")
# Make thread for ComReader
comthread = threading.Thread(target=ComReaderThread)
comthread.start()
# Make thread for SockReader
sockthread = threading.Thread(target=SockReaderThread)
sockthread.start()
main()
Note
This script is a general TCP-UART proxy, and can be used for other applications or scripts that
use the TCP protocol. Its functionality is not limited to MQTT.
Note
You can easily copy and paste code from the online version of this Guide. Use caution with the
PDF version, as it may not maintain essential indentations.
This proxy script waits for an incoming connection on localhost (127.0.0.1), on port 17300. After
accepting a connection, and creating a socket for that connection (clisock), it creates two threads,
one that reads the serial or COM port that the XBee Smart Modem is connected to, and one that
reads the socket (clisock), that the MQTT client is connected to.
With:
The proxy script running
n
The MQTT client connected to the proxy script via localhost (127.0.0.1)
n
The XBee Smart Modem connected to the machine via USB and properly powered
n
AP, DL, and DE set correctly
n
the proxy acts as an intermediary between the MQTT client and the XBee Smart Modem, allowing the
MQTT client to use the data connection provided by the device.
Think of the proxy script as a translator between the MQTT client and the XBee Smart Modem. The
following figure shows the basic operation.
Digi XBee3 Cellular LTE-M Global Smart Modem User Guide
# Exit the thread to avoid a loop of 0-byte receptions
# Write payload to modem via UART/serial
# Accept a connection on 'svrsock' to open 'clisock'
# Start the thread
# Start the thread
Get started with MQTT
Exiting socket reader thread.")
# Accept an incoming connection
37

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the XB3-C-A2-UT series and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Xbee3 cellular lte-m

Table of Contents