Categories
Auditing Powershell

Function: Internet Radio Control – Frontier Silicon

The below uses the PowerShell invoke web request cmdlet to control a Roberts Internet Radio using the Frontier Silicon API. I have tied this in with my home automation to turn the radio on and off as feedback what is playing.

 

 

New-FSRadioSession
Session Created With Kitchen Radio

Set-FSRadioPowerOn
Kitchen Radio Switched On

Set-FSRadioVolume
Please Enter A Value Between 1 and 20: 3
Volume Set To 3 On Kitchen Radio

Set-FSRadioVolumeStepUp
Volume Increased To 4 On Kitchen Radio

Set-FSRadioVolumeStepDown
Volume Decreased To 3 On Kitchen Radio

Set-FSRadioMuteOn
Volume Muted On Kitchen Radio

Set-FSRadioMuteOff
Volume Unmuted On Kitchen Radio

Set-FSRadioMode
Please Enter The Number Of The Mode You Wish To Select 0 = Internet Radio 1 = Spotify
3 = Music Player 4 = DAB Radio 5 = FM Radio 6 = AUX In : 1
Mode 1 Successfully Selected On Kitchen Radio

Set-FSRadioPause
Pause Successful On Kitchen Radio

Set-FSRadioPlay
Play Successful On Kitchen Radio

Set-FSRadioNext
Next Successful On Kitchen Radio

Set-FSRadioPrevious
Previous Successful On Kitchen Radio

Set-FSRadioMode
Please Enter The Number Of The Mode You Wish To Select 0 = Internet Radio 1 = Spotify
3 = Music Player 4 = DAB Radio 5 = FM Radio 6 = AUX In : 5
Mode 5 Successfully Selected On Kitchen Radio

Set-FSRadioFrequency
Please enter the frequency eg.99400 = 96.40 MHz: 99400
Frequency Successfully Set On Kitchen Radio

Set-FSRadioPreset
Please Enter The Number In Which To Store The Preset 0-9: 5
Preset Set Successfully On Kitchen Radio

Set-FSRadioMode
Please Enter The Number Of The Mode You Wish To Select 0 = Internet Radio 1 = Spotify
3 = Music Player 4 = DAB Radio 5 = FM Radio 6 = AUX In : 1
Mode 1 Successfully Selected On Kitchen Radio

Set-FSRadioRepeatOn
Repeat Enabled On Kitchen Radio

Set-FSRadioRepeatOff
Repeat Disabled On Kitchen Radio

Set-FSRadioShuffleOn
Shuffle Enabled On Kitchen Radio

Set-FSRadioShuffleOff
Shuffle Disabled On Kitchen Radio

Get-FSRadioPowerStatus
Kitchen Radio Is Currently On

Get-FSRadioPlayStatus
Kitchen Radio Is Playing

Set-FSRadioPause
Pause Successful On Kitchen Radio

Get-FSRadioPlayStatus
Kitchen Radio Is Paused

Set-FSRadioPlay
Play Successful On Kitchen Radio

Get-FSRadioVolume
Volume Set To 3 On Kitchen Radio

Get-FSRadioNowPlaying
Now Playing On Kitchen Radio…

Artist

Title

Album


#Setting Up Session and fetching Session ID
Function New-FSRadioSession{
$Global:RadioIP = Read-Host "Please enter IP address of the Radio"
$Global:RadioPIN = Read-Host "Please enter the PIN of your radio (Default is 1234)"

[XML]$SessionRequest = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/CREATE_SESSION?pin=$RadioPIN"
if($SessionRequest -ne $null){
           $Global:SessionID = $SessionRequest.fsapiResponse.sessionId
           [XML]$FriendlyNameFetch = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.sys.info.friendlyName?pin=$RadioPIN&sid=$SessionID"
           $Global:FriendlyName = $FriendlyNameFetch.fsapiResponse.value.c8_array
           Write-Host "Radio Session Created With $FriendlyName" -ForegroundColor Magenta
        }
else{Write-Host "Could Not Create Radio Session" -ForegroundColor Red}
}

#PowerOn
Function Set-FSRadioPowerOn{
[XML]$PowerOn = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.power?pin=$RadioPIN&sid=$SessionID&value=1"
if($PowerOn.fsapiResponse.status -eq "FS_OK"){Write-Host "$FriendlyName Radio Switched On" -ForegroundColor Magenta}
else{Write-Host "Failed To Turn On $FriendlyName Radio" -ForegroundColor Red}
}

#PowerOff
Function Set-FSRadioPowerOff{
[XML]$PowerOff = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.power?pin=$RadioPIN&sid=$SessionID&value=0"
if($PowerOff.fsapiResponse.status -eq "FS_OK"){Write-Host "$FriendlyName Radio Switched Off" -ForegroundColor Magenta}
else{Write-Host "Failed To Turn Off $FriendlyName Radio" -ForegroundColor Red}
}

