<?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 Mladen Dragicevic on Medium]]></title>
        <description><![CDATA[Stories by Mladen Dragicevic on Medium]]></description>
        <link>https://medium.com/@mladen.dragicevic?source=rss-b3a99add56dc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zWa9kT3vMjEpYnXZJ4EFZw.jpeg</url>
            <title>Stories by Mladen Dragicevic on Medium</title>
            <link>https://medium.com/@mladen.dragicevic?source=rss-b3a99add56dc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 01:31:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mladen.dragicevic/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[Real-Time GTFS Data Dashboard in Python]]></title>
            <link>https://medium.com/@mladen.dragicevic/real-time-gtfs-data-dashboard-in-python-209801ba32f1?source=rss-b3a99add56dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/209801ba32f1</guid>
            <category><![CDATA[dashboard]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[dash]]></category>
            <category><![CDATA[gtfs]]></category>
            <dc:creator><![CDATA[Mladen Dragicevic]]></dc:creator>
            <pubDate>Mon, 19 Sep 2022 14:17:26 GMT</pubDate>
            <atom:updated>2022-09-19T14:17:26.088Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*Lw02WTeLf-Pg6MREB1yS3g.png" /><figcaption>The final Demo dashboard</figcaption></figure><h3>Zagreb Public Transport</h3><p>Have you ever been to Zagreb, I think most would agree that public transport compared to some of the other capitals or cities similar in size is…well…not great. Public transport consists mainly of bus and tram networks which often intertwine with cars and pedestrians, making it quite inefficient and often unreliable. Here is an example of travelling at midday in center of Zagreb (so we can exclude the rush-hour effects):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*KoP4jxVHT6LeqwovJ5HD5w.png" /><figcaption>Google predicts around 50 minutes walk for distance of about 4km…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*BQt_9FEqihqQb6MMJh9hPw.png" /><figcaption>…and around 30–40 minutes for the same destination if using public transport in Zagreb. Efficient, right?</figcaption></figure><p>On the 5th of the September this year, ZET had its 131st birthday. <em>Zagrebački električni tramvaj</em> (translated <a href="https://en.wikipedia.org/wiki/Zagreba%C4%8Dki_elektri%C4%8Dni_tramvaj">Zagreb Electric Tram</a>) or ZET for short is the transit authority responsible for public transport in Zagreb. Since I usually avoid politics like the plague, I won’t comment that aspect in this post, but let’s just say that public transport in Zagreb needs serious modernization and investment, something which has not been done in quite some time now.</p><p>One of the things that most, if not all of the modern cities with public transport have, is real time feed info about transit data. This is something that has been completely missing in Zagreb, only the static schedule is available and displays on the station when the next ride is coming. So those nice features found on e.g. Google Maps where to go and when to catch the next line are not in real time in Zagreb.</p><p>What’s even worse, there was some talk about 10 years ago that some college students back then developed an app that was using data provided by ZET to show info about the positions of the public transport in real time, but the data and the app were taken down because the officials said this was a terrorism security threat (there is a post mentioning this <a href="https://rep.hr/vijesti/mobiteli/zet-testira-podatke-o-pozicijama-tramvaja-u-stvarnom-vremenu/8538/">here</a> in Croatian). Obviously this was nonsense and thankfully there was recently a switch in management of ZET Holding and city of Zagreb, so things could maybe finally change. Transit data has been published <a href="https://www.zet.hr/odredbe/datoteke-u-gtfs-formatu/669?fbclid=IwAR1HS2va6g8f1Nc3VBWuSSn89lzJVHImQNYr3BPs6tysaGZoeZwJX4_fVKI">online</a> in GTFS (General Transit Feed Specification) format. It is clearly stated on the page that data is <strong>for test purpose only</strong>, so it is <strong>not to be used to plan routes</strong>.</p><p>Still, I was curious what info they are offering and I wanted to build a real-time dashboard where all positions of trams and buses are displayed on the map using Python.</p><h3>General Transit Feed Specification</h3><p>Detailed specification of the GTFS standard can be found on <a href="https://developers.google.com/transit">Google Transit</a> pages and on <a href="https://gtfs.org/">gtfs.org</a>, here is just a short description from their site:</p><blockquote>The General Transit Feed Specification (GTFS) is a data specification that allows public transit agencies to publish their transit data in a format that can be consumed by a wide variety of software applications. Today, the GTFS data format is used by thousands of public transport providers.</blockquote><blockquote>GTFS is split into a <strong>schedule component</strong> that contains schedule, fare, and geographic transit information and a <strong>real-time component</strong> that contains arrival predictions, vehicle positions and service advisories.</blockquote><p><strong>Schedule component</strong> or <strong>GTFS Static</strong> is actually a single ZIP file containing a number of CSV files. ZET on their web pages provides more or less only static files flagged as mandatory by the standard:</p><ul><li><strong><em>agency.txt</em></strong> — <strong>required</strong>, transit agencies with service represented in this dataset</li><li><strong><em>stops.txt</em></strong> — <strong>required</strong>, stops where vehicles pick up or drop off riders. Also defines stations and station entrances</li><li><strong><em>routes.txt</em></strong> — <strong>required</strong>, transit routes. A route is a group of trips that are displayed to riders as a single service</li><li><strong><em>trips.txt</em></strong> — <strong>required</strong>, trips for each route. A trip is a sequence of two or more stops that occur during a specific time period</li><li><strong><em>stop_times.txt</em></strong> —<strong> required</strong>, times that a vehicle arrives at and departs from stops for each trip</li><li><strong><em>calendar.txt</em></strong> — <strong>conditionally required</strong>, service dates specified using a weekly schedule with start and end dates</li><li><strong><em>calendar_dates.txt</em></strong> —<strong> conditionally required</strong>, exceptions for the services defined in the <strong><em>calendar.txt</em></strong></li><li><strong><em>feed_info.txt</em></strong> — <strong>optional</strong>, dataset metadata, including publisher, version, and expiration information</li></ul><p><strong>Real-time component</strong> (<strong>GTFS Realtime</strong> feed) is used by transit agencies to provide real-time information about location of their vehicles, service alerts and trip updates. The GTFS Realtime data exchange format is based on <a href="https://developers.google.com/protocol-buffers/">Protocol Buffers</a>. Specification valid versions are “1.0” and “2.0” and full specification can be found on <a href="https://gtfs.org/realtime/reference/">gtfs.org reference</a> website for “2.0”, although it should be noted that ZET is currently providing “1.0” version, but reference can still be followed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8736c733c92d88cc0fb1645bd7c69fe/href">https://medium.com/media/a8736c733c92d88cc0fb1645bd7c69fe/href</a></iframe><h3>Project Outline</h3><p>OK, so the provided feed is less than ideal, and that defined some of the constraints on the dashboard:</p><ol><li>The feed is not provided in real-time, it is in near real-time. In my experience, the data is refreshed around every 30 seconds. So the dashboard cannot be refreshed in real-time, but in near real-time. I’m refreshing it every 15 seconds just in case not to miss an update.</li><li>The field with current position of the vehicle information is not provided in the feed. This is maybe the biggest drawback and is something that ZET should change ASAP. Anyway, since the precise location is not provided, I’ve opted for the second best — <strong><em>stop_id</em></strong> field. I’ve paired this field with latitude and longitude coordinates of the <strong><em>bus and tram stops</em></strong> provided in the GTFS static files.</li></ol><p>To be fair, it is stated by ZET that this is just demo data for testing purpose, so this could change in the future. In any case, I’ve decided to adapt to these constraints and proceeded as following:</p><ul><li>I’ll build the dashboard using Python frameworks. Smaller tweaks using JavaScript for better performance are allowed.</li><li>The goal is to deploy the dashboard on free tier Heroku.</li><li>The dashboard will be in near real-time showing the last known position provided by ZET (last stop).</li><li>Near real-time data is fetched in 15 seconds intervals. Static data is fetched once a day. For this to work, I needed a scheduler. I’ve opted for Airflow, so I’ve written two small DAGs to process the data and store it as JSON files on the file storage.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*E5JwiFpS9N_tt6ypamhirw.jpeg" /></figure><h3>Backend</h3><p>To reduce the load on the frontend, most of the data is preprocessed in the backend. There are two main DAGs orchestrated by Airflow:</p><ol><li><a href="https://github.com/mindesclabs/zetgtfsdemo/blob/main/backend/zet_static_data%20.py"><strong>zet_static_data .py</strong></a> — this DAG is used for collection of GTFS static data from ZET pages and routes data from OpenStreetMap. Needed data is joined and exported into GeoJSON format on the Box file storage for the frontend to consume.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4bhPzfX1yLEXyFcvBTqCw.png" /></figure><ol><li><a href="https://github.com/mindesclabs/zetgtfsdemo/blob/main/backend/zet_feed_data.py"><strong>zet_feed_data.py</strong></a><strong> </strong>— this DAG is collecting GTFS feed data from ZET pages every 15 seconds. Data is again exported into GeoJSON format and it is used to display individual vehicle position and information.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9nVrV32iisKJKFME2VxkA.png" /></figure><h3>Frontend</h3><p>The dashboard is constructed using <a href="https://dash.plotly.com/">Dash by Plotly</a> with the help of a light Leaflet wrapper, an open-source JavaScript library for interactive maps (<a href="https://pypi.org/project/dash-leaflet/">dash-leaflet</a>). Most of the code is Dash syntax with the exception of a couple JavaScript functions used for filtering, hover over vehicle popup info and icon assignment. Callbacks are app based, only the filter list populating callback is client-based as it is supposed to be faster, although truth to be told, on this amount of data it is probably not noticeable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ahXXvjWotfANqDsf8T0C_w.png" /><figcaption>Main window with interactive map.</figcaption></figure><p>Tram lines are displayed in yellow, while bus lines are in blue. Each type of vehicle has their corresponding custom icon to distinguish them better. In the tests, most of the vehicles were placed correctly on their route, but there were also some strange placements from time to time (e.g., one bus was constantly placed in France in August), because the provided coordinates were off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*Mbkja6bvMe7gLAlJiK5KrQ.png" /><figcaption>Routes are searchable. Multiple routes can be combined.</figcaption></figure><p>The map looks a bit crowded, so after the initial dashboard load, the <em>Clear all</em> button can be used to display just the map. I’ve added a search panel where one or more routes can be selected to be displayed on the map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*k881-OkL3MPDs3uYQwWtrw.png" /><figcaption>Additional vehicle info can be displayed in a hover-over manner.</figcaption></figure><p>I’ve also added a couple of fields of information about each vehicle, just for the demo purpose. Info is accessed by hovering over individual icons and it shows route id and name, name of the current stop and arrival time in CET. This is the last available info provided by ZET in their GTFS feed. As stated in the intro, unfortunately ZET does not provide precise GPS coordinates.</p><p>The app callback is being made every 15 seconds, but data is refreshed on the ZET web pages approximately every 30 seconds, so in reality a change on the screen will be mostly available in that time. The quality of the currently provided data is dubious. Often, the change in position of a single vehicle will seem lagged which can be the result of ZET not updating the position properly or it could be the issue that since they are not providing the exact coordinates, but rather the last stop, there is a delay in-between the stops. I’ve tested this a couple of times<em> in the field —</em> while I was in the city doing some errands or going to the office. There were situations when tram was supposed to be on a particular stop according to the GTFS feed, but no trams where nearby. So, I’m more leaning towards that the problem is the data quality issue and hopefully this will also be resolved when the data goes out of the testing phase.</p><h3>Final Notes</h3><p>In the end, the goal of this small project was to try to build a real-time GIS dashboard in Dash by using some real-world data. I would say this is very doable and working as intended. The dashboard is responsive, it refreshes correctly and it is customizable. So, the goal was accomplished.</p><p>For this particular project, a lot of features could be upgraded or added (like more information about the vehicles, select all option, current vehicle heading, etc.). This all of course makes sense if the underlying data is provided, correct and in time.</p><p>You can find the Demo and Code used to produce it on the following links:</p><ul><li>Demo Dashboard: <a href="http://zetgtfsdemo.herokuapp.com/"><strong>http://zetgtfsdemo.herokuapp.com/</strong></a></li><li>Github project: <a href="https://github.com/mindesclabs/zetgtfsdemo"><strong>https://github.com/mindesclabs/zetgtfsdemo</strong></a></li></ul><p>Thank you for your interest and if you like what you read, let me know and hit follow to keep up to date with my future projects.</p><p>Cheers!</p><p>Feel free to reach out :)</p><ul><li><a href="https://mdlabs.hr/">https://mdlabs.hr/</a></li><li><a href="https://www.linkedin.com/in/mdragicevic/">https://www.linkedin.com/in/mdragicevic/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=209801ba32f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Retro Audio System with piCorePlayer and Raspberry Pi 4]]></title>
            <link>https://medium.com/@mladen.dragicevic/building-retro-audio-system-with-picoreplayer-and-raspberry-pi-4-1e91074383e0?source=rss-b3a99add56dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e91074383e0</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[radio]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[audio]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Mladen Dragicevic]]></dc:creator>
            <pubDate>Sat, 09 Apr 2022 18:03:14 GMT</pubDate>
            <atom:updated>2022-04-09T18:03:14.173Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vq4KCYZSIEuENmzfZ4EF3A.jpeg" /></figure><p>Some time ago, I was visiting a small local record fair in the center of Zagreb when I’ve noticed a guy selling some old fashioned radios. He was in business of restoring mostly <a href="https://en.wikipedia.org/wiki/Antique_radio">vintage valve radios</a>. I was actually looking for something similar as a casing for a streaming server I was planning to build. Anyway, I’ve managed to get my hands on a broken piece he had, so I’ve started to build on this project.</p><p>Now, the radio itself was not working, but had most of the parts (although in a very bad condition). Also, it was big. Way bigger than I wanted to build at first, but it was best I could find so I was determined to salvage as much as possible and to utilize the size in some manner.</p><p>It was missing the back panel and the buttons at the front were in a bad condition. So, I’ve stripped the interior from the original parts as they were not working and I did not need them. I’ve also removed the speakers since idea was to use Bluetooth connection to connect to external speakers. After this, I’ve disassembled the front glass panel and the original buttons. Now I could clean the interior of the radio and the front glass panel where names of old radio stations are printed. I’ve also restored the buttons to their original condition as best as possible (filling broken plastic parts and repainting them). I did not want to repaint the wood or clean more on the fiber parts as I wanted that old grungy look for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*j4WQCstEhgLZ-GmpRooiiA.jpeg" /><figcaption>Front panel after restauration</figcaption></figure><h3>The Interiors</h3><p>Ok, now that I’ve had all the important parts of the casing in place, I could focus on the interior hardware. My intention was to connect the streaming server using the Bluetooth connection, so I could position the radio in a different part of the living room and reutilize the speakers I have for the TV. This also implied that a Wi-Fi connection is needed to connect the radio to the router. The speakers under the TV did not have a Bluetooth receiver, so I’ve bought <a href="https://www.logitech.com/en-us/products/speakers/bluetooth-audio-adapter.980-000910.html">Logitech Bluetooth Audio Receiver</a>. There are also other options available and they are fairly cheap, so this is a good solution if your speaker system is older. However, be aware of the distance between the source and the receiver as Bluetooth can be sensitive to obstacles and interference (I’ve learned this the harder way).</p><p>I already had a <a href="https://www.raspberrypi.com/products/raspberry-pi-4-model-b/">Raspberry Pi 4 model B</a> (with 4GB RAM) lying around, so I opted to use that. To be honest, this was probably an overkill for a project like this - an older or cheaper model could probably be used with the same outcome.</p><p>The good thing with this model of Raspberry Pi is that it has integrated Wi-Fi and Bluetooth chip. Also, Wi-Fi can operate on 5GHz so in theory it won’t interfere with the Bluetooth chip. The bad thing is that onboard Bluetooth is very limited in range and in practice if you don’t have the receiver very near, you will have audio stutter and interference. I’ve lost a couple of days trying to figure out why sometimes randomly I have such a bad stutter and blamed it on the Linux (because Bluetooth and Linux is a special kind of voodoo). But in the end, with the help of the good folks that are <a href="https://forums.slimdevices.com/showthread.php?114828-Announce-piCorePlayer-8-0-0&amp;p=1048563#post1048563">developing piCorePlayer</a>, I’ve managed to pinpoint that indeed problem is in the hardware and an external Bluetooth dongle is needed.</p><p>That being said, I think there is a special place in hell for those manufacturers that use cheap knockoff copies of chips in their dongles. First one I bought had what it turned out to be not an original Cambridge Silicon Radio chip, so I’ve tried to patch the kernel on multiple tries to make it work without a success (the damn thing just would not connect whatever I did, although <em>lsusb</em> command listed it as a CSR device…). I’ve also lost a couple of days on this (and quite some nerves). So just be careful with this, as I could not find good info online which dongle works well on Linux while it was also available in my local retail store to buy. In the end, I’ve managed to get it working with <a href="https://www.tp-link.com/us/home-networking/usb-adapter/ub400/">TP-Link UB400</a> out of the box. Anyway, takeaway lesson from this is that Linux and Bluetooth can be a nightmare, <em>you have been warned!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*Kg0MErnp3XAoBkECSt_7Lg.jpeg" /><figcaption>Honey, I Shrunk the Electronics</figcaption></figure><h3>The Cosmetics</h3><p>Actually, those were the main parts needed for this thing to work, but it was missing something. Remember how I said this thing was huge? So it will not be on a shelf, but rather placed in a room somewhere as a display piece…</p><p>This is why I wanted to make it a bit more interesting and since I had extra room inside the radio, I’ve decided to place some LED light strips. When the radio is turned on, LED strips would glow through the front glass panel illuminating radio stations names. Actually, for my first iteration I’ve used some yellow LED diodes I’ve soldered on, but they were just too weak for this glass panel. I wanted it to be more visible, hence the LED strips.</p><p>I needed external power for the LED strips and a relay to switch them on/off using the Raspberry GPIO based on the playing status of the streaming server. I wanted to have only one power cord from the radio, so I’ve placed an extension cord inside in order to have both adapters (from Raspberry and LED strips) plugged in without the need to cut their cords.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*nOF3h1QUztv704feIomQEw.jpeg" /></figure><p>Relay is getting signal on the GPIO17 (board pin 11) here, of course other GPIOs are also possible to use. I’ve used 3.3V relay connected as normally open. You can also use 5V relay which is much easier to find, but <a href="https://raspberrypi.stackexchange.com/questions/118116/can-you-use-a-5v-relay-module-with-the-pi">additional modifications</a> to the wiring could be needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*ro5YM7X59R4lO4Uc1eSE1Q.jpeg" /><figcaption>LED strips are between the metal part and front glass panel</figcaption></figure><h3>The Brain</h3><p>Now that hardware part was solved, it was time to focus on the software part. There is this great project that Paul, Steen, Ralphy and Greg are developing called <a href="https://www.picoreplayer.org/">piCorePlayer</a>. I have to say that also community and their response to the community is one of the best I’ve seen online. I’ve installed what is called option number 3: <em>complete music system with integrated player and server (Squeezelite and LMS).</em></p><p>But what is piCorePlayer? I’ll put a quote from their webpage here as I think it explains it quite well:</p><blockquote><strong>pCP is a highly specialized audio system. By installing extra software packages and hardware additional features can be added.</strong></blockquote><blockquote>piCorePlayer is built on a very small Linux distro which is only about 12 MB, known as piCore Linux. It boots very fast and it is running entirely in RAM, it doesn’t write to the SD-card unless you want to save a new setting. Therefore, pCP is very robust and you can simply pull the power without any risk of corruption of your SD card.</blockquote><p>There are numerous plugins available online, depending on which services and customizations you need. Also, <a href="https://github.com/CDrummond/lms-material">material skin for SlimServer</a> really makes whole Logitech Media Server look beautiful both on mobile phone and on the computer as it has responsive design. Setup is fairly easy, I’ve just followed the <a href="https://docs.picoreplayer.org/getting-started/">documentation</a> available online.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-gf1h561A_AnaV8EqF9BQ.png" /><figcaption>LMS using material skin</figcaption></figure><p>One thing that was not so easy to do was getting the LED strip to work based on the status of the player (whether it is paused or playing). For this to work I had to get a bit creative and managed to figure it out when I’ve stumbled on a plugin that looked like it is not officially supported anymore, but was still working. Plugin is called <strong><em>SBNetIO</em></strong> developed by Guenther Roll. Unfortunately, I could not find his code repo anymore as it seems deleted, but luckily plugin is still available on forked git projects. The plugin forwards LMS (formerly known as <em>Squeezebox Server</em>) events to a listening server by means of network communication. On server side these messages can be translated to arbitrary actions. Thus, in combination with a server the plugin offers a mechanism to run remote commands. So, to use the plugin you will need to setup another server — on its own, the plugin is pretty useless.</p><p>I’ve written a very simple Python script which starts a simple TCP server that based on the received signal starts or stops the LED strip lights (by activating/deactivating pin board number 11/GPIO17 in this case):</p><pre>#!/usr/bin/python3</pre><pre>import asyncio<br>import RPi.GPIO as GPIO</pre><pre>GPIO_SWITCH = 11</pre><pre>async def handle_command(reader, writer):</pre><pre>data = await reader.read(100)<br>    message = data.decode()<br>    addr = writer.get_extra_info(&#39;peername&#39;)<br>    if message == &#39;upali\n&#39;:<br>        GPIO.output(11, False)<br>    elif message == &#39;ugasi\n&#39;:<br>        GPIO.output(11, True)<br>    else:<br>        print(&#39;unknown command&#39;)</pre><pre>writer.write(data)<br>    await writer.drain()<br>    writer.close()</pre><pre>async def main():<br>    server = await asyncio.start_server(<br>        handle_command, &#39;127.0.0.1&#39;, 8888)</pre><pre>async with server:<br>        await server.serve_forever()</pre><pre>if __name__ == &quot;__main__&quot;:</pre><pre>#Initial GPIO-setup<br> GPIO.setwarnings(False)<br> GPIO.cleanup()<br> <br> # to use Raspberry Pi board pin numbers<br> GPIO.setmode(GPIO.BOARD)<br> GPIO.setup(GPIO_SWITCH, GPIO.OUT)<br> <br> asyncio.run(main())</pre><p>The server is running in this example on 127.0.0.1:8888. I’ve added user defined commands to the piCorePlayer startup procedure so this server starts on boot (it is under <em>Tweaks</em> on the settings panel, make sure to have Beta mode enabled):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DLjyBp5iWSeHKwmrmZLj1w.png" /><figcaption>Running Python script at startup</figcaption></figure><p>Now I needed to configure SBNetIO plugin to send the appropriate commands. If you check the plugin list, settings for this plugin is missing (I guess due to some sort of more recent incompatibility), but you can still access the settings by manually navigating to the correct address (I’m using material skin):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bj6fTyVBv3gDysAkKkrRag.png" /><figcaption><em>&lt;addres:port&gt;/material/settings/server/plugins/SBNetIO/settings/basic.html</em></figcaption></figure><p>Entering data here will create modifications to the preferences file located at <em>&lt;mounted_folder&gt;/slimserver/prefs/plugin/SBNetIO.prefs </em>(here is my preferences file after the settings input):</p><pre>---<br>_client:e4:5f:01:2a:8d:95:<br>  _version: 0<br>_client:ec:81:93:9b:88:03:<br>  PowerOffOnPause: 1<br>  Zone1Active: 1<br>  Zone1Auto: 1<br>  Zone1Name: Ledice<br>  Zone2Active: 0<br>  Zone2Auto: 0<br>  Zone2Name: Zone 2<br>  Zone3Active: 0<br>  Zone3Auto: 0<br>  Zone3Name: Zone 3<br>  _ts_PowerOffOnPause: 1646814137<br>  _ts_Zone1Active: 1646814137<br>  _ts_Zone1Auto: 1646825789<br>  _ts_Zone1Name: 1646825789<br>  _ts_Zone2Active: 1646814137<br>  _ts_Zone2Auto: 1646823450<br>  _ts_Zone2Name: 1646814137<br>  _ts_Zone3Active: 1646814137<br>  _ts_Zone3Auto: 1646823450<br>  _ts_Zone3Name: 1646814137<br>  _ts_delayOff: 1646826919<br>  _ts_delayOn: 1646814137<br>  _ts_msgOff1: 1646825789<br>  _ts_msgOn1: 1646825789<br>  _ts_pref_Enabled: 1646823450<br>  _ts_srvAddress: 1646823663<br>  _ts_srvAddress1: 1646825789<br>  _version: 0<br>  delayOff: &#39;0&#39;<br>  delayOn: &#39;0&#39;<br>  msgOff1: ugasi<br>  msgOn1: upali<br>  pref_Enabled: 1<br>  srvAddress: 127.0.0.1:8888<br>  srvAddress1: 127.0.0.1:8888<br>_version: 0</pre><p>So basically plugin is sending <em>msgOff1</em> for turning off command and <em>msgOn1 </em>for turning on command on the specified address and port (127.0.0.1:8888), while server written in Python is running on this port and accepting defined commands… Final product?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*XdXPCcXAbVb1fvAiNudbnA.gif" /><figcaption>Let there be light…</figcaption></figure><p>I still need to add back cover to the radio case, but overall I’m very happy how this project turned out. Audio quality is great, stutter is gone and whole thing looks quite nice :)</p><p>I would like to say thanks once more to the good people developing piCorePlayer as well people contributing with nice plugins and whole community. I’ve mostly focused in this blog post on the whole idea and how to setup things that were more or less unique to this project, but without the piCorePlayer this project would be much, much more complicated.</p><p>Thank you for reading this and I hope maybe it will inspire others with more ideas. If you like what you read let me know and hit follow to keep up to date with my future projects. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e91074383e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>