AXN10 Woes

I bought a Cambridge Audio AX system for my office because it was cheap and it let me play records too. It’s really not too bad but I have my suspicions over the AXN10 Network Streamer. I’ve noticed it has a tendency to stop playing after a while. It plays fine for a good four to six months and then it’s like it runs out of buffer space or something and can only play music in five second chunks followed by a five second pauses. It’s peculiar. It’s also done it three times now so it’s now something that needs investigating.

My current setup uses my music stores on a WD MyCloud Mirror (that also needs fixing) that is streamed out via AssetUPnP running on an Ubuntu 22.04.5 LTS box to my CXNv2 and my AXN10. I originally used Twonky but Twonky is now, effectively, a dead platform. It doesn’t and never will support the Disk Number fields so multi-disk albums are a problem with Twonky.

I was hoping that I could use AssetUPnP to log the music and the duration played but I’m not convinced it’s logging is that capable. It seemed to log connections from the TV but not from the CA AXN which is a bit of a problem when I’m interested in what the AXN is doing.

The AXN itself doesn’t seem to do any logging either but, obviously, the Stream Magic app connects over APIs to the device so I was wondering whether there was a hidden interface there that I could poke. I’m really not the best when it comes to reverse engineering interfaces so I did something really dumb and just put in the IP address of the AXN into a browser followed by /debug. Surprisingly, this returned a “Remote debug not enabled” message which immediately made me think that there must be a way to enable remote debug. Time to go digging…

