Raspberry Pi
The following example shows how to connect GUI-O application with Raspberry Pi in MQTT (IoT) mode. Secure connection using SSL/TLS is supported.
Raspberry Pi uses its own Linux-based operating system (Raspberry Pi OS), which significantly simplifies some tasks and enables using high-level (interpreted) programming languages such as Python.
Page contents
Setting up Raspberry Pi OS
This example uses Raspberry Pi 2 board, but any other Raspberry Pi board that has internet capabilities (Wired or Wireless) can be used.
Prerequisites
MicroSD card (using an adapter or card reader for connection with PC)
Download Raspberry Pi Imager based on your operating system (Ubuntu, Windows or macOS)
Step 1: Write image to microSD card using Raspberry Pi Imager
Open Raspberry Pi Imager (see image below)
Select "Choose OS" and select Raspberry Pi OS (32-bit), which is the recommended option
Select "Choose storage" and select your microSD card
Press the settings button (lower-right corner)
Enable "Set username and password" and set both then press "Save"
Finally, select "Write" and wait for the operation to complete
Step 2: Powering on Raspberry Pi
Insert the microSD card into Raspberry Pi
Connect Raspberry Pi to external monitor (TV or PC) via HDMI output port
Connect USB keyboard and USB mouse to Raspberry Pi
Power on the Raspberry Pi and wait for the initial setup to complete (Raspberry Pi might reboot)
Raspberry Pi & Arduino & GUI-O basic example
The following example shows basic interaction between GUI-O application and Raspberry Pi in MQTT (IoT) communication mode. Secure connection using SSL/TLS is enabled by default.
Step 1: Connect the components
Connect the components as shown in the schematic below.
Step 2: Create tokens for MQTT communication
Open GUI-O application and select "Add" from the top-right corner of the home screen
Select "IoT (Create device)" and add a new device (specifying arbitrary name and optional user name)
After adding a device, note the In and Out tokens which are required in Step 4 (tokens can be shared via email by pressing the "Share" icon)
Step 3: Install required Python modules
IMPORTANT: Your Raspberry Pi should be connected to the internet
Open the terminal on your Raspberry Pi and install Eclipse Paho MQTT Python client library by entering the following command:
$ pip install paho-mqtt
Step 4: Setup and run the Python script
IMPORTANT: Your Raspberry Pi should be connected to the internet
Download the RPiMqtt.zip package to your PC and extract the archive
Open the RPiMqtt.py script and set the In and Out tokens generated in Step 2
Secure connection can be disabled by setting the useTls variable to False (at the beginning of the script)
Copy the modified RPiMqtt.py script and the ca.crt certificate (if useTls is enabled) to your Raspberry Pi (e.g., using a USB flash drive)
Open the terminal on your Raspberry Pi, navigate to script location and run the script by entering the following command:
$ python ./RPiMqtt.py
Step 5: Using GUI-O application to interact with Raspberry Pi
Open GUI-O application and select "Connect" from the top-left corner of the home screen
Tap on the device created in Step 2
Wait for successful connection and try the example
Notes
The RPiMqtt.py script can be terminated by pressing "Ctrl + C" keys
Raspberry Pi OS supports connecting via Serial port, SSH or VNC (this can be configured under "Preferences -> Raspberry Pi Configuration")
VNC is perfect for controlling your Raspberry Pi without requiring the use of external monitor, USB keyboard or USB mouse
Connect . Create . Control