Digi XBee 3 Cellular LTE-M User Manual page 78

Smart modem
Table of Contents

Advertisement

Examples: IOT protocols with transparent mode
UART/serial
def main():
setup()
global clisock, svrsock
if (not clisock):
print("Awaiting ACCEPT on server sock...")
(clisock,cliaddr) = svrsock.accept()
connection
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
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 XBee® 3 Cellular LTE-M/NB-IoT Global Smart Modem User Guide
print("Sending payload to modem...")
bytes_wr = ser.write(data)
print("Wrote {} bytes to modem".format(bytes_wr))
# Setup the serial port and socket
# Accept a connection on 'svrsock' to open 'clisock'
# Start the thread
# Start the thread
# Write payload to modem via
# Accept an incoming
online version of this
guide. Use caution with the
Get started with MQTT
78

Advertisement

Table of Contents
loading

This manual is also suitable for:

Xbee 3 cellular nb-iot

Table of Contents