Mastodon

Sunday 24 September 2023

The ProgPod Mini

I'm one of these people that needs some music or some sort of sounds playing to get me to sleep. I can sleep through music, a thunderstorm, heavy winds. But a dripping tap, someone snoring or even heavy breathing and I'm wide awake.


I wanted an mp3 player that I could easily drag and drop music onto, some of the discontinued Apple device were great for this even though you had to use iTunes. I wanted a Windows share I could use and so my Pipod Mini-ish was born.




I put together a Raspberry Pi zero, a set of bluetooth earbuds, an SD card, a plastic box, 4 PCB mount switches, some vero board and a few bits of wire. On top of this there's a small board that acts as the psu and of course some hot glue. It's not pretty but it does work.

The physical side is up to you, a 3d printer could come up with quite a nice case and you could look at adding a display too. For this, I wasn't bothered as battery life was important.

When you set the Pi up for the first time with raspi-config set your user to auto login at the console.

First off, get some software installed.

sudo apt update
sudo apt upgrade
sudo apt-get install pulseaudio pulseaudio-module-bluetooth mpg123 mc samba samba-common bluez-tools

Add your user to bluetooth
sudo usermod -G bluetooth -a username


And now time for a restart
sudo shutdown -r now


Once it's back up and running open up a terminal and run.
pulseaudio --start

Then run bluetoothctl
Use "help" if you want more details about the available commands. The first time, you'll have to run the following:

power on
agent on
scan on
wait for the device to be discovered, note it's address (you can then use tab for auto-completion). For example, a set of ear buds I have show as Device 58:B3:BD:18:21:CE A90 Pro
pair 58:B3:BD:18:21:CE
trust 58:B3:BD:18:21:CE
connect 58:B3:BD:18:21:CE wait for the confirmation of connection and then type quit


Now we edit edit /etc/pulse/default.pa
sudo nano edit /etc/pulse/default.pa

Add this to the bottom of the file, then save and exit.

# automatically switch to newly-connected devices
load-module module-switch-on-connect

Then edit edit /etc/bluetooth/main.conf
sudo nano /etc/bluetooth/main.conf

Make sure this is showing at the end.

[Policy]
AutoEnable=true

Edit the bluetooth service with
sudo nano /lib/systemd/system/bluetooth.service

Look for this line:
ExecStart=/usr/lib/bluetooth/bluetoothd
and add --plugin=a2dp to the end so it looks like:
ExecStart=/usr/lib/bluetooth/bluetoothd --plugin=a2dp


Restart the service with:
systemctl daemon-reload
systemctl restart bluetooth


I wanted to be able to switch tracks and control the volume from four keys, switching the tracks was easy and just needed this adding into the /boot/config.txt file.

sudo nano /boot/config.txt

Add this to the end.

dtoverlay=gpio-key,gpio=16,keycode=33,label="Next"
dtoverlay=gpio-key,gpio=19,keycode=32,label="Previous"
dtoverlay=gpio-shutdown


I used similar options for the volume but nothing happened, so a bit of python controls this.

nano mixer.py


Paste this lot in

#!/bin/python
from gpiozero import Button
from signal import pause
from subprocess import Popen


def increase_volume():
global is_muted
if is_muted:
toggle_volume()
Popen(['amixer', 'sset', 'Master', '2%+'])


def decrease_volume():
global is_muted
if is_muted:
toggle_volume()
Popen(['amixer', 'sset', 'Master', '2%-'])


def toggle_volume():
global is_muted
Popen(['amixer', 'sset', 'Master', 'toggle'])
is_muted = not is_muted


def mute_volume():
global is_muted
if not is_muted:
toggle_volume()


is_muted = False #set it off to begin with


button_up = Button(20)
button_up.when_pressed = increase_volume
button_down = Button(21)
button_down.when_pressed = decrease_volume
button_down.when_held = mute_volume
pause()




I've created the music folder with:
sudo mkdir /mnt/Music
sudo chmod 0777 /mnt/Music


Then created a link to the user folder with
cd ~/
ln -s /mnt/Music


Amend the smb.conf file with
sudo nano /etc/samba/smb.conf


Add this to the bottom, then save and exit.

[Music]
comment = MP3 Files
path = /mnt/Music
guest ok = yes
browseable = yes
create mask = 0777
directory mask = 0777
read only = no


Last thing is to get it all playing on startup.

I made a file to run at startup with:

sudo nano /usr/local/bin/runmusic

This is the contents of the file:

#!/bin/bash
cd /home/username/Music
pulseaudio --start
amixer sset Master 40%,40% on
python /home/username/mixer.py &
mpg123 -CvZ --stereo --gapless *.mp3


Save that and then run:
sudo chmod +x /usr/local/bin/runmusic


