Testing MQTT between multiple devices - d-sanchezl/xware GitHub Wiki

Once MQTT has been installed in at least two devices, cross-device communications can be tested. This test is very important, as it will allow a user to know if any XWare or otherwise MQTT errors come from an error in utilization or an underlying networking issue.

The next section details testing between two physical devices (e.g. two Raspberry Pi's, one Raspberry, and one Windows). If you wish to use a connection between a virtual Raspberry client and its Windows/Linux host, first enable bridged networking in your virtual machine.

Between two physical devices

  1. Enable the MQTT server in the device you desire. If unsure, the device with the highest processing capabilities should act as a server, while low-powered devices should be gateways (devices where sensor data is gathered to be later sent to the server).
  • If the server is a Raspberry Pi, nothing needs to be done - the MQTT server is active by default. If the server is a Windows machine, activate the server in a Command Prompt as shown here.
  1. Activate a subscription in one device in a command prompt/terminal, with for example:
mosquitto_sub -h [IPADRESS] -t "Test"
  • In the [IPADRESS] field, type the IP address of the device where the server is located. On Linux, verify this IP address by hovering your mouse cursor over the Networks icon in the top-right corner of the screen, or by typing ifconfig on a terminal. On Windows, use ipconfig on a different command prompt window.

  • If the device with the server is the local device, and this device is a Raspberry Pi, you can type localhost instead of the IP address. Windows requires the full IP, even if it is the IP of the machine itself.

  1. Publish a message to this topic from a different device, opening a command prompt/terminal there and typing:
mosquitto_pub -h [IPADRESS] -t "Test" -m "This message comes from another device"
  1. If the subscribed device receives the message, cross-device communication has been successfully tested. Otherwise, try these troubleshooting steps:

Troubleshooting

  • If the MQTT server is running on a Windows machine, make sure to allow the mosquitto program to communicate through your firewall.

  • Make sure that MQTT pub/sub functionality works in a single device, by using the previous commands on two command windows inside a single device.

  • Make sure that both devices are connected to the same network (e.g. they are both connected to the same WiFi network).

  • Try manually typing the local IP address in the Server device instead of using the "localhost" keyword.

Bridging a VM and its host

  • For VMWare users: While running your Raspberry virtual machine, click on Player -> Manage -> Virtual Machine Settings. Then select Network Adapter, and choose the "Bridged" option. This will place your Virtual Machine on the same network as the host, meaning that the virtual Raspberry can interface with the host as if it was a physical device connected through WiFi or Ethernet.
  • VirtualBox users: you can find a guide on the also popular VirtualBox here - simply select the "Bridged" option.

After this connection is established, follow the same steps as for two physical devices, found above.