#SetVolumeLevel
Function Set-FSRadioVolume{
$VolumeValue = Read-Host "Please Enter A Value Between 1 and 20"
[XML]$Volume = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.audio.volume?pin=$RadioPIN&sid=$SessionID&value=$VolumeValue"
if($Volume.fsapiResponse.status -eq "FS_OK"){Write-Host "Volume Set To $VolumeValue On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Failed To Set Volume To $VolumeValue On $FriendlyName Radio" -ForegroundColor Red}
}

#VolumeStepUp
Function Set-FSRadioVolumeStepUp{
[XML]$VolumeStepUpCurrentValue = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.sys.audio.volume?pin=$RadioPIN&sid=$SessionID" 
$VolumeStepUpNewValue = [int]$VolumeStepUpCurrentValue.fsapiResponse.value.u8 + 1
[XML]$VolumeStepUp = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.audio.volume?pin=$RadioPIN&sid=$SessionID&value=$VolumeStepUpNewValue" 
if($VolumeStepUp.fsapiResponse.status -eq "FS_OK"){Write-Host "Volume Increased To $VolumeStepUpNewValue On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Failed To Increase Volume To $VolumeStepUpNewValue On $FriendlyName Radio" -ForegroundColor Red}
}

#VolumeStepDown
Function Set-FSRadioVolumeStepDown{
[XML]$VolumeStepDownCurrentValue = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.sys.audio.volume?pin=$RadioPIN&sid=$SessionID" 
$VolumeStepDownNewValue = [int]$VolumeStepDownCurrentValue.fsapiResponse.value.u8 - 1
[XML]$VolumeStepDown = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.audio.volume?pin=$RadioPIN&sid=$SessionID&value=$VolumeStepDownNewValue" 
if($VolumeStepDown.fsapiResponse.status -eq "FS_OK"){Write-Host "Volume Decreased To $VolumeStepDownNewValue On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Failed To Decrease Volume To $VolumeStepDownNewValue On $FriendlyName Radio" -ForegroundColor Red}
}

#MuteVolumeOn
Function Set-FSRadioMuteOn{
[XML]$MuteOn = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.audio.mute?pin=$RadioPIN&sid=$SessionID&value=1"
if($MuteOn.fsapiResponse.status -eq "FS_OK"){Write-Host "Volume Muted On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Failed To Mute Volume On $FriendlyName Radio" -ForegroundColor Red}
}

#MuteVolumeOff
Function Set-FSRadioMuteOff{
[XML]$MuteOff = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.audio.mute?pin=$RadioPIN&sid=$SessionID&value=0"
if($MuteOff.fsapiResponse.status -eq "FS_OK"){Write-Host "Volume Unmuted On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Failed To Unmute Volume On $FriendlyName Radio" -ForegroundColor Red}
}

#Play
Function Set-FSRadioPlay{
[XML]$Play = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.control?pin=$RadioPIN&sid=$SessionID&value=1"
if($Play.fsapiResponse.status -eq "FS_OK"){Write-Host "Play Successful On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Play Unsuccessful On $FriendlyName Radio" -ForegroundColor Red}
}

#Pause
Function Set-FSRadioPause{
[XML]$Pause = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.control?pin=$RadioPIN&sid=$SessionID&value=2"
if($Pause.fsapiResponse.status -eq "FS_OK"){Write-Host "Pause Successful On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Pause Unsuccessful On $FriendlyName Radio" -ForegroundColor Red}
}

#Next
Function Set-FSRadioNext{
[XML]$Next = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.control?pin=$RadioPIN&sid=$SessionID&value=3"
if($Next.fsapiResponse.status -eq "FS_OK"){Write-Host "Next Successful On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Next Unsuccessful On $FriendlyName Radio" -ForegroundColor Red}
}

#Previous
Function Set-FSRadioPrevious{
[XML]$Previous = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.control?pin=$RadioPIN&sid=$SessionID&value=4"
if($Previous.fsapiResponse.status -eq "FS_OK"){Write-Host "Previous Successful On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Previous Unsuccessful On $FriendlyName Radio" -ForegroundColor Red}
}

#SetMode
Function Set-FSRadioMode{
$ModeNo = Read-Host "Please Enter The Number Of The Mode You Wish To Select 0 = Internet Radio` 1 = Spotify`
3 = Music Player` 4 = DAB Radio` 5 = FM Radio` 6 = AUX In` "
[XML]$Mode = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.sys.mode?pin=$RadioPIN&sid=$SessionID&value=$ModeNo"
if($Mode.fsapiResponse.status -eq "FS_OK"){Write-Host "Mode $ModeNo Successfully Selected On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Mode $ModeNo Was Unable To Be Selected On $FriendlyName Radio" -ForegroundColor Red}
}

#SetFrequency
Function Set-FSRadioFrequency{
$Frequency = Read-Host "Please enter the frequency eg.99400 = 96.40 MHz"
[XML]$Previous = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.frequency?pin=$RadioPIN&sid=$SessionID&value=$Frequency"
if($Previous.fsapiResponse.status -eq "FS_OK"){Write-Host "Frequency Successfully Set On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Frequency Was Unable To Be Set On $FriendlyName Radio" -ForegroundColor Red}
}