Ecosia wasn’t really of much help here but Google, especially Googles AI bot was most helpful. Initially it pointed me to a very nice project on GitHub (https://github.com/noahhusby/aiostreammagic)

Now, I’m no python developer (I’m no developer at all, really) but by explaining what I was trying to achieve Google came up with the following program:

import asyncio
import csv
import os
import sys
from datetime import datetime
from aiostreammagic import StreamMagicClient

# CONFIGURATION
AXN10_IP = "IP GOES HERE"  # Replace with your exact AXN10 IP
LOG_FILE = "/usr/local/bin/axn10-tracker/streamer_playback_log.csv"

class PlaybackTracker:
    def __init__(self):
        self.current_track = None
        self.current_artist = None
        self.play_start_time = None
        self.last_state = None

    def log_to_csv(self, start_time, stop_time, artist, track, duration_seconds):
        """Appends a completed playback record to the CSV file."""
        file_exists = os.path.isfile(LOG_FILE)
        
        try:
            with open(LOG_FILE, mode='a', newline='', encoding='utf-8') as f:
                writer = csv.writer(f)
                if not file_exists:
                    writer.writerow(["Start Time", "Stop Time", "Artist", "Track", "Played Duration (Sec)", "Played Duration (Min)"])
                
                duration_minutes = round(duration_seconds / 60, 2)
                writer.writerow([
                    start_time.strftime("%Y-%m-%d %H:%M:%S"),
                    stop_time.strftime("%Y-%m-%d %H:%M:%S"),
                    artist or "Unknown Artist",
                    track or "Unknown Track",
                    round(duration_seconds, 1),
                    duration_minutes
                ])
            print(f"Logged to CSV: '{track}' by {artist} - {duration_minutes} mins.", flush=True)
        except Exception as e:
            print(f"Failed writing to CSV: {e}", file=sys.stderr, flush=True)

    async def on_state_change(self, client: StreamMagicClient, *args):
        """Official callback engine triggered immediately on AXN10 updates."""
        # Grab the core play state object safely
        ps_obj = client.play_state
        if ps_obj:
            # Extract simple state string (e.g., 'play', 'pause', 'stop', 'idle')
            play_state = getattr(ps_obj, 'state', 'stopped').lower()
            
            # Extract nested metadata objects
            metadata = getattr(ps_obj, 'metadata', None)
            track_title = getattr(metadata, 'title', None) if metadata else None
            artist_name = getattr(metadata, 'artist', None) if metadata else None
        else:
            play_state = "stopped"
            track_title = None
            artist_name = None

        # Clean diagnostic line showing exactly what song has been processed
        print(f"[TRACKER STATUS] State: {play_state.upper()} | Title: '{track_title}' by {artist_name}", flush=True)

        now = datetime.now()

        # CASE 1: Streamer just entered a play cycle
        if play_state == "play" and self.last_state != "play":
            self.play_start_time = now
            self.current_track = track_title
            self.current_artist = artist_name
            self.last_state = "play"
            print(f"Playback started: '{track_title}' by {artist_name}", flush=True)

        # CASE 2: Tracks shifted during active streaming
        elif play_state == "play" and self.current_track != track_title:
            if self.play_start_time:
                duration = (now - self.play_start_time).total_seconds()
                if duration > 2:
                    self.log_to_csv(self.play_start_time, now, self.current_artist, self.current_track, duration)
            
            self.play_start_time = now
            self.current_track = track_title
            self.current_artist = artist_name
            print(f"Track changed: '{track_title}' by {artist_name}", flush=True)

        # CASE 3: Playback stopped, paused, or returned to idle
        elif play_state in ["pause", "stop", "idle"] and self.last_state == "play":
            if self.play_start_time:
                duration = (now - self.play_start_time).total_seconds()
                if duration > 2:
                    self.log_to_csv(self.play_start_time, now, self.current_artist, self.current_track, duration)
            self.play_start_time = None
            self.current_track = None
            self.last_state = play_state
            print(f"Playback stopped ({play_state}).", flush=True)

async def main():
    tracker = PlaybackTracker()
    print(f"Initializing event pipeline for AXN10 at {AXN10_IP}...", flush=True)
    
    while True:
        try:
            client = StreamMagicClient(AXN10_IP)
            
            # 1. Bind our handler logic block
            await client.register_state_update_callbacks(tracker.on_state_change)
            
            # 2. ACTUALLY EXECUTE THE NETWORK HANDSHAKE CONNECTION
            await client.connect()
            
            print("Connected! Active socket listening for streaming metrics...", flush=True)
            
            # Keep the context block alive indefinitely
            while True:
                await asyncio.sleep(3600)
                
        except Exception as e:
            print(f"Network drop encountered: {e}. Reconnecting in 15 seconds...", file=sys.stderr, flush=True)
            await asyncio.sleep(15)

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nShutdown signal captured.")

This logs every event to a CSV and lets me keep track of everything that has been played and for how long. It also came up with a companion program to summarise the data for me. I probably could have done that bit myself but I was more interested in having something work that hacking around trying to make things work.

import csv
from datetime import datetime
from collections import defaultdict

LOG_FILE = "/usr/local/bin/axn10-tracker/streamer_playback_log.csv"

def analyze_logs():
    total_seconds = 0
    track_counts = defaultdict(int)
    track_durations = defaultdict(float)
    
    try:
        with open(LOG_FILE, mode='r', encoding='utf-8') as f:
            reader = csv.DictReader(f)
            
            for row in reader:
                # Calculate overall cumulative time
                seconds = float(row["Played Duration (Sec)"])
                total_seconds += seconds
                
                # Group data by track identifier
                track_identifier = f"'{row['Track']}' by {row['Artist']}"
                track_counts[track_identifier] += 1
                track_durations[track_identifier] += seconds
                
    except FileNotFoundError:
        print(f"Error: Could not find '{LOG_FILE}'. Make sure the logger script has run and recorded at least one song.")
        return

    # Convert total seconds into hours and minutes
    total_minutes = total_seconds / 60
    total_hours = total_minutes / 60
    
    print("=" * 50)
    print("      CAMBRIDGE AUDIO AXN10 PLAYBACK REPORT      ")
    print("=" * 50)
    print(f"Total Listening Time: {total_hours:.2f} Hours ({int(total_minutes)} Minutes)")
    print("-" * 50)
    
    # Sort and find the tracks listened to for the longest total duration
    print("Top 5 Most Listened-To Tracks (By Actual Duration):")
    sorted_by_duration = sorted(track_durations.items(), key=lambda x: x[1], reverse=True)
    
    for i, (track, seconds) in enumerate(sorted_by_duration[:5], 1):
        mins = seconds / 60
        print(f" {i}. {track} — Listened for {mins:.1f} mins total")

if __name__ == "__main__":
    analyze_logs()

The next thing we worked on was making it into a service so that it would always run. The last thing I needed was to forget to log a week or month’s worth of data and complete stuff my numbers up. Adding it as a service was pretty trivial.

First create the logger service:

sudo vi /etc/systemd/system/axn10-logger.service

   [Unit]
   Description=Cambridge Audio AXN10 Playback Logger
   After=network-online.target
   Wants=network-online.target

   [Service]
   Type=simple
   User=YOUR_UBUNTU_USERNAME
   WorkingDirectory=/usr/local/bin/axn10-tracker
   ExecStart=/usr/local/bin/axn10-tracker/venv/bin/python3 /usr/local/bin/axn10-tracker/axn10_logger.py
   Restart=always
   RestartSec=10
   StandardOutput=journal
   StandardError=journal

   [Install]
   WantedBy=multi-user.target

then enable and run the service:

sudo systemctl daemon-reload
sudo systemctl enable axn10-logger.service
sudo systemctl start axn10-logger.service

It actually took a few iterations to get the logging code to properly run as a service and to log the data correctly but Google helped me achieve something I could not have done on my own.

So now, every time I play something on my AXN it gets logged to a file and over time it will show me, not only the total play time between failures, it will also show me what artists / albums / songs I’m listening to the most. That’s pretty cool.

Expanding a RAID – Part Deux

Make sure the filesystem isn’t being used:

sudo systemctl stop plexmediaserver
sudo systemctl stop smbd

unmount the filesystem

sudo umount /storage

use parted to resize the filesystem

sudo parted
resize part 1 100%

remount

sudo mount /storage

resize the Btrfs filesystem

sudo btrfs filesystem resize max /storage

and, all being well, the system isn’t hosed.

Expanding a RAID

Quick overview more for me than anything else:

lsblk to see disks in system:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage
sdb 8:16 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage
sdc 8:32 0 3.6T 0 disk
├─sdc1 8:33 0 1G 0 part
├─sdc2 8:34 0 1G 0 part
│ └─md0 9:0 0 1022M 0 raid1
│ └─md0p1 259:2 0 1020M 0 part /boot
├─sdc3 8:35 0 128G 0 part
│ └─md1 9:1 0 127.9G 0 raid1
│ └─md1p1 259:1 0 127.9G 0 part [SWAP]
└─sdc4 8:36 0 3.5T 0 part
└─md2 9:2 0 3.5T 0 raid1
└─md2p1 259:3 0 3.5T 0 part /
sdd 8:48 0 3.6T 0 disk
├─sdd1 8:49 0 1G 0 part /boot/efi
├─sdd2 8:50 0 1G 0 part
│ └─md0 9:0 0 1022M 0 raid1
│ └─md0p1 259:2 0 1020M 0 part /boot
├─sdd3 8:51 0 128G 0 part
│ └─md1 9:1 0 127.9G 0 raid1
│ └─md1p1 259:1 0 127.9G 0 part [SWAP]
└─sdd4 8:52 0 3.5T 0 part
└─md2 9:2 0 3.5T 0 raid1
└─md2p1 259:3 0 3.5T 0 part /
sde 8:64 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage
sdf 8:80 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage

add in new disk and lsblk again:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage
sdb 8:16 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage
sdc 8:32 0 3.6T 0 disk
├─sdc1 8:33 0 1G 0 part
├─sdc2 8:34 0 1G 0 part
│ └─md0 9:0 0 1022M 0 raid1
│ └─md0p1 259:2 0 1020M 0 part /boot
├─sdc3 8:35 0 128G 0 part
│ └─md1 9:1 0 127.9G 0 raid1
│ └─md1p1 259:1 0 127.9G 0 part [SWAP]
└─sdc4 8:36 0 3.5T 0 part
└─md2 9:2 0 3.5T 0 raid1
└─md2p1 259:3 0 3.5T 0 part /
sdd 8:48 0 3.6T 0 disk
├─sdd1 8:49 0 1G 0 part /boot/efi
├─sdd2 8:50 0 1G 0 part
│ └─md0 9:0 0 1022M 0 raid1
│ └─md0p1 259:2 0 1020M 0 part /boot
├─sdd3 8:51 0 128G 0 part
│ └─md1 9:1 0 127.9G 0 raid1
│ └─md1p1 259:1 0 127.9G 0 part [SWAP]
└─sdd4 8:52 0 3.5T 0 part
└─md2 9:2 0 3.5T 0 raid1
└─md2p1 259:3 0 3.5T 0 part /
sde 8:64 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage
sdf 8:80 0 9.1T 0 disk
└─md3 9:3 0 27.3T 0 raid5
└─md3p1 259:0 0 27.3T 0 part /storage
sdg 8:96 0 9.1T 0 disk
├─sdg1 8:97 0 2G 0 part
│ └─md127 9:127 0 0B 0 md
├─sdg2 8:98 0 9.1T 0 part
│ └─md126 9:126 0 0B 0 md
├─sdg3 8:99 0 1G 0 part
└─sdg4 8:100 0 1G 0 part

/dev/sdg has been added

However, because sdg is showing as md127 we need to stop and remove the raid:

mdadm --stop /dev/md127
mdadm --remove /dev/md127

now we can partition the disk

use parted to wipe filesystem and add a new label to the disk

parted -s -a optimal /dev/sdg mklabel gpt

Use fdisk to check the new GTP Partition tables. Don’t bother to create any partitions.

fdisk -p to check out the unpartitioned disk:

$ sudo fdisk /dev/sdg
Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sdg: 9.1 TiB, 10000831348736 bytes, 19532873728 sectors
Disk model: WDC WD100EFAX-68
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 56FF5A1F-FE90-4AB1-ABD6-DBB1E1D22042

Command (m for help): q

Just check to see which array you’re adding the disk to:

$ cat /prod/mdstat

Personalities : [raid6] [raid5] [raid4] [raid1] [raid0] [raid10]
md1 : active raid1 sdd3[1] sde3[0]
134085632 blocks super 1.2 [2/2] [UU]
bitmap: 0/1 pages [0KB], 65536KB chunk

md2 : active raid1 sdd4[1] sde4[0]
3770516480 blocks super 1.2 [2/2] [UU]
bitmap: 1/29 pages [4KB], 65536KB chunk

md0 : active raid1 sdd2[1] sde2[0]
1046528 blocks super 1.2 [2/2] [UU]

md3 : active raid5 sdf[2] sdb[1] sdg[4] sda[0]
29298914304 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
bitmap: 0/73 pages [0KB], 65536KB chunk

unused devices: <none>

md3 in this case. Add the disk into the array:

mdadm --add /dev/md3 /dev/sdg

Check the array:

$ sudo mdadm --add /dev/md3 /dev/sdg
mdadm: added /dev/sdg

sysadmin@tnas:~$ cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid1] [raid0] [raid10]
md1 : active raid1 sdd3[1] sde3[0]
134085632 blocks super 1.2 [2/2] [UU]
bitmap: 0/1 pages [0KB], 65536KB chunk

