GNU Radio to Web client

As part of the “Remote SDR” project, it is necessary to extract the audio channel data created by GNU Radio from the “Remote SSB receiver” and send it to a Web client.

Among the processing blocks present in GNURADIO-companion, there is the UDP sink block for outputting the data. To enter an audio data stream into a web page, you can use websockets. The program proposed below in python 3, retrieves the audio stream received from GNU radio according to the UDP protocol (port 9001) and passes this data to the web client according to the websocket protocol (port 8001). We exchange 1024 byte packets. You should not make them too important so as not to delay the audio signal. Here the audio is coded on 2 bytes. We thus send 512 samples, knowing that we are sampled at 10kHz, that makes about 50ms of signal.

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

#Collect of Audio data from GNU Radio and send to web client
#Recuperation des données audio  de GNU_Radio et envoi vers le client web
import socket
import asyncio
import websockets

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

# get local machine name
host = 'localhost'                           
port_audio_Web = 8001
port_audio_GR = 9001

# connection to hostname on the port.
s_audio.bind((host, port_audio_GR))                           
print ("Passerelle audio Web")

# Receive no more than 1024 bytes audio
async def audio(websocket_a, path):
    while True:
# on recupere les data de GNU-RADIO
        msg_audio = s_audio.recv(1024)
#       print ("audio",len(msg_audio))
# on envoi le message vers le client web distant
        await websocket_a.send(msg_audio)
	


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

asyncio.get_event_loop().run_until_complete(start_server_audio)

asyncio.get_event_loop().run_forever()

For sending the spectrum to create a waterfall on the web page, we use another program very similar to that of audio. Knowing that a spectrum is described at the output of FFT by 1024 points each represented by 2 bytes, we will send packets of 2048 bytes.

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

#Collect spectral data to be passed to a web client
#Recuperation des données  spectre de GNU_Radio et envoi vers le client web
import socket
import asyncio
import websockets

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

# get local machine name
host = 'localhost'                           

port_spectre_Web = 8002
port_spectre_GR = 9002

# connection to hostname on the port.
s_spectre.bind((host, port_spectre_GR))                               
print("Passerelle Spectre vers client WEB")

# Reception 2048 bytes du spectre 
async def spectre(websocket_s, path):
    while True:
# on recupere les data de GNU-RADIO
        msg_spectre = s_spectre.recv(2048)
#       print ("spectre",len(msg_spectre))
        
# on envoi le message vers le client web distant
        await websocket_s.send(msg_spectre)
	

start_server_spectre = websockets.serve(spectre, "", port_spectre_Web)

asyncio.get_event_loop().run_until_complete(start_server_spectre)

asyncio.get_event_loop().run_forever()

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

Posts on Remote-SDR

F1ATB André

Ham Radio - Home automation - Photovoltaic

You may also like...

Leave a Reply

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