Web Client to GNU Radio

As part of the “Remote SDR” project, it is necessary to send an audio stream and parameters from a web page to the remote SSB transmitter coded in GNU Radio.

Among the processing blocks present in GNURADIO-companion, there is the source UDP block for entering an audio data stream. To send this stream from a web client, you can use websockets. The program proposed below in python 3, retrieves the audio stream received from the web client according to the websocket protocol (port 8005) and passes this data to GNU Radio according to the UDP protocol (port 9005).

In addition this program each time an audio frame is received (packet of 512 bytes), changes the pin 26 of the GPIO of the Orange PI One Plus. This generates an alternating signal which, once rectified, will energize relays to power the transmitter. See details here.

#!/usr/bin/python3           # This is client.py file

import socket
import asyncio
import websockets
import os                       # To execute system command

# create a socket object
s_audio = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 

# get local machine name
host = ''                           

port_audio_Web = 8005
port_audio_GR = 9005

numgpio=227								 # GPIO 227 corresponds to pin 26 in Orange PI One PLUS H6

# Préparation port commande relais
os.system("sudo echo "+numgpio+" > /sys/class/gpio/export")              #activation
os.system("sudo echo out > /sys/class/gpio/gpio"+numgpio+"/direction")   # Output

# connection to hostname on the port.

print ("Passerelle audio client Web vers TX")

# Receive   bytes audio
async def audio(websocket_a, path):
    while True:
# on recupere les data du micro du client

        donnee_audio = await websocket_a.recv()

        # Oscillateur pour activer le relais alimentation via un condensateur et un redressement
		# Oscillator on pin 26 as watchdog
        etat=not etat     #inversion à chaque trame recue
        if etat:
             os.system("echo 1 > /sys/class/gpio/gpio"+numgpio+"/value")
             os.system("echo 0 > /sys/class/gpio/gpio"+numgpio+"/value")

start_server_audio = websockets.serve(audio, "", port_audio_Web)



For sending transmitter configuration commands, we use the xmlrpc protocol on the GNU Radio side (port 9004) and always websockets on the web client side (port 8004).

#!/usr/bin/python3           # 

import asyncio
import websockets
import json
import xmlrpc.client

# create a socket object

# get local machine name
host = 'localhost'                           

port_para_Web = 8004
adr_local = "http://localhost:9004"

Sxml = xmlrpc.client.ServerProxy(adr_local)

print("Passerelle Parametres TX du client WEB")

async def consumer_handler(websocket_p, path):
    async for message_recu in websocket_p:
        if "Fr_TX" in F :
              print("Fr_TX ",F["Fr_TX"])

        if "GRF_TX" in F :
              print("GainRF TX ",F["GRF_TX"])
        if "GIF_TX" in F :
              print("GainIF TX ",F["GIF_TX"])

        if "GBB_TX" in F :
              print("GainBB TX ",F["GBB_TX"])
        if "LSB_USB" in F :
              print("LSB USB ",F["LSB_USB"])
        await websocket_p.send("OK")			  

start_server_para = websockets.serve(consumer_handler, "", port_para_Web)

loop = asyncio.get_event_loop()

except KeyboardInterrupt:
    logging.info("Process Para interrupted")
    logging.info("Arret Para service.")

For the receiver described here, we use the same protocols to pass the configuration parameters.

The source files are available on Github F1ATB / Remote-SDR.

Posts on Remote-SDR

Leave a Reply

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