md2 : active raid1 sdd4[1] sde4[0]
3770516480 blocks super 1.2 [2/2] [UU]
bitmap: 2/29 pages [8KB], 65536KB chunk

md0 : active raid1 sdd2[1] sde2[0]
1046528 blocks super 1.2 [2/2] [UU]

md3 : active raid5 sdc5 sdf[2] sdb[1] sdg[4] sda[0]
29298914304 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
bitmap: 0/73 pages [0KB], 65536KB chunk

The disk is now visible in the array: sdc5 but it’s marked as a spare disk (S).

Now we need to grow the array:

mdadm --grow /dev/md3 --raid-devices=5

where the number of raid devices is the number of disks we want in the raid.

Watch /proc/mdstat to see the progress:

$ cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid1] [raid0] [raid10]
md1 : active raid1 sdd3[1] sde3[0]
134085632 blocks super 1.2 [2/2] [UU]
bitmap: 0/1 pages [0KB], 65536KB chunk

md2 : active raid1 sdd4[1] sde4[0]
3770516480 blocks super 1.2 [2/2] [UU]
bitmap: 1/29 pages [4KB], 65536KB chunk

md0 : active raid1 sdd2[1] sde2[0]
1046528 blocks super 1.2 [2/2] [UU]

md3 : active raid5 sdc[5] sdf[2] sdb[1] sdg[4] sda[0]
29298914304 blocks super 1.2 level 5, 512k chunk, algorithm 2 [5/5] [UUUUU]
[>………………..] reshape = 0.0% (337408/9766304768) finish=3376.6min speed=48201K/sec
bitmap: 0/73 pages [0KB], 65536KB chunk

