Let op: Tweakers stopt per 2023 met Tweakblogs. In
dit artikel
leggen we uit waarom we hiervoor hebben gekozen.
DIY 4K Steam Link (aka Moonlight Box)
Vanwege een aantal reacties in dit nieuwsbericht dacht ik dat ik een korte howto van mijn setup even op het digitale papier wil toevertrouwen. Ik doe het even in het Engels zodat onze internationale vrienden er ook nog wat aan hebben.
.
To install the OS you can use fe this guide. Make sure that you enable SSH.
Insert the SD card, and connect the RPi to the TV and the network. Make sure you are using the HDMI-0 port on the Pi4 (closest to USB-C power jack)
After booting the RPi. Run raspi-config configure it to auto login (Option 1 System Options, S5 Boot / Auto Login, B2 Console Autologin) and configure the max GPU memory (Option 4 Performance Options, P2 GPU Memory set it to 256)
SSH into your PI and edit the /boot/config.txt.
Find the line with
and change it to this:
With some cooling and heatsinks this overclock was rock stable when using Moonlight
Also uncomment the line with config_hdmi_boost and change it's value to 7 (atleast that resolved some issues in my setup).
Also make sure that disable_overscan is uncommented and set to 1.
Reboot your Pi for the changes to take effect.
So I have setup my Pi to a resultion of 1440p using this config:
Ok. This may vary from setup to setup. For the # steps I will tell you what I use, and what you could use.
#0 This can not be done in code ofc. I have the RPi power supply in a smart switch. That switch is controlled by Home Assisant. So with a quick shout to Google Assistant, or manually in Home Assistant I can power on the Raspberry. You could ofcourse just plug it into the socket, or use a extention cord with a on/off button.
#1 In my home almost everything is controlled through Home Assistant. In my script a curl call is done to NodeRed. Which in turn turns on the PC though the wake_on_lan integration. You could use etherwake (apt-get install etherwake, and in the script put etherwake xx:yy:zz:11:22:33 where xx:yy:zz:11:22:33 is the MAC address of your game PC)
#2 Again. In my situation a curl call is done to NodeRed. And a RPC shutdown is send to my PC. To do it directly from the RPi just google "net rpc raspberry pi".
#3 In my situation a timer starts with the call done in #2. After 30 seconds the smart switch is switched off. You could ofcourse remove the power supply from the socket or turn it off through an extention cord with an on/off button.
Now to start the script on boot, edit .bashrc (sudo nano ~/.bashrc) and add this to the end of the file:
After rebooting the RPi, the autorun script runs in the console and starts Moonlight-QT.
Introduction
This tutorial/how-to guides you in creating a Steam Link-like device using a Raspberry PI 4 and Moonlight to have solid in home game streaming at 4K60. There are some optional steps that I have implemented that may or may not be applicable for you, cherry pick the ones that are of interest for you. 😊.Required/Recommended Equipment
- A windows PC with a GeForce GTX GPU and GameStream setup howto
- A Raspberry Pi 4 with a solid power supply, and preferably with a case with active cooling and ofcourse an SD card
- A wired network connection on your Windows PC and the RPi (Wireless does technically work. But just… don’t…)
- A controller (I use a Xbox One Wireless adapter, in the optional steps I will guide you through the setup, if you have an other controller Google will be your friend on how to set that one up)
Prep your Pi
We will be using Raspberry PI OS Lite as our operating system. The reason why we do not use the regular one is that if you want HEVC support in Moonlight (and we do want that) you need to run it from the console.To install the OS you can use fe this guide. Make sure that you enable SSH.
Insert the SD card, and connect the RPi to the TV and the network. Make sure you are using the HDMI-0 port on the Pi4 (closest to USB-C power jack)
After booting the RPi. Run raspi-config configure it to auto login (Option 1 System Options, S5 Boot / Auto Login, B2 Console Autologin) and configure the max GPU memory (Option 4 Performance Options, P2 GPU Memory set it to 256)
Changing config.txt
First we need to overclock your PI. With stock speeds you will have same jittering when streaming at resolutions higher then 1080p.SSH into your PI and edit the /boot/config.txt.
Find the line with
code:
1
2
| #uncomment to overclock the arm. 700 MHz is the default. #arm_freq=800 |
and change it to this:
code:
1
2
3
4
5
| #uncomment to overclock the arm. 700 MHz is the default. #arm_freq=800 over_voltage=6 arm_freq=2147 gpu_freq=750 |
With some cooling and heatsinks this overclock was rock stable when using Moonlight
Also uncomment the line with config_hdmi_boost and change it's value to 7 (atleast that resolved some issues in my setup).
Also make sure that disable_overscan is uncommented and set to 1.
Reboot your Pi for the changes to take effect.
(Optional) set the resolution to 1440p
Yes. I know. This is a guide for 4K streaming. But my game PC can't quite handle this. And to be honest, I do not really see the difference between 4K and 1440p on my TV. But your milage may vary.So I have setup my Pi to a resultion of 1440p using this config:
code:
1
2
3
4
5
6
| hdmi_group=2 hdmi_mode=87 hdmi_cvt=2560 1440 60 3 0 0 1 max_framebuffer_width=2560 max_framebuffer_height=1440 hdmi_pixel_freq_limit=400000000 |
Install Moonlight-Qt
Can't be more simple then this:code:
1
2
| curl -1sLf 'https://dl.cloudsmith.io/public/moonlight-game-streaming/moonlight-qt/setup.deb.sh' | sudo -E bash sudo apt install moonlight-qt |
(Optional) Install the drivers for the Xbox One wireless adapter
The great medusalix has developed a driver for the Xbox One wireless adapter. To install this on your RPi4 follow these steps:code:
1
2
3
4
5
6
7
8
| sudo apt-get install git sudo apt-get install libusb-1.0-0-dev sudo apt-get install cabextract git clone https://github.com/medusalix/xow cd xow make BUILD=RELEASE sudo make install sudo systemctl enable xow |
Automaticlly starting Moonlight on bootup
Create a script called autorun_moonlight.sh in your home directory. And use this codecode:
1
2
3
4
5
6
7
8
9
10
11
| #0 Power on RPi echo "Starting PC" #1 code to start pc echo "Starting Moonlight" moonlight-qt echo "Moonlight exited." echo "Shutting down PC" #2 code to shutdown pc echo "Shutting down RPi" shutdown now #3 power off RPi |
Ok. This may vary from setup to setup. For the # steps I will tell you what I use, and what you could use.
#0 This can not be done in code ofc. I have the RPi power supply in a smart switch. That switch is controlled by Home Assisant. So with a quick shout to Google Assistant, or manually in Home Assistant I can power on the Raspberry. You could ofcourse just plug it into the socket, or use a extention cord with a on/off button.
#1 In my home almost everything is controlled through Home Assistant. In my script a curl call is done to NodeRed. Which in turn turns on the PC though the wake_on_lan integration. You could use etherwake (apt-get install etherwake, and in the script put etherwake xx:yy:zz:11:22:33 where xx:yy:zz:11:22:33 is the MAC address of your game PC)
#2 Again. In my situation a curl call is done to NodeRed. And a RPC shutdown is send to my PC. To do it directly from the RPi just google "net rpc raspberry pi".
#3 In my situation a timer starts with the call done in #2. After 30 seconds the smart switch is switched off. You could ofcourse remove the power supply from the socket or turn it off through an extention cord with an on/off button.
Now to start the script on boot, edit .bashrc (sudo nano ~/.bashrc) and add this to the end of the file:
code:
1
2
3
| if [ $(tty) == /dev/tty1 ]; then
~/autorun_moonlight.sh
fi |
After rebooting the RPi, the autorun script runs in the console and starts Moonlight-QT.
Een lamp aan uit zetten met MQTT en Node-RED
Wat kan ik er mee?
Zie titel. Een lamp aan en uit zetten. Maar dan wel op een fantastische over-geengineerde manier waar mijn lieftallige vriendin het nut niet van inziet.Wat is MQTT?
In het kort: MQTT is standaard bedoeld voor IoT toepassingen. Het is een broker waarmee berichten op basis van een publish-subscribe systeem heen en weer gestuurd kunnen worden. Voor meer informatie: http://internetofthingsag...TT-MQ-Telemetry-TransportWat is Node-RED?
In het kort: Node-RED is tool waarmee je op basis van flows eenvoudige (of minder eenvoudige) acties kan 'programmeren'. De kracht van Node-RED zit hem in de snelle iteratie, het visuele programmeren, de gigantische library van uitbreidingen en de eenvoud dat je het kan uitbreiden. Voor meer informatie: https://nodered.org/Waarom?
Het idee is dat een MQTT broker i.c.m. Node-RED wordt gebruikt om alle componenten aan elkaar te koppelen, de status bekend te maken naar een of meerdere frontends en automations volledig buiten de frontend te regelen.Dit bied je de volgende voordelen:
- Je kan eenvoudig wisselen van frontend, of zelfs meerdere gebruiken. Zoals je ze maar MQTT praten. Zelf een eenvoudige frontend maken is dan ook super eenvoudig. Voorbeeld: ik heb in een avondje een dashboard gemaakt om alle lampen in mijn huis te besturen in Unity3D.
- Het doet wat jij zegt dat het moet doen, dmv de flows heb je volledig inzicht in wat er gebeurd.
- Node-RED wordt enorm veel gebruikt, voor veel toepassingen zijn er node's beschikbaar.
Mijn setup
Ik ben nog maar net begonnen met mijn Domotica setup; dus het is nog bescheiden. Maar dit is mijn setup:Op een RPi3 draait nog een MQTT-broker, Node-RED en Home Assistant, met daar aan gehangen een RFXcom.
MQTT-broker op een VPS: deze ontvang mijn locatie via OwnTracks, in Node-RED heb ik een flow die gesubscribed is op het topic waar OwnTracks naar toe publisht, en deze publisht het 1-op-1 door naar de on-prem broker.
2 hue lampen + bridge
3 kaku stekkers met daaraan een paar losse lampen
1 temp sensor via 433Mhz
7" tablet aan de muur met daar op draaiende een dashboard gemaakt met Unity3D (betere visuele performance t.o.v. HTML5)
Wat heb ik nodig?
Een MQTT-broker: ik gebruik zelf MosquittoEen Node-RED installatie met de node-red-contrib-rfxcom package geinstalleerd
Basis begrip van hoe Node-RED werkt
Een RFXCOM RFXtrx433E
Een frontend die MQTT praat, in mijn voorbeelden gebruik ik Home Assistant
Voorbeeld RFXcom lamp/schakelaar
Stap 1
We maken eerst een lamp aan in de configuratie van Home Assistant:code:
1
2
3
4
5
6
7
8
| - platform: mqtt name: "Mooie lamp" command_topic: "lamp/433/switch/ARC/B/1" state_topic: "lamp/433/state/ARC/B/1" payload_on: "On" payload_off: "Off" qos: 0 optimistic: false |
Korte uitleg:
| Veld | Omschrijving |
|---|---|
| platform | geeft aan dat het een lamp betreft die gebruikt maakt van het MQTT platform |
| name | de naam die je de lamp wil geven binnen Home Assistant |
| command_topic | naar welk MQTT topic je een bericht stuurt om aan te geven dat je de lamp aan of uit wil zetten |
| state_topic | naar welk MQTT topic Home Assistant moet luisteren voor de huidige lamp status |
| payload_on/playload_off | welk bericht je moet sturen of naar moet lluisteren voor de aan of uit stand |
| qos | Plat gezegd de 'garantie' dat een bericht daadwerkelijk aangekomen is. Omdat de client en de broker op het zelfde systeem staan bij mij is 0 voldoende (fire and forget) |
| optimistic | bij true gaat de schakelaar binnen Home Assistant direct om, mijn voorkeur is om te wachten op de MQTT state wijziging. |
Omdat ik niet voor elke lamp een flow wil maken in Node-RED heb ik in de command en de state topics het adres opgenomen van de lamp/schakelaar (in mijn geval gaat het dus om een KaKu schakelaar op het adres B/1).
Stap 2
Nu gaan we de flow maken.Deze flow vangt twee scenario's af:
- In home assistant (of een andere applicatie die commando's stuurt naar het switch topic) kan de lamp aan of uit zetten[/i]
- Via een KaKu remote kan de lamp aan of uit gezet worden[/i]
Even kort de nodes bij langs:
lamp/433/switch/#
Deze MQTT input node luistert naar alle topics die beginnen met lamp/433/switch.
ExtractDeviceName
Eenvoudige function node die lamp/433/switch stript van de topic. De payload kan 1 op 1 doorgezet worden.
433 light (output)
Uitgaande node. Het topic geeft aan welk adres geschakeld moet worden en de payload geeft aan welke status de schakelaar moet krijgen.
ChangeTopic
Eenvoudige function node die /switch/ vervangt met /state/. Voor de rest zet hij het bericht 1-op-1 door naar de MQTT output node
lamp/433/state/#
Zet alle inkomende berichten 1-op-1 door naar de MQTT broker
433 light (input)
Deze vangt alle berichten af en stuurt ze door naar de volgende node
ConvertToMQTT
Deze checkt eerst of het bericht een schakelaar betreft (in mijn geval begint het adres dan met ARC
Volgende delen
Ik ben nog aan het uitzoeken wat de beste manier is op om deze manier mijn huis te automatiseren. Er zijn zelfs een paar architectuur voorstellen (zie bijvoorbeeld hier) Voor mij is het een heerlijke prutshobby (hoewel ik wel rekening moet houden met de WAF-factorMocht je vragen hebben dan hoor ik het graag.
Dit is mijn eerste tweakblog. Het is meer werk dan dat ik verwacht had, maar vond het wel leuk om mijn hobby projectje met jullie te delen. Wie weet later meer!