#SetPreset
Function Set-FSRadioPreset{
$PresetNo = Read-Host "Please Enter The Number In Which To Store The Preset 0-9"
[XML]$Preset = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.addPreset?pin=$RadioPIN&sid=$SessionID&value=$PresetNo"
if($Preset.fsapiResponse.status -eq "FS_OK"){Write-Host "Preset Set Successfully On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Preset Was Unable To Be Set On $FriendlyName Radio" -ForegroundColor Red}
}

#SetRepeatOn
Function Set-FSRadioRepeatOn{
[XML]$RepeatOn = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.repeat?pin=$RadioPIN&sid=$SessionID&value=1"
if($RepeatOn.fsapiResponse.status -eq "FS_OK"){Write-Host "Repeat Enabled On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Could Not Enable Repeat On $FriendlyName Radio" -ForegroundColor Red}
}

#SetRepeatOff
Function Set-FSRadioRepeatOff{
[XML]$RepeatOff = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.repeat?pin=$RadioPIN&sid=$SessionID&value=0"
if($RepeatOff.fsapiResponse.status -eq "FS_OK"){Write-Host "Repeat Disabled On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Could Not Disable Repeat On $FriendlyName Radio" -ForegroundColor Red}
}

#SetShuffleOn
Function Set-FSRadioShuffleOn{
[XML]$ShuffleOn = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.shuffle?pin=$RadioPIN&sid=$SessionID&value=1"
if($ShuffleOn.fsapiResponse.status -eq "FS_OK"){Write-Host "Shuffle Enabled On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Could Not Enable Shuffle On $FriendlyName Radio" -ForegroundColor Red}
}

#SetShuffleOff
Function Set-FSRadioShuffleOff{
[XML]$ShuffleOff = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/SET/netRemote.play.shuffle?pin=$RadioPIN&sid=$SessionID&value=0"
if($ShuffleOff.fsapiResponse.status -eq "FS_OK"){Write-Host "Shuffle Disabled On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Could Not Disable Repeat On $FriendlyName Radio" -ForegroundColor Red}
}

#####GET######

#GetPowerStatus
Function Get-FSRadioPowerStatus{
[XML]$PowerStatus = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.sys.power?pin=$RadioPIN&sid=$SessionID"
if($PowerStatus.fsapiResponse.value.u8 -eq "1"){Write-Host "$FriendlyName Radio Is Currently On" -ForegroundColor Magenta}
elseif($PowerStatus.fsapiResponse.value.u8 -eq "0"){Write-Host "$FriendlyName Radio Is Currently Off" -ForegroundColor Magenta}
else{Write-Host "Failed To Get $FriendlyName Radio Power Status" -ForegroundColor Red}
}

#GetPlayStatus
Function Get-FSRadioPlayStatus{
[XML]$PlayStatus = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.play.status?pin=$RadioPIN&sid=$SessionID"
if($PlayStatus.fsapiResponse.Status -eq "FS_OK"){
[int]$PlayStatus = $PlayStatus.fsapiResponse.value.u8
Switch ($PlayStatus) {
        0 {$PlayStatusResult = 'Stopped'}
        1 {$PlayStatusResult = 'Unknown'}
        2 {$PlayStatusResult = 'Playing'}
        3 {$PlayStatusResult = 'Paused'}
}
Write-Host "$FriendlyName Radio Is $PlayStatusResult" -ForegroundColor Magenta}
else{Write-Host "Failed To Get $FriendlyName Radio Play Status" -ForegroundColor Red}
}

#GetVolumeLevel
Function Get-FSRadioVolume{
[XML]$Volume = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.sys.audio.volume?pin=$RadioPIN&sid=$SessionID"
if($Volume.fsapiResponse.status -eq "FS_OK"){
$VolumeLevel = $Volume.fsapiresponse.value.u8
Write-Host "Volume Set To $VolumeLevel On $FriendlyName Radio" -ForegroundColor Magenta}
else{Write-Host "Failed To Get Volume From $FriendlyName Radio" -ForegroundColor Red}
}

#GetNowPlaying
Function Get-FSRadioNowPlaying{
    [XML]$Name = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.play.info.name?pin=$RadioPIN&sid=$SessionID"
    [XML]$Text = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.play.info.text?pin=$RadioPIN&sid=$SessionID"
    [XML]$Artist = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.play.info.artist?pin=$RadioPIN&sid=$SessionID"
    [XML]$Album = Invoke-WebRequest -Uri "http://$RadioIP/fsapi/GET/netRemote.play.info.album?pin=$RadioPIN&sid=$SessionID"
if($Name.fsapiResponse.status -eq "FS_OK"){
$NPName = $name.fsapiresponse.value.c8_array
$NPText = $Text.fsapiresponse.value.c8_array
$NPArtist = $Artist.fsapiresponse.value.c8_array
$NPAlbum = $Album.fsapiresponse.value.c8_array
Write-Host "Now Playing On $FriendlyName Radio...`n
    $NPname `n
    $NPText `n
    $NPArtist `n
    $NPAlbum `n
" -ForegroundColor Magenta}
else{Write-Host "Failed To Get Now Playing Information From $FriendlyName Radio" -ForegroundColor Red}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.