Portsdown 4 Receive Command Line?

Discussion about this major DATV Project. See https://wiki.batc.org.uk/The_Portsdown_Transmitter
G4UFS
Posts: 10
Joined: Sun Oct 04, 2020 9:40 am

Re: Portsdown 4 Receive Command Line?

Post by G4UFS » Sun Dec 20, 2020 9:23 pm

G4UFS wrote:
Sun Dec 20, 2020 3:54 pm
For anyone interested, I managed to get a later version of the script working by selecting "Button 1" from the "More functions" button in Menu "M2" on the Portsdown 4. The following instructions should work with version 20.12.18 of the UDPControl script, attached. N.B. You will need the two scripts from Dave - G8GKQ ("lmstop.sh" and "lmvlcff2.sh") in the beginning of this thread.

UDPControl.py installation instructions -

1) Copy the following scripts to the /home/pi/rpidatv/scripts folder
lmvlcff2.sh
lmstop.sh
UDPControl.py

2) Make sure that all the above scripts are executable
sudo chmod +x lmvlcff2.sh
sudo chmod +x lmstop.sh
sudo chmod +x UDPControl.py

3) Edit user_button1.sh (or whatever user button you prefer) and make look like this :-

#! /bin/bash
/home/pi/rpidatv/scripts/UDPControl.py

4) Reboot the Portsdown

5) If not done so already, download an install Quick Tune on Windows PC

6) Go to setting and type the IP address of your Portsdown in the "IP Address" field
Make "Port" number = 5115
Click "Add New Receiver"

UDPControl usage -
To activate Quick Tune on the Portsdown, goto Menu M2 > More functions > Button 1 (or which ever you edited above)
Now, when clicking signals on Quick tune, the Portsdown should switch to them.

To exit quick tune on the Portsdown, click the beacon signal three times (leave a second or so between clicks).
N.B to enable it again, follow the steps above to activate it.

Sometimes the Portsdown doesn't tune first time. If no signal is received within 10 seconds or so, try clicking the signal again in Quick Tune. N.B, if the beacon is clicked 3 times, the script will exit and you will need to activate it again.


TODO :
Work out a way of exiting the script from the Portsdown screen instead of clicking the beacon three times
Work out a way to add the information overlay, currently the overlay will not display

One final note. This works for "me". Please make sure you take a backup of your system before doing anything. The usual disclaimers apply - that I wont be responsible for anything etc...

Merry Christmas All !! :)

UDPControl.py 20.12.18

Code: Select all

#!/usr/bin/python


# Python script that sets up a UDP server on post 5115 and listens for commands from "QO100 Live Tune" by Rob M0DTS
#     See https://wiki.batc.org.uk/QO100_Live_Tune
# QuickTune was designed to allow quick tuning of the Windows MiniTiouner application to QO100 signals as they appeared
# on the Wideband Spectrum Monitor. "UDPControl" allows QO100 Live Tune to be used with the Portsdown Longmynd in the same
# manner
# 73 De Dave - G4UFS


# Version History
# 2020.12.17 - Initial release
# 2020.12.18 -
# Fixed releasing of UDP port when script exited
# Changed to absolute names for supporting script so that UDPControl script can be called from anywhere
#       (N.B. Supporting scrips must be in /home/pi/rpidatv/scripts)
# Modified to exit script when beacon clicked three times
# This script can be called from "Button 1" on "More Functions" menu so that is can be started from the Portsdown menu system


import socket
import os
import sys
import time

# Used to track if this is the first startup of the tuning script. See showTS() for furter details of use
state = 0
# Number of times to click on the beacon before returning to menu
stop_count = 3
stop_counter = stop_count

# Function to get the ip address of the Portsdown
def getIPadd():
    soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        soc.connect(('10.255.255.255', 1))
        IPadd = soc.getsockname()[0]
    except Exception:
        IPadd = '127.0.0.1'
    finally:
        soc.close()
    return IPadd



def showTS(Freq,SR):
    global state
    # Stop any receiving that may already be going on
    os.system("/home/pi/rpidatv/scripts/lmstop.sh")
    # Setup to receive the new frequency, SR stream
    os.system("/home/pi/rpidatv/scripts/lmvlcff2.sh " + Freq + " " + SR + " > null")
    if stop_count != 0:
      # Stream crashes if this is the first time starting it so "state" variable implemented to track the first time and start the stream again
      if state == 0:
        time.sleep(3)
        state = 1
        os.system("/home/pi/rpidatv/scripts/lmstop.sh")
        os.system("/home/pi/rpidatv/scripts/lmvlcff2.sh " + FreqNumber + " " + SRNumber + " > null")



###################  Main Code ################################################################################


# Get IP address so that we can bind UDP server to it

# Has IP been passed on the command line? if so, use it. If not, try and get one from the OS
if len(sys.argv) == 2:
     print str(sys.argv[1])
     localIP = str(sys.argv[1])
