Digi International Inc XB3C1 Manual Do Utilizador

Página de 146
Getting started with the XBee Smart Modem Development Kit
Get started with MQTT
Digi XBee3 Cellular LTE Cat 1 Smart Modem User Guide
38
The thread that reads the serial port forwards any data received onward to the client socket, and the
thread reading the client socket forwards any data received onward to the serial port. This is
represented in the figure above.
The proxy script needs to be running before running an MQTT publish or subscribe script.
1. With the proxy script running, run the subscribe example from
, but change the connect line from client.connect("m2m.eclipse.org",
1883, 60) to client.connect("127.0.0.1", port=17300, keepalive=20). This connects the
MQTT client to the proxy script, which in turn connects to a broker via the XBee Smart
Modem’s internet connection.
2. Run the publish example from
in a third Python
instance (while the publish script is running you will have three Python scripts running at the
same time).
The publish script runs over your computer’s normal internet connection, and does not use the XBee
Smart Modem. You are able to see your published message appear in the subscribe script’s output
once it is received from the broker via the XBee Smart Modem. If you watch the output of the proxy
script during this process you can see the receptions and transmissions taking place.
The proxy script must be running before you run the subscribe and publish scripts. If you stop the
subscribe script, the socket closes, and the proxy script shows an error. If you try to start the proxy
script after starting the subscribe script, you may also see a socket error. To avoid these errors, it is
best to start the scripts in the correct order: proxy, then subscribe, then publish.