<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Episode 4: Resource downloader]]></title><description><![CDATA[<p dir="auto">This is a simple example that shows how to download videos and images from online resources, which can be incorporated into any application.</p>
<p dir="auto"><strong>I will be using GUI-O IoT (MQTT) connection, but the example can be easily be ported to other connection types.</strong></p>
<p dir="auto"><strong>Software prerequisites:</strong></p>
<ul>
<li>
<p dir="auto">Arduino IDE (<a href="https://www.arduino.cc/en/software" rel="nofollow ugc">https://www.arduino.cc/en/software</a>)</p>
</li>
<li>
<p dir="auto">ESP32 Arduino board support, if using ESP32 based board (see <a href="https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html" rel="nofollow ugc">https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html</a>)</p>
</li>
<li>
<p dir="auto">Arduino Client for MQTT(<a href="https://github.com/knolleary/pubsubclient" rel="nofollow ugc">https://github.com/knolleary/pubsubclient</a>)<br />
You can follow the setup instructions or directly download and include the <strong><a href="https://drive.google.com/uc?export=download&amp;id=1yRJCDFR2xQDodyIA_lqKfcYdU6pAFy1C" rel="nofollow ugc">PubSubClient.zip</a></strong> library within the Arduino IDE (Sketch -&gt; Include Library -&gt; Add .ZIP library)</p>
</li>
<li>
<p dir="auto">GUI-O design tool (<a href="https://www.gui-o.com/design-tool" rel="nofollow ugc">https://www.gui-o.com/design-tool</a>)</p>
</li>
<li>
<p dir="auto">GUI-O application (<a href="https://play.google.com/store/apps/details?id=com.guio.guioapp" rel="nofollow ugc">https://play.google.com/store/apps/details?id=com.guio.guioapp</a>)</p>
</li>
<li>
<p dir="auto">For additional information about the GUI-O application, download the developer manual from <a href="https://www.gui-o.com/" rel="nofollow ugc">https://www.gui-o.com/</a></p>
</li>
</ul>
<p dir="auto"><strong>Components needed:</strong></p>
<ul>
<li>ESP32-WROOM-32 (or any other Arduino supported WiFi capable board; see <a href="https://github.com/knolleary/pubsubclient#compatible-hardware" rel="nofollow ugc">https://github.com/knolleary/pubsubclient#compatible-hardware</a> for compatible hardware)</li>
</ul>
<p dir="auto"><strong>The entire tutorial is split into various steps. All necessary information is given in each step</strong>.</p>
<h3>0. DESIGN THE GUI (optional)</h3>
<p dir="auto">The best way to create a GUI layout is to use GUI-O live designer tool.</p>
<p dir="auto">Note that the Arduino source code already includes the necessary commands, so this step is not needed, unless you want to make some visual adjustments. If you make adjustments, please include the generated ASCII code in the Arduino source code (see section 3. MODIFY AND UPLOAD THE SOURCE CODE).</p>
<p dir="auto">First, you need to establish a TCP/IP connection between the designer tool and GUI-O application:</p>
<ol>
<li>Determine the local IP address of your PC's network interface (WiFi or Ethernet)</li>
</ol>
<ul>
<li>Under Windows, open the command prompt, enter <code>ipconfig</code> and press Enter</li>
<li>Under Linux, open the terminal, enter <code>ifconfig</code> and press Enter</li>
</ul>
<ol start="2">
<li>
<p dir="auto">Open GUI-O application and open settings menu. Select "Connections -&gt; Ethernet" and create a new device with IP address (determined from 1.) and any port between 49152 - 65535</p>
</li>
<li>
<p dir="auto">Open GUI-O designer and select "TCP/IP connection" tab. Set the IP address and port. Both values must match the device settings created within the GUI-O application. Click "Start server" button.</p>
</li>
<li>
<p dir="auto">Within the GUI-O application, tap the created device and wait for successful connection.</p>
</li>
<li>
<p dir="auto">In the GUI-O designer, select "File -&gt; Load designer file" and load the <a href="https://drive.google.com/uc?export=download&amp;id=1XtX-eaSz3huthTYf3ryMkqz7Fos9eawy" rel="nofollow ugc">ResourceDownloader.gdf</a> design file. Make the desired adjustments, if necessary. Copy / replace the GUI-O commands into the Arduino source code (see section 3. MODIFY AND UPLOAD THE SOURCE CODE).</p>
</li>
</ol>
<h3>1. CREATE A UNIQUE MQTT CHANNEL</h3>
<p dir="auto">Open GUI-O application and navigate to settings menu. Select "Connections -&gt; IoT" and add a new device. After adding the device, note the <strong>In</strong> and <strong>Out</strong> token (you can share this tokens e.g., to your e-mail by pressing the "share" button).</p>
<p dir="auto">Finally, press "Connect" menu entry to establish the connection with the MQTT server.</p>
<h3>2. MODIFY AND UPLOAD THE SOURCE CODE</h3>
<p dir="auto">The source code has inline comments, describing the important parts of the code. You can copy the source code from the snippet below, or download it <a href="https://drive.google.com/uc?export=download&amp;id=1mGdb8z5MHfQVXUyWNwYCN1nHXUa0BGx0" rel="nofollow ugc">here</a>.</p>
<p dir="auto">The only thing that needs to be done is to set the <strong>ssid</strong> and <strong>password</strong> of your router and the unique <strong>In</strong> and <strong>Out</strong> channels that were generated by the GUI-O application (see section 2. CREATE A UNIQUE MQTT CHANNEL).</p>
<p dir="auto">After setting these values, upload the code to your board (make sure that the correct board and upload port are selected). Reset the board after upload.</p>
<pre><code>/*
 * GUI-O Resource downloader MQTT example (using ESP32-WROOM-32)
 *
 * Copyright (C) 2022, kl3m3n
 * last updated on 12.11.2022
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include &lt;WiFi.h&gt;
#include &lt;PubSubClient.h&gt;

static const char *ssid = "&lt;ssid&gt;"; // router name
static const char *pass = "&lt;pass&gt;"; // router password

static const char *mqttServer = "mqtt.gui-o.com";   // host name
static const char *mqttUser = "gui-o-mqtt-generic"; // user name
static const char *mqttPass = "lqXeZpv5VJyv0XBT";   // password

// IMPORTANT NOTE: if optional user name was specified when adding a new IoT device,
// the user name should also be included when setting the topics (e.g., "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/&lt;user_name&gt;")
static const char *Out = "&lt;Out&gt;"; // GUI-O app publish topic
static const char *In = "&lt;In&gt;";  // GUI-O app subscribe topic

// mqtt client
WiFiClient wiFiClient;
PubSubClient mqttClient(wiFiClient);

// forward declare functions for mqtt messages handling
void mqttCallback(char* topic, byte* message, unsigned int length);
void parseGuioMsg(const String &amp;msg);

void setup() {
  // debug output
  Serial.begin(115200);
  
  // connect WiFi (keep trying...)
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, pass);
  while(WiFi.status() != WL_CONNECTED) { 
    Serial.print(".");
    delay(500); 
  }
  
  Serial.println("WiFi connected!"); 
  
  // setup mqtt
  mqttClient.setServer(mqttServer, 1883);
  mqttClient.setCallback(mqttCallback);
}

void loop() {
  while(!mqttClient.connected()) {
    Serial.println("MQTT connecting...");

    // mqtt client id is the mac address (AABBCCDDEEFF)
    char mqttClientId[15];    
    uint8_t mac[6];
    WiFi.macAddress(mac);

    snprintf(mqttClientId, sizeof(mqttClientId), "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

    if(mqttClient.connect(mqttClientId, mqttUser, mqttPass)) {
      Serial.println("MQTT connected!");
      mqttClient.subscribe(&amp;Out[0]);
    }
    else {
      Serial.print("MQTT connection failed (");
      Serial.print(mqttClient.state());
      Serial.println(")! Retrying...");      
      delay(2500);
    }
  }
  mqttClient.loop();
}

// mqtt callback function
void mqttCallback(char* topic, byte* message, unsigned int length) {
  // build message string
  String msg;
  for(int i = 0; i &lt; length; i++) {
    msg += (char) message[i];
  }
  // parse message string
  parseGuioMsg(msg);
}

void parseGuioMsg(const String &amp;msg) {
  if(msg.startsWith("@init")) {
    Serial.println("GUI-O app is requesting INITIALIZATION!");

    // clear screen and set background
    mqttClient.publish(&amp;In[0], "@cls\r\n");
    mqttClient.publish(&amp;In[0], "@guis BGC:#FFFFFF\r\n");
    delay(100);

    // initialize GUI
    mqttClient.publish(&amp;In[0], "|LB UID:title X:50 Y:20 FSZ:4 FFA:\"font8\" TXT:\"Resource&lt;br&gt;downloader\"\r\n");
    mqttClient.publish(&amp;In[0], "|VI UID:fire X:50 Y:50 W:70 VP:\"https://i.imgur.com/lVwrTnZ.mp4\"\r\n");
    mqttClient.publish(&amp;In[0], "|IM UID:play X:30 Y:70 W:15 IP:\"https://i.imgur.com/Gs2ERbO.png\"\r\n");
    mqttClient.publish(&amp;In[0], "|IM UID:pause X:70 Y:70 W:15 IP:\"https://i.imgur.com/FXywHFH.png\"\r\n");
    mqttClient.publish(&amp;In[0], "|LB UID:details X:50 Y:90 FSZ:2 TXT:\"GUI-O resource downloader&lt;br&gt;demonstration by kl3m3n\"\r\n");
  }
  else if(msg.startsWith("@play")) {
    mqttClient.publish(&amp;In[0], "@fire PLS:1\r\n");
  }
  else if(msg.startsWith("@pause")) {
    mqttClient.publish(&amp;In[0], "@fire PLS:2\r\n");    
  }
}
</code></pre>
<h3>3. ESTABLISH CONNECTION</h3>
<p dir="auto">Make sure that the GUI-O application is connected to the MQTT server.<br />
Also make sure that the ESP32 board (or other Arduino supported board) is connected to the MQTT server (you can check this by observing the serial debug messages using the Arduino serial monitor).</p>
<p dir="auto"><strong>NOTE:</strong> make sure that you are connected to WiFi as the GUI-O app will require connection in order to download the resources. If mobile data connection is used, please open the settings menu and enable data usage from "General settings -&gt; Network usage -&gt; Use any network". The resources will be downloaded only once; after that, the resources will be loaded from local storage.</p>
<p dir="auto">Press the <strong>Initialize</strong> button (see image below) from the GUI-O application home screen.</p>
<p dir="auto"><img src="https://i.imgur.com/DDEHAR7l.jpg" alt="initialize_button.jpg" class=" img-fluid img-markdown" /></p>
<h3>4. THE RESULT</h3>
<p dir="auto">Image below shows the result (screen capture) on my Android device after pressing the "Initialize" button. The video playback state can be controlled with the "play" and "pause" buttons. Note that the buttons are also images downloaded from online resource.</p>
<p dir="auto"><img src="https://i.imgur.com/MzdoVyXl.jpg" alt="screen.jpg" class=" img-fluid img-markdown" /></p>
<hr />
<p dir="auto">If you have any questions or run into any problems, please let me know!</p>
<p dir="auto">Best regards,<br />
kl3m3n</p>
]]></description><link>https://forum.gui-o.com/topic/89/episode-4-resource-downloader</link><generator>RSS for Node</generator><lastBuildDate>Sun, 17 May 2026 05:45:40 GMT</lastBuildDate><atom:link href="https://forum.gui-o.com/topic/89.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 Nov 2022 09:59:14 GMT</pubDate><ttl>60</ttl></channel></rss>