else:
     localIP = getIPadd()

# Change the below if the detected IP address is different to the one to be used
# e.g. If using both wired and Wireless networks, the UDP server will need to bind to one
# or the other network interfaces' IP's. The desired card may not be the one detected by the
# getIPadd function
#localIP = "nnn.nnn.nnn.nnn"

print localIP

# Setup a UDP Server on the below port number
localPort   = 5115
bufferSize  = 1024
UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
UDPServerSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
UDPServerSocket.bind((localIP, localPort))
print("Listening for messages")



#################### Main Loop ################################################################################
# Listen for incoming UDP messages
while(True):
    bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
    message = bytesAddressPair[0]
    address = bytesAddressPair[1]
    #print message
    #print address

    # Split the frequency and SR data
    # In the current version of Quick Tune, split [1] = Frequency data and split[4] = SR
    splitMsg = message.split(",")
    #print splitMsg

    # Parse splitMsg[1] for the frequency
    StartFreqNumber = splitMsg[1].find("=")+1
    FreqNumber = splitMsg[1][StartFreqNumber:]
    print FreqNumber

    # Parse SplitMsg[4] for the Symbol Rate
    StartSRNumber = splitMsg[4].find("=")+1
    SRNumber = splitMsg[4][StartSRNumber:]
    print SRNumber



    # Not very elegant but check to see if the beacon has been clicked three times in a row and go back to menu if so
    if int(FreqNumber) < 10492000:
      stop_counter = stop_counter - 1
    else:
      stop_counter = stop_count


    if stop_counter == 0:
      os.system("/home/pi/rpidatv/scripts/lmstop.sh")
      #time.sleep(1)
      os.system("/home/pi/rpidatv/scripts/utils/guir.sh &")
      stop_counter = stop_count
      state = 0
      soc.shutdown(socket.SHUT_RDWR)
      soc.close()
      sys.exit()
    else:
      # Start playing the stream
      showTS(FreqNumber,SRNumber)



Jabi
Posts: 66
Joined: Sun Jun 14, 2020 3:23 pm

Re: Portsdown 4 Receive Command Line?

Post by Jabi » Mon Dec 28, 2020 4:25 pm

Hello:
Good Xtmas for all. I have one qestion: How execute instructions on SSH mode? My Raspi4 with Portsdown 4 dit:
"Network error: Connection refused"
Is imossible connect on SSH mode ...
73,s de Jabi, ea2aru.

G8GKQ
Site Admin
Posts: 2928
Joined: Sun Mar 22, 2009 1:21 pm

Re: Portsdown 4 Receive Command Line?

Post by G8GKQ » Mon Dec 28, 2020 4:38 pm

Jabi

Did you use ssh when you built the card? If you used the exact instructions on GitHub, it should work.

Go to the info screen on Menu 2. Does it show an IP address?

Dave

Jabi
Posts: 66
Joined: Sun Jun 14, 2020 3:23 pm

Re: Portsdown 4 Receive Command Line?

Post by Jabi » Mon Dec 28, 2020 5:11 pm

Dave:
I'm trying to run SSH with Porstdown 4 running already. Or do I have to put the new instructions in before installing Portsdown 4 on the SD?
73, s from Jabi, ea2aru.

Jabi
Posts: 66
Joined: Sun Jun 14, 2020 3:23 pm

Re: Portsdown 4 Receive Command Line?

Post by Jabi » Mon Dec 28, 2020 5:13 pm

I'm trying to run SSH with Porstdown 4 already running. Or do I have to put the new instructions before installing Portsdown 4 on the SD, when building the SD?
73, s from Jabi, ea2aru.

G8GKQ
Site Admin
Posts: 2928
Joined: Sun Mar 22, 2009 1:21 pm

Re: Portsdown 4 Receive Command Line?

Post by G8GKQ » Mon Dec 28, 2020 5:20 pm

Jabi

I'm not quite sure what you have done, as you need to use ssh to build a Portsdown properly. You do not need to rebuild the card.

To enable ssh on a Raspberry Pi, you will need put a file called ssh in the /boot folder (if you are using Linux) or in the boot volume (if you take the card out of the Portsdown and put it in a Windows computer). Then next time you boot up ssh should be enabled.

These instructions might help you - they expain how to enable ssh by putting an ssh file on the card: https://github.com/BritishAmateurTelevi ... -4-version

Dave

Jabi
Posts: 66
Joined: Sun Jun 14, 2020 3:23 pm

Re: Portsdown 4 Receive Command Line?

Post by Jabi » Mon Dec 28, 2020 5:54 pm

Ok. Many tnx for all and Merry Xtmas for you and yours de Jabi, ea2aru.

Post Reply

Return to “The Portsdown Digital ATV System”