unused devices: <none>

Yep, this is going to take a while. Time to put the kettle on.

Helpful guides:

https://wpguru.co.uk/2021/01/expand-software-raid-mdadm/
https://www.itsfullofstars.de/2019/03/how-to-add-a-new-disk-to-raid5/
https://tomlankhorst.nl/setup-lvm-raid-array-mdadm-linux

MTU Sizing

Edit /etc/netplan/50-cloud-init.yaml

network:
ethernets:
enp3s0:
dhcp4: true
dhcp6: true
mtu: 1472
version: 2

Then do:

sudo netplan try

and accept the change if it seems to work.

  • the default frame size is 1500.

Syslog Time Wrong

With the TNAS I’ve stumbled across an issue while watching the syslog.

Date returns a sensible value

TNAS:/var/log# date
Wed Jan 15 19:19:10 GMT 2025

but

TNAS:/var/log# tail -f messages 
Jan 16 03:18:01 TNAS cron[9540]: (CRON) STAT FAILED (/etc/crontab)

and

TNAS:/var/log# tail -f syslog 
Jan 16 03:05:01 TNAS cron[9540]: (CRON) STAT FAILED (/etc/crontab)

the fix is pretty simple. Make sure that local time is pointing to the right location:

TNAS:~# ls -l /etc/localtime 
lrwxrwxrwx 1 ****** ****** 33 Jan 12 17:26 /etc/localtime -> /usr/share/zoneinfo/Europe/London