Next up is:
sudo nano ~/.bashrc

Add this to the end:
/usr/local/bin/runmusic


And finally, make a file called winstall.sh or something, it really isn't important.


nano winstall.sh


Copy this lot into it


mkdir ~/temp
cd ~/temp


echo "Installing Window Networking Service"
wget https://github.com/christgau/wsdd/archive/master.zip
unzip master.zip
sudo mv wsdd-master/src/wsdd.py wsdd-master/src/wsdd
sudo cp wsdd-master/src/wsdd /usr/bin


echo "[Unit]">wsdd.service
echo "Description=Web Services Dynamic Discovery host daemon">>wsdd.service
echo "; Start after the network has been configured">>wsdd.service
echo "After=network-online.target">>wsdd.service
echo "Wants=network-online.target">>wsdd.service
echo "; It makes sense to have Samba running when wsdd starts, but is not required">>wsdd.service
echo "Wants=smb.service">>wsdd.service
echo "[Service]">>wsdd.service
echo "Type=simple">>wsdd.service
echo "ExecStart=/usr/bin/wsdd --shortlog">>wsdd.service
echo "; The following lines can be used for a chroot execution of wsdd.">>wsdd.service
echo "; Also append '--chroot /run/wsdd' to ExecStart to enable chrooting">>wsdd.service
echo "; AmbientCapabilities=CAP_SYS_CHROOT">>wsdd.service
echo "ExecStartPre=/bin/mkdir -p /run/wsdd">>wsdd.service
echo "ExecStartPre=/usr/bin/install -d -o nobody -g nogroup -m 0700 /run/wsdd">>wsdd.service
echo "ExecStopPost=rmdir /run/wsdd">>wsdd.service
echo "[Install]">>wsdd.service
echo "WantedBy=multi-user.target">>wsdd.service


sudo mv wsdd.service /etc/systemd/system/wsdd.service
sudo systemctl daemon-reload
sudo systemctl start wsdd.service
sudo systemctl enable wsdd


sudo systemctl daemon-reload
sudo service smbd restart

cd ~/
rm -rf temp

run it with sh winstall.sh

Once completed you should find the Raspberry Pi visible in the Windows Network

Save and then reboot.


To get my headphones to connect I have to put them back in the case and take them out once the Pi has started up. You could use the audio out on a Pi 3 or Pi4 or add a USB sound card to your Pi Zero. I don't really want any more wires.


Last thing I'll be doing is adding a charge socket to the bottom and power off button to shut it down cleanly.


I'm not clever enough to think this lot up by myself so thanks to Actuino at https://gist.github.com/actuino/9548329d1bba6663a63886067af5e4cb for the initial guidance and someone else for the python mixer script.



Tuesday 1 August 2023

Raspberry Pi Access Point

 So you go on holiday and you take your tablets, laptop, phones and other stuff that connects to wifi. You then have to go and enter the new network details into each device to the new network and you put the details away and then find there's something else you haven't connected.

Wouldn't it be nice to take your own wifi connection with you.

So, I had a spare Raspberry Pi zero W version 2, broken camera port, a nice little case, a micro USB to large USB adaptor and some hot glue. All I needed was a second wifi adaptor.

I got this one from our friends at Amazon.

You don't have to get this one, I bought it and it works but feel free to try out any other ones.

First thing of course is to install Raspbian onto the Pi. I've gone for the lite 32 bit version. No desktop but it really isn't a problem. I'm not going through the setup process as if you can't do that you shouldn't do this. And all the config is done through ssh to the onboard wifi. Anything below that's in bold and italics is ok to copy and paste. 

Once you have finished setting it up, plug the adaptor in and you'll find like I did that although it's detected it doesn't work, yet.

The documentation with the adaptor gives you a link to the manufacturers website.

On the webpage it tells you to run the following.

 sh -c 'wget linux.brostrend.com/install -O /tmp/install && sh /tmp/install'

It takes a while and then it just works, you'll have the onboard adaptor of wlan0 and this one wlan2. 

Now we start doing other things and getting some software installed.

sudo apt install hostapd dnsmasq mc

I like mc, it's like Xtree Gold from the old dos days and is a great way to navigate the file system.

Now we run this.

sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent

After that reboot with sudo reboot.

Once it's restarted more configuring files to get it all working.

sudo nano /etc/dhcpcd.conf

Paste all this in at the end.

interface wlan1

    static ip_address=192.168.4.1/24
    nohook wpa_supplicant

Save the files each time you finish, then onto.

sudo nano /etc/sysctl.d/routed-ap.conf

Paste this in and then save.

# Enable IPv4 routing
net.ipv4.ip_forward=1


Add a firewall rule with 
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

Save the firewall rules with:

sudo netfilter-persistent save

