<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Boussettaachraf on Medium]]></title>
        <description><![CDATA[Stories by Boussettaachraf on Medium]]></description>
        <link>https://medium.com/@boussettaachraf26?source=rss-4d5e294d6b98------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jaCBCYJXON1uqPtS</url>
            <title>Stories by Boussettaachraf on Medium</title>
            <link>https://medium.com/@boussettaachraf26?source=rss-4d5e294d6b98------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:30:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@boussettaachraf26/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I used Mqtt in Wordpress]]></title>
            <link>https://medium.com/@boussettaachraf26/how-i-used-mqtt-in-wordpress-30694ac09685?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/30694ac09685</guid>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Fri, 19 Jun 2026 13:35:48 GMT</pubDate>
            <atom:updated>2026-08-06T13:18:20.128Z</atom:updated>
            <content:encoded><![CDATA[<p>In this story I will show how I connected to MQTT Broker in our website and how we used it to manage the waiting Queue.</p><p>In this part I assume that you have already created an MQTT cluster on <a href="https://console.hivemq.cloud/clusters">hiveMq</a>.</p><p>Now I will demonstrate how to connect to your Mqtt Broker in wordpress and subscribe to the topics to show them finally in your website. Go to Wordpress dashboard and choose Design &gt; Theme &gt; Theme Editor there you can edit the active Theme</p><p>In functions.php:</p><pre>function load_mqtt_scripts() {<br><br>    // Load Paho MQTT library<br>    wp_enqueue_script(<br>        &#39;paho-mqtt&#39;,<br>        &#39;https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js&#39;,<br>        array(),<br>        null,<br>        false<br>    );<br><br>    // Load custom MQTT client script<br>    wp_enqueue_script(<br>        &#39;mqtt-client&#39;,<br>        get_stylesheet_directory_uri() . &#39;/mqtt-client.js&#39;,<br>        array(&#39;paho-mqtt&#39;),<br>        null,<br>        true<br>    );<br>}<br><br>add_action(&#39;wp_enqueue_scripts&#39;, &#39;load_mqtt_scripts&#39;);<br></pre><p>what this code is doing is to call load_mqtt_scripts everytime a page is loaded.</p><p>Now we need to add our script mqtt-client.js in the same folder as functions.php and make sure to update our mqtt username and password.</p><pre>document.addEventListener(&quot;DOMContentLoaded&quot;, function () {<br><br>    if (typeof Paho === &quot;undefined&quot;) {<br>        console.error(&quot;Paho library not loaded&quot;);<br>        return;<br>    }<br><br>    const broker = &quot;xxxxx.s1.eu.hivemq.cloud&quot;;<br>    const port = 8884;<br>    const path = &quot;/mqtt&quot;;<br>    const username = &quot;Myuser&quot;;<br>    const password = &quot;MyPass&quot;;<br><br>    const topicsData = {};   // store topic -&gt; value<br><br>    const client = new Paho.MQTT.Client(<br>        broker,<br>        port,<br>        path,<br>        &quot;wp-client-&quot; + Math.random()<br>    );<br><br>    client.onConnectionLost = function (response) {<br>        console.log(&quot;Connection lost:&quot;, response.errorMessage);<br>    };<br><br>    client.onMessageArrived = function (message) {<br><br>        const topic = message.destinationName;<br>        const value = message.payloadString;<br><br>        console.log(topic + &quot;:&quot;, value);<br><br>        topicsData[topic] = value;<br><br>        updateList();<br>    };<br><br>    function updateList() {<br><br>        const list = document.getElementById(&quot;mqtt-list&quot;);<br>        if (!list) return;<br><br>        list.innerHTML = &quot;&quot;;<br><br>        for (const topic in topicsData) {<br><br>            const li = document.createElement(&quot;li&quot;);<br>            li.textContent = topic + &quot;: &quot; + topicsData[topic];<br><br>            list.appendChild(li);<br>        }<br>    }<br><br>    client.connect({<br>        useSSL: true,<br>        userName: username,<br>        password: password,<br>        onSuccess: function () {<br><br>            console.log(&quot;Connected to MQTT&quot;);<br><br>            // subscribe to ALL topics<br>            client.subscribe(&quot;#&quot;);<br><br>        },<br>        onFailure: function (error) {<br>            console.error(&quot;Connection failed:&quot;, error);<br>        }<br>    });<br><br>});</pre><p>If you look at the function updateList, you might notice this line</p><pre>const list = document.getElementById(&quot;mqtt-list&quot;);</pre><p>This is exactly the magic link between the javascript and html page, so obviously what is missing now is to add this Element to the page needed.<br>So go to the page where you want to show the mqtt messages and simply add.</p><pre>&lt;ul id=&quot;mqtt-list&quot;&gt;&lt;/ul&gt;</pre><p>With that every time the page is loaded the MQTT messages sent by the publisher are shown</p><p>I hope that was helpful to people willing to use MQTT in their wordpress Projects.</p><p>Hope you enjoyed reading !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30694ac09685" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Start with jupyter notebook on VsCode]]></title>
            <link>https://medium.com/@boussettaachraf26/start-with-jupyter-notebook-on-vscode-9ea0c00547b8?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ea0c00547b8</guid>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Tue, 14 Apr 2026 07:02:10 GMT</pubDate>
            <atom:updated>2026-07-03T13:10:46.861Z</atom:updated>
            <content:encoded><![CDATA[<p>I find using Jupyter Notebook in VScode very handy to start playing around with python , in this short tutorial I share how easy it is to set it up.</p><p>1- Create and activate a virtual environment (Windows PowerShell):</p><pre>python -m venv .venv<br>.venv\Scripts\Activate.ps1</pre><p>2- Install everything:</p><pre>pip install -r requirements.txt<br># If you do not have requirements.txt yet, install packages manually, then generate it:<br>pip freeze &gt; requirements.txt</pre><p>3- Make the venv available to Jupyter:</p><pre>pip install ipykernel<br>python -m ipykernel install --name myenv - display-name &quot;Python (myenv)&quot;</pre><p>Short words about ipykernel and jupyter, a kernel is the process running in the background and executing the code when you run the cell, so jupyter is the interface and ipykernel executes the code.</p><p>4- In VS Code notebook, open the folder where you installed your environment and switch kernel to Python (myenv).</p><p>Now you are ready to execute your python code :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ea0c00547b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating QT Application with Yocto and Raspberrypi]]></title>
            <link>https://medium.com/@boussettaachraf26/creating-qt-application-with-yocto-and-raspberrypi-4adea16ba9c6?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/4adea16ba9c6</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[qt]]></category>
            <category><![CDATA[yocto]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Wed, 31 Dec 2025 08:05:57 GMT</pubDate>
            <atom:updated>2025-12-31T08:05:57.108Z</atom:updated>
            <content:encoded><![CDATA[<p>I developed a GUI Application using QT on my local ubuntu machine and now I want to deploy it to an embedded device. If this is what you want to do then this short story will give a step by step guide to do this.</p><p>I am using Raspberrypi 3b+ but the steps should also valid for other hardware Platform as well.</p><p>So Let’s begin !</p><p>The first step is creating the Qt Application, just open Qt creator and create your application I will be refering to it asmyapp. make sure that it is compiling and running on your PC, if that’ the case we are done with the first step.</p><p>In the second step we will focus on setting up yocto for building a complete image including the Qt Application. I assume that you already have cloned a yocto project and build a minimal image with it, if not take a look at this short <a href="https://medium.com/@boussettaachraf26/set-up-yocto-for-raspberry-pi-31b4a1ec4b10">story</a>.</p><p>Along with the other layers (meta-raspberrypi, meta-openembedded…) clone meta-qt6 from this Link : git://code.qt.io/yocto/meta-qt6.git.</p><p>So in the end you have following layers in your yocto project:</p><pre>build<br>meta-apps<br>meta-qt6<br>meta-raspberrypi<br>meta-openembedded<br>poky</pre><p>Third step is the creation of the Application layer.</p><pre>source poky/oe-init-build-env<br>bitbake-layers add-layer meta-apps</pre><p>bitbake will create a new layer and add it to your layer configuration conf/bblayers.conf.</p><p>Now in the new created layer meta-apps, create the folder for your recipe myapp, Add the source files from your tested Qt Application and last but not least add the recipe file myapp_1.0.bb. so in the end your layer looks as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*g6SKOTC2CC-Vyy9V2xlvtA.png" /></figure><p>Fourth step is to fill in the recipe file, the recipe file tells bitbake among others how to build the Application from the sources and install it.</p><pre>SUMMARY = &quot;My Qt Application&quot;<br>LICENSE = &quot;CLOSED&quot;<br><br>SRC_URI = &quot;file://main.cpp \<br>           file://Main.qml \<br>           file:CMakeLists.txt \<br>           &quot;<br><br>S = &quot;${WORKDIR}/sources&quot;<br>UNPACKDIR = &quot;${S}&quot;<br><br>inherit qt6-cmake<br><br>RDEPENDS:${PN} += &quot;qtbase qtdeclarative qtdeclarative-qmlplugins &quot;<br>DEPENDS += &quot;qtbase qtdeclarative qttools qtdeclarative-native &quot;<br><br>EXTRA_OECMAKE += &quot;-DCMAKE_BUILD_TYPE=Release&quot;</pre><p>SRC_URI contains the list of files of your projects, make sure to include all *.cpp, *.h ,*.qml, and CMakeLists.txt from your Application</p><p>inherit qt6-cmake : qt6-cmake comes from meta-qt6/classes/qt6-cmake.bbclass this class will inject variables and tasks do_configure, do_compile, do_installin your recipe so that you shouldn’t write them manually.</p><p>DEPENDS and RDEPENDS are respectively the compile and runtime dependencies of the package ;qtbaseis the qt core module, qtdeclarative is needed for QML and qttools is for QML Build tools, depending on your Application code, you might need more Dependencies.</p><p>Last step is to write the image recipe, where we include the qt Application, I added the image recipe in this path <strong>meta-raspberrypi/recipes-core/images/rpi-qt-image.bb</strong>, the image recipe looks as follow:</p><pre>DESCRIPTION = &quot;Qt Fullscreen Appliance Image&quot;<br>LICENSE = &quot;CLOSED&quot;<br><br>inherit core-image<br><br>IMAGE_INSTALL += &quot; \<br>qtbase \<br>qtdeclarative \<br>myapp \<br>ttf-dejavu-sans \<br>fontconfig \<br>&quot;<br><br># Remove desktop environments — pure embedded<br>IMAGE_FEATURES:remove = &quot;x11&quot;</pre><p>Here you need to add myappto the IMAGE_INSTALL variable. I also added ttf-dejavu and fontconfig these are the font recipes. If you don’t include them then your target won’t be able to draw the characters.</p><p>That&#39;s all , Lets build the image and run it in the target. The command used for building the image is bitbake rpi-qt-image. The application should be included in the filesystem :)</p><p>Before testing I want to tell few words about Qt Backends. Qt Application uses QPA, Qt Platform Abstraction, to display the GUI to the screen independently on the Platform. Different QPA could be used depending on the Application needs; Wayland, EGLFS, …</p><p>A common QPA is EGLFS which stands for Embedded GL Full screen, and used for rendering Full screen GUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/111/1*zTj_cPXUes7U7FX7wubyTg.png" /><figcaption>Qt Application to driver call</figcaption></figure><p>To select the backend we must set the environment variable QT_QPA_PLATFORM before running the appplication.</p><p>Allright now you know how to start your GUI on Full screen; Just flash your Image and start your board when the prompt comes up.<br>QT_QPA_PLATFORM=eglfs myApp</p><p>All right we are done!</p><p>I hope that was a quick and straight forward !</p><p>Enjoy developing your GUI !</p><p>If you have any questions leave me omments</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4adea16ba9c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running YOLO with raspberrypi and ov5647 camera]]></title>
            <link>https://medium.com/@boussettaachraf26/running-yolo-with-raspberrypi-and-ov5647-camera-c868746a1bf2?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/c868746a1bf2</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[yolov5]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Wed, 22 Oct 2025 08:24:42 GMT</pubDate>
            <atom:updated>2025-10-22T08:24:42.576Z</atom:updated>
            <content:encoded><![CDATA[<p>In this short story I share my experience running YOLOv5 model for object detection on the raspberrypi 3b+.</p><p>The goal of the application is to stream a video using ov5647 connected to the rpi and to run the detection algorithm</p><p>The easiest way to get hands on with YOLO is to use rpicam-vid for capturing frames then forward these frames in a TCP stream to another script, which instantiate the YOLO model and run the interference on the captured frames.</p><p>First step is to make sure that the camera is working for that connect a monitor to your rpi via HDMI/DSI port and start rpicam-hello on the console, if everything wents well you should see a live video for around 5s.</p><p>Second step is to clone YOLO repository and install the dependencies. I used YOLOv5 but feel free to use newer versions. On your terminal run the following command to clone yolov5 repository.</p><pre><br>git clone https://github.com/ultralytics/yolov5.git</pre><p>After that, create a virtual environment and install the needed dependencies, creating a virtual environment is not mandatory, I usually prefer it to avoid confusion between the system packages and the packages needed by a specific project.</p><pre>cd yolov5<br>python -m venv .yolov5env<br>source .yolov5env/bin/activate<br>pip install -r requirements.txt<br>pip install opencv-python<br><br># activate the virtual environment<br>source .yolov5env/bin/activate</pre><p>Now we are ready to run the detection on the raspberrypi !<br>On one hand we start the `rpicam-vid` process to stream video to `tcp://127.0.0.1:8888`</p><pre>rpicam-vid -n -t 0 --inline --listen -o tcp://127.0.0.1:8888</pre><p>On the other hand we start another script that detects the objects from the stream, the stream looks as follow:</p><pre>## detection_from_stream.py ##<br>from ultralytics import YOLO<br>import cv2<br><br># Load a YOLO model (v5 or v8 compatible)<br>model = YOLO(&quot;yolov5n.pt&quot;)<br><br># Run inference (on a local stream, image, or video)<br>results = model(&quot;tcp://127.0.0.1:8888&quot;, stream=True)<br><br># Loop through frames and show detections<br>for result in results:<br>    # result.plot() draws boxes, labels, and confidence scores on the image<br>    frame = result.plot()<br><br>    # Show the frame<br>    cv2.imshow(&quot;YOLO Detections&quot;, frame)<br><br>    # Press &#39;q&#39; to quit<br>    if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):<br>        break<br><br>cv2.destroyAllWindows()</pre><p>To run it just call from the activated environment</p><pre>python detection_from_stream.py</pre><p>A window will open up showing the recognized objects in boxes. That was straight and forward isn’t :)</p><p>To give some feedback on my experience with the recognition using rpi3b+, I have to say that it was too slow, that’s due to different reasons:</p><ul><li>first raspberrypi doesn’t have a GPU where that can be used by YOLO for inference, Raspberrypi has a VideoCore GPU designed for graphics/Video acceleration. YOLO needs CUDA (NVIDIA’s GPU Compute platform)</li><li>Second reason, is that I am using rpi3b+ which is much slower than newer models. As an example, the Raspberry Pi 5’s CPU can reach up to 2.4 GHz, whereas the Raspberry Pi 3B+ is limited to 1.4 GH</li></ul><p>So If you have the chance to test with newer versions please give your feedback in the comments :)</p><p><strong>References:</strong></p><ul><li><a href="https://docs.ultralytics.com/guides/raspberry-pi/">Raspberry Pi</a></li><li><a href="https://github.com/ultralytics/yolov5">GitHub - ultralytics/yolov5: YOLOv5 🚀 in PyTorch &gt; ONNX &gt; CoreML &gt; TFLite</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c868746a1bf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux ,Device Drivers :Component framework]]></title>
            <link>https://medium.com/@boussettaachraf26/linux-device-drivers-component-framework-5c3e49fc7602?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c3e49fc7602</guid>
            <category><![CDATA[drm]]></category>
            <category><![CDATA[learn-linux-device-driver]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Tue, 22 Jul 2025 15:39:03 GMT</pubDate>
            <atom:updated>2025-07-22T15:39:03.790Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linux ,Device Drivers :Component framework</h3><p>I had the opportunity to work on the DRM subsystem and it is quite an interesting organized piece of code.</p><p>In this tutorial I’d like to present the component Framework which is the backbone of DRM.</p><h3><strong>Introduction.</strong></h3><p>In the DRM subsystem, several components work together to form a display pipeline</p><p>The display pipeline consists of a CRTC connected to an encoder, which connects to a connector (e.g., panel, HDMI).</p><p>host DSI should be connected to the should be connected to the panel or bridge, so that the complete pipeline works and here comes the <strong>component framework</strong> to the picture. using component framework it is possible to implement the DRM driver in a <strong>aggregate/subcomponent</strong> fashion, the <strong>aggregate</strong> knows who are the <strong>subcomponents</strong> that should exist and when this event happens then <strong>aggregate</strong> is also ready.</p><p>Lets create an example so that the picture is more clear.</p><h3>The Big image</h3><p>The aggregate driver, egisters a list of matches , here we are matching against the names of subdevices, and once all the matches are fulfilled the aggregate driver is ready and calls the <strong>bind</strong> function</p><p>The full example can be found in <a href="https://github.com/bou6/linux_device_driver_examples/tree/main/components">Github</a> :</p><h3><strong>Device Tree changes:</strong></h3><p>For this example we added the following nodes to the base of the device tree.</p><pre>//base node<br>/ {<br>//..... <br>aggregate {<br>  compatible = &quot;master,device&quot;;<br>  status = &quot;okay&quot;;<br> };<br><br> subdev1@0 {<br>  name = &quot;subdev1&quot;;<br>  compatible = &quot;subdev,device&quot;;<br>  status = &quot;okay&quot;;<br> };<br> <br> subdev2@1 {<br>  name = &quot;subdev2&quot;;<br>  compatible = &quot;subdev,device&quot;;<br>  status = &quot;okay&quot;;<br> };<br>//...<br>}</pre><h3>Aggregate Driver:</h3><p>The aggregate driver contains an array of device names, For the sake of example, the aggregate driver is adding these 2 components .</p><pre>// the name of devices that the master device is matching<br>const char* subdev_names[] = {<br>    &quot;subdev1&quot;,<br>    &quot;subdev2&quot;<br>};<br><br>static void master_match_add_subdevices(struct device *dev, struct component_match **match,const char **subdev_names, int count)<br>{<br>    for (int i = 0; i &lt; count; i++) {<br>        // Add the sub-device node to the component match<br>        component_match_add(dev, match, compare_cb, subdev_names[i]);<br>        printk(KERN_INFO &quot;Added sub-device node: %s\n&quot;, subdev_names[i]);<br>    }<br>}</pre><p>The callback<strong> <em>compare_cb</em></strong> compares the name of the registred device node and the names from <strong><em>subdev_names</em></strong><em>;</em> if it returns true then the master driver detects that there is a match.</p><pre>static int compare_cb(struct device *dev, void *data)<br>{<br>    printk(KERN_INFO &quot;Comparing %s to %s\n&quot;, dev_name(dev), (char *)data);<br><br>    if (dev-&gt;of_node == NULL) {<br>        dev_err(dev, &quot;Device node is NULL\n&quot;);<br>        return 0; // No match if device node is NULL<br>    }<br><br>    // get the name of the device node<br>    const char *node_name = dev-&gt;of_node-&gt;name;<br>    if (!node_name) {<br>        dev_err(dev, &quot;Device node name is NULL\n&quot;);<br>        return 0; // No match if device node name is NULL<br>    }<br><br>    if (strcmp(node_name, data) != 0) {<br>        dev_info(dev, &quot;Device node name %s does not match target %s\n&quot;, node_name, (char *)data);<br>        return 0;  <br>    }<br><br>    dev_info(dev, &quot;Device node name %s matches target %s\n&quot;, node_name, (char *)data);<br>    // Return 1 to indicate a match<br>    return 1;<br>}</pre><p>Lets insert the <strong><em>aggregate_drv</em></strong> and see see the outcome:</p><pre>[ 2620.103177] Initializing the master driver<br>[ 2620.104917] Probing master device<br>[ 2620.106399] Added sub-device node: subdev1 //added subdev1<br>[ 2620.107798] Added sub-device node: subdev2 //added subdev2<br>[ 2620.109197] Comparing usb1-port1 to subdev1<br>[ 2620.110638] usb usb1-port1: Device node is NULL<br>[ 2620.112009] Comparing 1-1-port1 to subdev1<br>[ 2620.113364] usb 1-1-port1: Device node is NULL<br>[ 2620.114702] Comparing 1-1-port2 to subdev1<br>[ 2620.115970] usb 1-1-port2: Device node is NULL<br>[ 2620.117199] Comparing 1-1-port3 to subdev1<br>[ 2620.118460] usb 1-1-port3: Device node is NULL<br>[ 2620.119647] Comparing 1-1-port4 to subdev1<br>[ 2620.120830] usb 1-1-port4: Device node is NULL<br>[ 2620.122156] Comparing 1-1.1-port1 to subdev1<br>[ 2620.123331] usb 1-1.1-port1: Device node is NULL<br>[ 2620.124543] Comparing 1-1.1-port2 to subdev1<br>[ 2620.125745] usb 1-1.1-port2: Device node is NULL<br>[ 2620.126940] Comparing 1-1.1-port3 to subdev1<br>[ 2620.128110] usb 1-1.1-port3: Device node is NULL<br>[ 2620.129273] master_device master: Master device probed successfully <br>// probe is called succesfully but bind function is not called</pre><p>The aggregate driver is probed successfully, the bind function is not called that means that the component framework is comparing the registered devices, including unrelated ones (like USB devices), using <strong><em>compare_cb</em></strong> but no device has fulfilled the condition.</p><p>Ok then let’s write the subdevice driver and load it :)</p><h3>Subdevice driver:</h3><p>In the probe function the subdevice calls <strong><em>component_add</em></strong></p><pre>static int subdev_probe(struct platform_device *pdev)<br>{<br>    struct device *dev = &amp;pdev-&gt;dev;<br><br>    if (component_add(dev, NULL) &lt; 0) {<br>        dev_err(dev, &quot;Failed to add component\n&quot;);<br>        return -ENODEV;<br>    }<br>    dev_info(dev, &quot;Sub-device probed successfully\n&quot;);<br><br>    return 0;<br>}</pre><p>With <strong><em>component_add</em></strong> called we tell the component framework. that the subdevice is ready.<br>Lets take a look at the kernel trace after loading the subdevice driver.</p><pre>[ 2639.326232] Initializing the subdev driver<br>[ 2639.327725] Probing sub-device: subdev1<br>[ 2639.328876] Comparing usb1-port1 to subdev1<br>[ 2639.330117] usb usb1-port1: Device node is NULL<br>[ 2639.331280] Comparing 1-1-port1 to subdev1<br>[ 2639.332461] usb 1-1-port1: Device node is NULL<br>[ 2639.333683] Comparing 1-1-port2 to subdev1<br>[ 2639.334868] usb 1-1-port2: Device node is NULL<br>[ 2639.336054] Comparing 1-1-port3 to subdev1<br>[ 2639.337232] usb 1-1-port3: Device node is NULL<br>[ 2639.338539] Comparing 1-1-port4 to subdev1<br>[ 2639.339720] usb 1-1-port4: Device node is NULL<br>[ 2639.340905] Comparing 1-1.1-port1 to subdev1<br>[ 2639.342112] usb 1-1.1-port1: Device node is NULL<br>[ 2639.343304] Comparing 1-1.1-port2 to subdev1<br>[ 2639.344490] usb 1-1.1-port2: Device node is NULL<br>[ 2639.345708] Comparing 1-1.1-port3 to subdev1<br>[ 2639.346896] usb 1-1.1-port3: Device node is NULL<br>[ 2639.348087] Comparing subdev1@0 to subdev1<br>[ 2639.349272] sub_device subdev1@0: Device node name subdev1 matches target subdev1<br>[ 2639.350556] Comparing usb1-port1 to subdev2<br>[ 2639.351810] usb usb1-port1: Device node is NULL<br>[ 2639.353048] Comparing 1-1-port1 to subdev2<br>[ 2639.354275] usb 1-1-port1: Device node is NULL<br>[ 2639.355495] Comparing 1-1-port2 to subdev2<br>[ 2639.356702] usb 1-1-port2: Device node is NULL<br>[ 2639.357941] Comparing 1-1-port3 to subdev2<br>[ 2639.359158] usb 1-1-port3: Device node is NULL<br>[ 2639.360375] Comparing 1-1-port4 to subdev2<br>[ 2639.361606] usb 1-1-port4: Device node is NULL<br>[ 2639.362824] Comparing 1-1.1-port1 to subdev2<br>[ 2639.364038] usb 1-1.1-port1: Device node is NULL<br>[ 2639.365259] Comparing 1-1.1-port2 to subdev2<br>[ 2639.366498] usb 1-1.1-port2: Device node is NULL<br>[ 2639.367726] Comparing 1-1.1-port3 to subdev2<br>[ 2639.368946] usb 1-1.1-port3: Device node is NULL<br>[ 2639.370203] Comparing subdev1@0 to subdev2<br>[ 2639.371430] sub_device subdev1@0: Device node name subdev1 does not match target subdev2<br>[ 2639.372751] sub_device subdev1@0: Sub-device probed successfully<br>[ 2639.376013] Probing sub-device: subdev2<br>[ 2639.377419] Comparing usb1-port1 to subdev2<br>[ 2639.379144] usb usb1-port1: Device node is NULL<br>[ 2639.380479] Comparing 1-1-port1 to subdev2<br>[ 2639.381815] usb 1-1-port1: Device node is NULL<br>[ 2639.383084] Comparing 1-1-port2 to subdev2<br>[ 2639.384306] usb 1-1-port2: Device node is NULL<br>[ 2639.385555] Comparing 1-1-port3 to subdev2<br>[ 2639.386775] usb 1-1-port3: Device node is NULL<br>[ 2639.387998] Comparing 1-1-port4 to subdev2<br>[ 2639.389215] usb 1-1-port4: Device node is NULL<br>[ 2639.390461] Comparing 1-1.1-port1 to subdev2<br>[ 2639.391686] usb 1-1.1-port1: Device node is NULL<br>[ 2639.392916] Comparing 1-1.1-port2 to subdev2<br>[ 2639.394160] usb 1-1.1-port2: Device node is NULL<br>[ 2639.395396] Comparing 1-1.1-port3 to subdev2<br>[ 2639.396624] usb 1-1.1-port3: Device node is NULL<br>[ 2639.397879] Comparing subdev1@0 to subdev2<br>[ 2639.399110] sub_device subdev1@0: Device node name subdev1 does not match target subdev2<br>[ 2639.400430] Comparing subdev2@1 to subdev2<br>[ 2639.401760] sub_device subdev2@1: Device node name subdev2 matches target subdev2<br>[ 2639.403152] Binding the master device<br>[ 2639.404523] master_device master: bind called // !!! Bind is called <br>[ 2639.405885] sub_device subdev2@1: Sub-device probed successfully</pre><p>After registering the devices (subdev1 and subdev2), the component frameowrk is going through the registred devices again and try to find the matches.</p><p>This time matching is succesfull and in the end the bind function of the master is called</p><p>As you can see in this line bind is called now</p><pre>[ 2639.404523] master_device master: bind called</pre><h3>Links:</h3><ul><li><a href="https://www.kernel.org/doc/html/latest/driver-api/component.html">component framework</a></li><li><a href="https://github.com/bou6/linux_device_driver_examples/tree/main/components">Code repo</a></li></ul><h3>Conclusion</h3><p>The Linux Component Framework is a powerful mechanism for writing modular drivers, particularly useful in display pipelines such as DRM. By registering components and relying on callbacks like compare_cb, component_add(), and bind(), developers can structure drivers in a clean and maintainable way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c3e49fc7602" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with YOLOv5: My First Dive into Real-Time Object Detection]]></title>
            <link>https://medium.com/@boussettaachraf26/getting-started-with-yolov5-my-first-dive-into-real-time-object-detection-f37b555f7700?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/f37b555f7700</guid>
            <category><![CDATA[yolov5]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[begginer]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Tue, 22 Apr 2025 14:51:52 GMT</pubDate>
            <atom:updated>2025-10-10T10:07:49.758Z</atom:updated>
            <content:encoded><![CDATA[<p>As someone diving into object detection for the first time, I was genuinely impressed by how fast and straightforward it was to get started with <strong>YOLOv5</strong>. From installation to running my first model on an image, the whole experience felt incredibly smooth — especially for a first-timer in this area. I expected a steep learning curve, but YOLOv5’s well-documented repo, user-friendly interface, and lightning-fast inference made it a surprisingly accessible entry point into real-time computer vision. In this post, I’ll share my first hands-on experience, the steps I followed, and some thoughts on what makes YOLOv5 such a great starting point.</p><h3>Prerequisites</h3><p>Install PyTorch and required packages (assumes Python 3.8+ is installed):</p><pre>pip install torch torchvision torchaudio<br>pip install matplotlib opencv-python</pre><p>Clone the <strong>YOLOv5 repo</strong> and install dependencies:</p><pre>git clone https://github.com/ultralytics/yolov5<br>cd yolov5<br>pip install -r requirements.txt</pre><h3>Step 1: Download a Pretrained YOLOv5 Model</h3><p>The models can be downloaded from the release page : <a href="https://github.com/ultralytics/yolov5/releases">https://github.com/ultralytics/yolov5/releases</a></p><p>Ultralytics provides several sizes: yolov5s, yolov5m, yolov5l, yolov5x. The smallest is fastest.</p><p>Example (downloads automatically when running detection):</p><pre>python detect.py --source data/images/bus.jpg --weights yolov5s.pt --conf 0.25</pre><p>This command:</p><ul><li>Uses the pretrained <strong>yolov5s.pt</strong> model</li><li>Takes the test image bus.jpg from the data/images/ folder</li><li>Runs detection and saves results to runs/detect/exp/</li></ul><h3>Step 2: Try It On Your Own Image</h3><p>Put your own image, e.g., my_pic.jpg, in the yolov5 directory, then run:</p><pre>python detect.py --source my_pic.jpg --weights yolov5s.pt --conf 0.4</pre><p>Output will be saved in runs/detect/exp*/my_pic.jpg with boxes and labels drawn on it.</p><p>I run on a random <a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fde.m.wikipedia.org%2Fwiki%2FDatei%3ARail_bus_manufacturd_by_sri_lankan_railway_engineers.jpg&amp;psig=AOvVaw2P_xT4WOddNVUNhBroO8Kv&amp;ust=1745416925603000&amp;source=images&amp;cd=vfe&amp;opi=89978449&amp;ved=0CBQQjRxqFwoTCMin_vPm64wDFQAAAAAdAAAAABAE">image from Internet</a> and the result was pretty good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jiDEaAS6VzdZZClJQxFgsw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f37b555f7700" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using the Yocto toolchain for Cross Compilation]]></title>
            <link>https://medium.com/@boussettaachraf26/using-the-yocto-toolchain-for-cross-compilation-2dab8267dae7?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dab8267dae7</guid>
            <category><![CDATA[yocto]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 15:52:17 GMT</pubDate>
            <atom:updated>2025-06-11T08:50:21.344Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes, it’s more convenient to work with the toolchain generated by Yocto without diving into the complexities of <strong>BitBake</strong>. Extracting and using the Yocto toolchain separately can be particularly useful for <strong>application developers</strong> who want to build software for an embedded target <strong>without modifying the Yocto build system</strong>.</p><p>Using the <strong>extracted toolchain</strong> ensures that your application is compiled with the <strong>same kernel headers and libraries</strong> as those used in the Yocto-generated image. This guarantees compatibility and reduces potential runtime issues.</p><p>In this Article I demonstrate how to extract the toolchain from yocto and how to build a <strong>hello world application</strong> and a <strong>kernel module </strong>with the extracted toolchain</p><h3>Target System</h3><ul><li><strong>Hardware:</strong> Raspberry Pi</li><li><strong>Build System:</strong> Yocto</li></ul><h3>Prerequisites</h3><p>Before proceeding, ensure that:<br> ✅ All the necessary <strong>Yocto layers</strong> for your target system are available.<br> If not, refer to my previous post on <a href="https://medium.com/@boussettaachraf26/set-up-yocto-for-raspberry-pi-31b4a1ec4b10">setting up Yocto layers for Raspberry Pi.</a></p><h3>Step 1: Generate the Standalone Yocto SDK</h3><p>To generate a standalone <strong>SDK (toolchain)</strong> for cross-compilation, run:</p><pre>bitbake rpi-test-image -c populate_sdk</pre><p>This command builds an <strong>SDK installer</strong> containing the cross-compilation tools, libraries, and sysroot needed for development.</p><h3>Step 2: Install the SDK</h3><p>Navigate to the <strong>SDK deployment folder</strong> and install it to your preferred location:</p><pre>cd build/tmp/deploy/sdk/<br>poky-glibc-x86_64-rpi-test-image-cortexa53-raspberrypi3-64-toolchain-5.1.sh -d /opt/poky-sdk</pre><p>Here, the <strong>-d /opt/poky-sdk</strong> flag installs the toolchain into /opt/poky-sdk. You can choose another directory if needed.</p><h3>Step 3: Set Up the Cross-Compilation Environment</h3><p>Before using the cross-toolchain, set up the required environment variables:</p><pre>cd /opt/poky-sdk<br>source environment-setup-cortexa53-poky-linux</pre><p>This script sets up variables such as CC, CXX, LD, ARCH, and SYSROOT to point to the correct cross-compilation tools and libraries.</p><h3>Step 4: Verify the Environment Setup</h3><p>Ensure that all necessary environment variables are correctly set:</p><pre>printenv | grep ARCH # returns arm64<br>printenv | grep CC # return CC=aarch64-poky-linux-gcc ..</pre><p>This confirms that the compiler and architecture settings are correctly configured.</p><h3>Step 5: Cross-Compile a Simple Application</h3><p>Create a <strong>Hello World</strong> program (hello_world.c):</p><pre>//hello_world.c<br>#include &lt;stdio.h&gt;<br><br>int main()<br>{<br> printf(&quot;hello world \n&quot;);<br> return 0;<br>}</pre><h3>Compile Using the Yocto Toolchain</h3><p>Use the <strong>cross-compiler</strong> ($CC) to build the program:</p><pre>$CC hello_world.c -o hello</pre><h3>Step 6: Verify the Compiled Binary</h3><p>Check the binary architecture to ensure it was built for <strong>AArch64 (ARM 64-bit)</strong>:</p><pre>file hello<br>hello: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 5.15.0, BuildID[sha1]=ecfc02460957e24fc17b1571e724615c6ed96c0f, with debug_info, not stripped</pre><h3>Compile kernel module</h3><p>It is also possible to build out of tree kernel module without the need to write a yocto recipe:</p><p>Just create a folder and add your driver file and a Makefile:</p><pre>#include &lt;linux/module.h&gt;<br>#include &lt;linux/kernel.h&gt;<br>#include &lt;linux/init.h&gt;<br>#include &lt;linux/fs.h&gt;<br><br>#define DEVICE_NAME &quot;example_device&quot;<br><br>static int __init example_driver_init(void)<br>{<br>    printk(KERN_INFO &quot;Initializing the example driver\n&quot;);<br>    // Initialization code here<br>    return 0;<br>}<br><br>static void __exit example_driver_exit(void)<br>{<br>    printk(KERN_INFO &quot;Exiting the example driver\n&quot;);<br>    // Cleanup code here<br>}<br><br>module_init(example_driver_init);<br>module_exit(example_driver_exit);<br><br>MODULE_LICENSE(&quot;GPL&quot;);<br>MODULE_AUTHOR(&quot;Your Name&quot;);<br>MODULE_DESCRIPTION(&quot;A simple example Linux driver&quot;);<br>MODULE_VERSION(&quot;1.0&quot;);</pre><p>The Makefile is as follows, you need to update the KDIR path, which is the build directory for your kernel:</p><pre># Name of the module (without .ko)<br>obj-m := example_driver.o<br><br># Kernel source directory<br>KDIR := &lt;path_to_your_rpi_yocto&gt;/rpi-yocto/build/tmp/work/raspberrypi3_64-poky-linux/linux-raspberrypi/6.12.25+git/linux-raspberrypi3_64-standard-build<br><br># Current directory<br>PWD := $(shell pwd)<br><br># Default target<br>all:<br> $(MAKE) -C $(KDIR) M=$(PWD) modules<br><br># Clean target<br>clean:<br> $(MAKE) -C $(KDIR) M=$(PWD) clean</pre><h3>Conclusion</h3><p>In this short demo, we demonstrated how to <strong>extract and use the standalone Yocto SDK</strong> for <strong>cross-compiling applications</strong> for Raspberry Pi. Using the <strong>pre-built toolchain</strong> ensures binary compatibility with the target system and simplifies development without modifying the Yocto build system.</p><p>✅ <strong>No need to modify BitBake recipes</strong><br> ✅ <strong>Ensures binary compatibility</strong><br> ✅ <strong>Simplifies cross-compilation for application developers</strong></p><p>This method is highly useful when developing <strong>custom applications</strong> for embedded devices while keeping the <strong>Yocto-built environment intact</strong>.</p><p>Let me know if you have any questions or if you’d like to expand on any section! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dab8267dae7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set Up Yocto for Raspberry Pi]]></title>
            <link>https://medium.com/@boussettaachraf26/set-up-yocto-for-raspberry-pi-31b4a1ec4b10?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/31b4a1ec4b10</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[yocto]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Mon, 16 Dec 2024 09:04:41 GMT</pubDate>
            <atom:updated>2025-07-23T07:41:54.334Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Yocto Project Overview</strong></h3><p>The Yocto Project is a powerful build system for creating custom Linux distributions tailored for embedded devices. It provides flexibility and modularity through its layer-based architecture. Each layer encapsulates recipes, configuration files, and metadata for building specific features or supporting specific hardware.</p><p>For building a custom Linux system for Raspberry Pi, several layers are required:</p><ul><li><strong>Poky</strong>: The core Yocto layer and build system.</li><li><strong>meta-raspberrypi</strong>: The Board Support Package (BSP) layer for Raspberry Pi hardware.</li><li><strong>meta-openembedded</strong>: A collection of additional recipes and metadata for extended functionality.</li></ul><h3><strong>Prerequisites</strong></h3><p><strong>Install Required Host Packages</strong></p><p>Ensure your development environment has the necessary tools installed. On Ubuntu-based systems, run the following command:</p><pre>sudo apt-get install gawk wget git-core diffstat unzip \<br>texinfo gcc-multilib build-essential chrpath zstd</pre><p><strong>Cloning the Yocto Layers</strong></p><p>To set up Yocto for Raspberry Pi, clone the following repositories, Make sure all repositories are cloned into the same directory work for simplicity.</p><ol><li>Poky (core layer and build system):</li></ol><pre>git clone https://github.com/yoctoproject/poky.git</pre><p>2. meta-raspberrypi (Raspberry Pi BSP layer):</p><pre>git clone https://github.com/agherzan/meta-raspberrypi</pre><p>3. meta-openembedded (extended recipes and metadata):</p><pre>git clone https://github.com/openembedded/meta-openembedded.git // meta-openembedded</pre><h3><strong>Configuration:</strong></h3><p>Yocto uses a dedicated environment for its build process. To initialize it, go to the work directory and run following command:</p><pre>source poky/oe-environment</pre><p>This command creates a build directory in your current working directory and switches to it. Inside the build directory, you&#39;ll find configuration files, such as conf/local.conf and conf/bblayers.conf.</p><p><strong>Set the Target Machine<br></strong>For Raspberry Pi 3 Model B+, specify the target machine in the build/conf/local.conf file by adding the following line, This ensures the build process generates an image compatible with Raspberry Pi 3B+:</p><pre>MACHINE = &quot;raspberrypi3-64&quot;</pre><p><strong>Configure Layers<br></strong>To include the necessary layers in your build, edit the conf/bblayers.conf file. Add the paths to the following layers:</p><pre>BBLAYERS ?= &quot; \<br>  /path/to/poky/meta \<br>  /path/to/poky/meta-poky \<br>  /path/to/poky/meta-yocto-bsp \<br>  /path/to/meta-raspberrypi \<br>  /path/to/meta-openembedded/meta-oe \<br>  /path/to/meta-openembedded/meta-python \<br>&quot;</pre><p><strong>Handle Licensing Issue<br></strong>The Raspberry Pi BSP layer may introduce licensing constraints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IVMMZJRe3yeXGL2-DqWzLw.png" /></figure><p>the Synaptics driver may require explicit acceptance of its licensing terms. To resolve this, add the following line to conf/local.conf</p><pre><br>LICENSE_FLAGS_ACCEPTED = &quot;synaptics-killswitch&quot;</pre><p>See reference <a href="https://github.com/agherzan/meta-raspberrypi/issues/1111">here</a></p><p><strong>Optional Configurations</strong><br>You can further customize your build by adjusting these parameters in local.conf:</p><p><strong>Enable ssh server with empty root password.<br></strong>I usually enable the following feature so that I can get access to the target during the development phase.</p><pre>EXTRA_IMAGE_FEATURES = &quot;ssh-server-dropbear allow-empty-password empty-root-password allow-root-login&quot;<br>IMAGE_INSTALL += &quot; net-tools&quot;</pre><h3>Build the Image</h3><p>Run the following command to build your custom image:</p><pre>bitbake rpi-test-image</pre><p>Replace rpi-test-image with your desired image recipe, such core-image-minimalas or a custom image recipe defined in your layers.</p><h3>Flash the Image to the SD Card</h3><p>Once the build is complete, you’ll find the image in the build/tmp/deploy/images/raspberrypi3–64 directory. Flash the image to an SD card using a tool like dd or balenaEtcher.</p><p>Script example using dd command:</p><pre># flashing the image in the sdcard<br><br>cd build/tmp/deploy/images/raspberrypi3–64<br>echo &quot;unmounting the partitions if already present&quot;<br><br>if mount | grep /dev/mmcblk0; then<br>    echo &quot;Unmounting partitions on /dev/mmcblk0&quot;<br>    sudo umount /dev/mmcblk0*<br>fi<br><br>bunzip2 rpi-test-image-raspberrypi3-64.rootfs.wic.bz2<br>sudo dd if=rpi-test-image-raspberrypi3-64.rootfs.wic of=/dev/mmcblk0 bs=4M status=progress<br>sleep 5<br>rm rpi-test-image-raspberrypi3-64.rootfs.wic<br>echo &quot;synching...&quot;<br>sync<br>echo &quot;Checking partitions on /dev/mmcblk0...&quot;<br>sudo fdisk -l /dev/mmcblk0</pre><h3>Conclusion</h3><p>This guide outlines the steps for setting up Yocto to build a custom Linux image for Raspberry Pi. By leveraging the modularity of Yocto layers, you can extend functionality, support different hardware, and create highly customized Linux distributions tailored to your project’s needs.</p><p>For further customization, explore additional layers and Yocto documentation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31b4a1ec4b10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mqtt with Esp8266 and HiveMq]]></title>
            <link>https://medium.com/@boussettaachraf26/mqtt-with-esp8266-and-hivemq-256b5b9c4969?source=rss-4d5e294d6b98------2</link>
            <guid isPermaLink="false">https://medium.com/p/256b5b9c4969</guid>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[hivemq]]></category>
            <category><![CDATA[platformio]]></category>
            <dc:creator><![CDATA[Boussettaachraf]]></dc:creator>
            <pubDate>Thu, 04 Jul 2024 08:00:37 GMT</pubDate>
            <atom:updated>2024-07-04T08:00:37.065Z</atom:updated>
            <content:encoded><![CDATA[<p>In this short Article I give a guideline on how to create mqtt broker in HiveMq as well as connecting an ESP8266 to the Broker</p><h3>Configure the Server</h3><p>Create an account in HiveMq and there you can create free cluster to start Mqtt communication.<br>this is how your dashboard will look like:<br>On the left side are the available clusters, and on the ride side you can see the url and the ports of each cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2P5C5K5z0rGrQNChVNMqyw.png" /></figure><p>As a second step you need to create the credential (username and password) for you cluster, these will be used by the client to communicate with the Mqtt broker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0048mv7gs-8i1c5DED_8g.png" /></figure><p>That’s it we have created our Mqtt broker :) !.</p><h3><strong>Developing the client side</strong></h3><p>If you go to “Getting Started” Tab you find several examples depending on your client preferences,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*csysNtdJN_7rvWJDjE10wA.png" /></figure><p>I used Mosquitto to test that everything is working, it is really straight forward.<br>to subscribe to a topic, start the subscriber process on a first console:</p><pre>mosquitto_sub -h &lt;url&gt;.eu.hivemq.cloud -p 8883 -u &lt;userid&gt; -P &lt;password&gt; -t &lt;your_topic&gt;</pre><p>on the second console start publishing messages.</p><pre>mosquitto_pub -h &lt;url&gt;.eu.hivemq.cloud -p 8883 -u &lt;userid&gt; -P &lt;password&gt; -t &lt;your_topic&gt; -m &lt;your_message&gt;</pre><p>The result looks as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EHwPip7Re36_1am7SGsjaQ.png" /></figure><h3>esp8266 client setup with platform.io</h3><p>As mentionned in the <a href="https://console.hivemq.cloud/clients/arduino-esp8266?uuid=294fd52b749e4ed494a3c125261d9f0e">Getting Started Guideline</a> insecure connection is not supported by HiveMq this is you need to upload the certificates into your board. A good video explaining how TLS protocol works can be found <a href="https://www.youtube.com/watch?v=r1nJT63BFQ0">here.</a></p><h3>Uploading certificates using platform.io</h3><p>Use this <a href="https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/BearSSL_CertStore/certs-from-mozilla.py">script</a> to get the certificate, just copy paste the code locally and run</p><pre>python certs-from-mozilla.py</pre><p>The output of the script is a file <strong>data/certs.ar.</strong></p><p>As a second step you need to upload these certificates to the Target, that can easily be done in VisualCode using platformIO plugin , we need to copy the folder under the project tree, and then hit the upload Filesystem Image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*e_j8jXYMipApJmBx9P_YJQ.png" /><figcaption>copy the certificates under your project</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*mlxUo9wCYDEH7j60hzQpJg.png" /><figcaption>upload the certificates</figcaption></figure><p>All right, at this point the certificates should be uploaded to the target.<br>With this code you can double check if everything is correct, if you get <strong>“An error has occurred while mounting LittleFS”</strong>, then you have to redo the steps mentioned above:</p><pre>#include &lt;FS.h&gt;<br>#ifdef ESP32<br>  #include &lt;LITTLEFS.h&gt;<br>  #define Filesystem LITTLEFS<br>#else<br>  #include &lt;LittleFS.h&gt;<br>  #define Filesystem LittleFS<br>#endif<br>#include &lt;ESP8266WiFi.h&gt;<br>#include &lt;PubSubClient.h&gt;<br><br>void setup() {<br>  // Initialize serial for debugging<br>  Serial.begin(115200);<br><br>  // Initialize LittleFS<br>  if (!Filesystem.begin()) {<br>    Serial.println(&quot;An error has occurred while mounting LittleFS&quot;);<br>    return;<br>  }<br>  Serial.println(&quot;LittleFS mounted successfully&quot;);<br><br>  // Open the file for reading<br>  File certFile = Filesystem.open(&quot;/certs.ar&quot;, &quot;r&quot;);<br>  if (!certFile) {<br>    Serial.println(&quot;Failed to open certs.ar&quot;);<br>    return;<br>  }<br><br>  // Read and print the file content<br>  while (certFile.available()) {<br>    String line = certFile.readStringUntil(&#39;\n&#39;);<br>    Serial.println(line);<br>  }<br><br>  // Close the file<br>  certFile.close();<br>}<br><br>void loop() {<br>  // Put your main code here, to run repeatedly:<br>}</pre><h3><strong>Connect the board to mqtt and test</strong></h3><p>Now it is time to upload your Mqtt hello world example, just go again to HiveMq cluster, Getting started tab and then Arduino and copy paste the code in your IDE, make sure to update the following lines.</p><pre>// Update these with values suitable for your network.<br>const char* ssid = &quot;your_wifi_name&quot;;<br>const char* password = &quot;your_wifi_password&quot;;<br>const char* mqtt_server = &quot;&lt;your_cluster_url&gt;&quot;;<br><br>.......<br>// Update with your cluster username and password<br>if (client-&gt;connect(clientId.c_str(), &quot;YOUR_USERNAME&quot;, &quot;YOUR_PASSWORD&quot;))</pre><p>If you take a look at the main loop, you will see that the code is publishing a hello world message to <strong>testTopic</strong></p><pre>client-&gt;publish(&quot;testTopic&quot;, msg);</pre><p>So if you now connect your mosquito client to that topic you should be able to receive a “hello world”</p><pre>mosquitto_sub -h &lt;your_cluster&gt;.eu.hivemq.cloud -p 8883 -u &lt;user_id&gt;-P &lt;password&gt; -t testTopic</pre><p>And That’s it you made your first Mqtt communication !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=256b5b9c4969" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>