then just restart syslog

TNAS:~# systemctl restart syslog

Ubuntu Firmware Update

This was a new thing I came across this morning:

2 devices have a firmware upgrade available.

Run `fwupdmgr get-upgrades` for more information.

I’ve not seen that before so I had to figure out how to fix the issue. Turns out it’s pretty simple:

fwupdmgr get-upgrades

Shows the available upgrades

fwupdmgr update

Applies any updates.

Ubuntu

As much as I love Docker (even though I’m not brilliant with it) sometimes I just need a proper server. In this case I need a nice shiny WebDav server with the ability to show web pages too.

I’m using Ubuntu for this because, as much as I like Debian, I find Ubuntu just that little bit easier to work with. Except Snap. Snap can burn in hell. The rest of it is pretty nice though.

The plan is to use Nginx as the web /WebDav server and if I can configure it up the way I need and get it doing everything I want I can then get the UNIX team at work to build me one for the office. I can’t help but wonder if they can manage that.

Ubuntu on USB

I can never remember how to do this and the Ubuntu pages are, surprisingly, useless. So, for future reference:

  • Download Ubuntu server from: https://ubuntu.com/download/server
  • Write it to a USB stick: dd if=ubuntu-24.04.1-live-server-amd64.iso of=/dev/disk2 bs=1m
  • Set PC to boot from USB stick
  • Boot.

In my case I’m using a small Dell OptiPlex 7070 Micro. So, to get into the BIOS it’s:

  • Boot
  • Hammer F2
  • General -> Advanced Boot Options -> Enable Legacy Option ROMs
  • General ->Boot Sequence -> Legacy External Devices
  • Reboot
  • Hammer F2
  • General -> Boot Sequence -> USB Storage Device

It should now be possible to boot from the USB stick.

When partitioning the disk don’t get confused between the USB stick filesystem and the PC filesystem. It’s pretty easy once you realise that the PC is NVME.