And now setup DHCP and DNS stuff

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf

Add the following to the file and save it.

interface=wlan1
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
domain=wlan
address=/gw.wlan/192.168.4.1


Now we setup the access point software.

sudo nano /etc/hostapd/hostapd.conf

Paste this in, changing the country code to where you live, the ssid to the same as your home one if you want and the passphrase needs to be changed too.

country_code=UK

interface=wlan1

ssid=SSID

hw_mode=g

channel=7

macaddr_acl=0

auth_algs=1

ignore_broadcast_ssid=0

wpa=2

wpa_passphrase=PWD

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP

rsn_pairwise=CCMP

Now we run this to get it starting up when the pi boots.


sudo systemctl unmask hostapd

sudo systemctl enable hostapd

sudo systemctl start hostapd


Then give it one final reboot and you should see a new wifi connection pop up.

That's about it really.

Thanks to hackster.io for the initial guidance and Github for a little help in making it work.

You can use just about any Pi for this, seems to work quite well and I may even add  a connection to my vpn from it.

If you want to connect the Pi to a different wifi connection when you're away and travelling, boot it up, ssh into it and run 

sudo raspi-config



Select option 1

Then select S1 and enter the wifi connection details there. There may be a more elegant way like setting up a graphical desktop but this is nice and minimal and it works.

Here's some pictures of the complete thing with a few magnets attached to the back to make it easy to stick to things. And yes, I went overboard with the hot glue gun as I was going to make something that was waterproof first.

Hope this all makes sense to you and have fun.












Thursday 12 January 2023

PIxelfed



The easiest way to describe Pixelfed is to say it's a federated version of Instagram. There's no big bad company behind it, your data is on your server and you can easily run your own at home if you want too. This can connect to any other Pixelfed instance in the Fediverse as it's called.







The image-sharing platform defines itself as “A free and ethical photo-sharing platform” with no ads, third-party analytics, or tracking.

You can find more on pixelfed.org

What Pixelfed does need is more servers to spread the load, I've put this guide together based on some notes from the Pixelfed website itself and another website that I can't for the life of me find to give credit to.

You will need an install of Ubuntu Server 22.04 to run this using these instructions.

Let us begin

Change to root user

sudo -i

Install latest updates

apt update

apt upgrade -y

reboot now

Then install the required software

apt -y install redis-server mariadb-server ffmpeg jpegoptim optipng pngquant gifsicle unzip zip php-fpm php-cli php-bcmath php-curl php-gd php-intl php-mbstring php-redis php-xml php-zip php-mysql nginx certbot python3-certbot-nginx mc php-json php-tokenizer php-imagick

Make some changes to the php config files

nano /etc/php/8.1/fpm/php.ini

Edit these lines, I've set the max size and max filesize to 100M , max file uploads is 50

post_max_size (default 8M, set this around or slightly greater than your desired post size limit)

file_uploads (default On, which it needs to be)

upload_max_filesize (default 2M, set this <= post_max_size)

max_file_uploads (default 20, but make sure it is >= your desired attachment limit)

max_execution_time (default 30, consider raising this to 600 or more so that longer tasks arent interrupted)


And change the line that says

;date.timezone =

to

date.timezone = Europe/London

or wherever your timezone is.

Enable some of the services

systemctl enable redis-server

systemctl enable mariadb


Setup the database

mysql_secure_installation

mysql -u root -p

create database pixelfed;

grant all privileges on pixelfed.* to 'pixelfed'@'localhost' identified by 'yourpassword';

flush privileges;

exit;



Install Composer

curl -sS <https://getcomposer.org/installer -o /tmp/composer-setup.php>

php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer



Get the software downloaded

cd /var/www

git clone -b dev https://github.com/pixelfed/pixelfed.git pixelfed

cd pixelfed

composer install --no-ansi --no-interaction --optimize-autoloader

cp .env.example .env

nano .env



Edit these lines to your requirements

# Instance Configuration

OPEN_REGISTRATION="true"

ENFORCE_EMAIL_VERIFICATION="false"

PF_MAX_USERS="1000"

OAUTH_ENABLED="true"



# Instance URL Configuration

APP_URL="https://pixelfed.yourdomain"

APP_DOMAIN="pixelfed.yourdomain"

ADMIN_DOMAIN="pixelfed.yourdomain"

SESSION_DOMAIN="pixelfed.yourdomain"

TRUST_PROXIES="*"



# Database Configuration

DB_CONNECTION="mysql"

DB_HOST="127.0.0.1"

DB_PORT="3306"

DB_DATABASE="pixelfed"

DB_USERNAME="pixelfed"

DB_PASSWORD="yourpassword"



# ActivityPub Configuration

ACTIVITY_PUB="true"

AP_REMOTE_FOLLOW="true"

AP_INBOX="true"

AP_OUTBOX="true"

AP_SHAREDINBOX="true"


Setup the permissions

sudo chown -R www-data:www-data /var/www/pixelfed

sudo find . -type d -exec chmod 755 {} \; # set all directories to rwx by user/group

sudo find . -type f -exec chmod 644 {} \; # set all files to rw by user/group


Generate the secret APP_KEY:

php artisan key:generate

Storage/ directory must be linked to the application:

php artisan storage:link

Database migrations must be run:

php artisan migrate --force

If you want to enable support for location data:

php artisan import:cities

If you enabled ActivityPub federation:

php artisan instance:actor

If you enabled OAuth:

php artisan passport:keys

Routes should be cached whenever the source code changes or whenever you change routes:

php artisan route:cache

php artisan view:cache


Every time you edit your .env file, you must run this command to have the changes take effect:

php artisan config:cache

Setup Laravel Horizon - Job queueing

php artisan horizon:install

php artisan horizon:publish


Let's make a startup service for Pixelfed with

nano /etc/systemd/system/pixelfed.service

Paste this in

[Unit]

Description=Pixelfed task queueing via Laravel Horizon

After=network.target

Requires=mariadb

Requires=php8.1-fpm

Requires=redis

Requires=nginx



[Service]

Type=simple

ExecStart=/usr/bin/php artisan horizon --environment=production

ExecStop=/usr/bin/php artisan horizon:terminate --wait

User=www-data

WorkingDirectory=/var/www/pixelfed/

Restart=on-failure



KillSignal=SIGCONT

TimeoutStopSec=3600



[Install]

WantedBy=multi-user.target


Save and exit then run the following to get the services activated

systemctl daemon-reload

systemctl enable pixelfed

systemctl status pixelfed


Create a cron task to do some tidying up

crontab -e

Paste this in

* * * * * /usr/bin/php /var/www/pixelfed/artisan schedule:run >> /dev/null 2>&1


Enable nginx

systemctl enable nginx

Disable the default site

unlink /etc/nginx/sites-enabled/default

Create the pixelfed website

cp /var/www/pixelfed/contrib/nginx.conf /etc/nginx/sites-available/pixelfed.conf

ln -s /etc/nginx/sites-available/pixelfed.conf /etc/nginx/sites-enabled/

nano /etc/nginx/sites-available/pixelfed.conf


Change the server name and the path to your chosen ones and amend the line that says

fastcgi_pass unix:/run/php-fpm/php-fpm.sock; # make sure this is correct

to

fastcgi_pass unix:/run/php/php-fpm.sock; # make sure this is correct

Setup an initial ssl connection, it doesn't need to be done but it's easier.

sudo mkdir /etc/nginx/ssl

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt

systemctl reload nginx

service php8.1-fpm restart

service nginx restart

service pixelfed restart

Install proper ssl certificates

certbot

Create the first user and make admin,

php artisan user:create

And that is it so far, you can now go to https://pixelfed.yourdomain and have some fun.


Once that's all done, I have added a few extra lines to the bottom of the .env file

ENABLE_CONFIG_CACHE=true

MAX_BIO_LENGTH=500

IMPORT_INSTAGRAM=true

MAX_PHOTO_SIZE=100000

IMAGE_DRIVER=imagick

LIMIT_ACCOUNT_SIZE=false

Make sure you run the following to activate the changes.


php artisan config:cache


You really should also setup a firewall to allow only the required connections, you can do this with.


sudo ufw allow http
sudo ufw allow https


You should also setup a port for connection by ssh, the default port is 22 so you would run
sudo ufw allow 22


It would be a good idea to change the port from the default.


Run sudo ufw enable
To enable the firewall, that's it people.


Feel free to look me up on pixelfed @paulholt@pixelfed.travelsoftux.co.uk and look up the man behind it all, @dansup@pixelfed.social.


Saturday 24 December 2022

Countdown To Christmas 2022, Day 10

Last one of the year, it's got to be Greg Lake and I believe in Father Christmas. 

Have a good one and let's hope next year is better again.



Spotify Link



Itunes Link


Friday 23 December 2022

Countdown To Christmas 2022, Day 9

Day 9, last day for this tomorrow, this has to be in there. 

It's Slade with Merry Christmas Everybody.



Spotify Link




ITunes Link


Wednesday 21 December 2022

Countdown To Christmas 2022, Day 8

 From way back in 1974, this is Showaddywaddy and Hey Mr Christmas. Christmas music as if should be, fun, kids singing, slighbells.



Spotify Link


Itunes Link

Tuesday 20 December 2022

Countdown To Christmas 2022, Day 7

From way back this is another great Christmas track.

Band Aid, Do They Know It's Christmas




Spotify Link




ITunes Link