Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Server ‐ Setup

dharm pimsen edited this page Mar 3, 2024 · 2 revisions

Server Setup Guide

This guide will walk you through setting up the server.

Installation

  1. Clone the project using the following command:

    git clone https://github.com/damp11113/IDRB.git
    
  2. Navigate to the IDRB/Server directory.

Python Package Setup

Ensure you have the following Python packages installed:

  • damp11113
  • pyzmq
  • requests
  • pycrypto (for encryption channel)
  • pyogg (for Opus codec)

You can install pyogg from https://github.com/damp11113/PyOgg.

Server Configuration

Settings.py

The Settings.py file contains configurations for the server.

# Server Settings
protocol = "TCP"
server_port = ('0.0.0.0', 6980)
compression_level = 9  # 0-9
buffersize = 32

# Server Info
ServerName = "Your Server Name"
ServerDesc = "The Best Server"
Country = "US"

# ThaiSDR Directory (for listing this server)
public = True
ServerIP = "IDRB.example.com"
ServerPort = server_port[1]
ThaiSDRkey = ""
Server Settings
  • protocol: Supported protocols are TCP, ZeroMQ, and ZeroMQ (WebSocket).
  • server_port: Set the IP host like ('0.0.0.0', 6980). Use * instead of 0.0.0.0 if using ZeroMQ.
  • compression_level: Set the compression level for Zlib (0-9).
  • buffersize: Set the buffer size for sending. Lower buffer size equals lower delay.
Server Info

Configure to display server information to clients and directories.

  • ServerName: Your server's name.
  • ServerDesc: Description of your server.
  • Country: Location of the server.
ThaiSDR Directory Settings

Follow these steps if you want your server to be listed publicly on ThaiSDR Directory:

  1. Go to dashboard.damp11113.xyz and log in or sign up for an account.
  2. Click on API Key.
  3. Create a new API key, selecting "ThaiSDR Directory" as the API type.
  4. Copy the API key.
  • public: Specify if the server should be listed publicly.
  • ServerIP: Your server's IP or URL (without protocol).
  • ServerPort: Configure the port (e.g., 80 if using Cloudflare Tunnel).
  • ThaiSDRkey: Your API key.

RDS.py

The RDS.py file contains RDS (Radio Data System) configurations.

RDS = {
    "PS": "DPRadio",
    "RT": "Testing internet radio",
    "PI": 0x27C8, # static
    "PTY": 0,
    "PTY+": "Testing",
    "Country": "TH",
    "Coverage": "All",
    "CT": {
        "Local": None,
        "UTC": None,
    },
    "PIN": 12345,
    "TMC": {
        "TP": False,
        "TA": False,
        "Messages": None
    },
    "ECC": None,
    "LIC": None,
    "AudioMode": "Stereo", # mono, stereo, surround 5.1/7.1, HRTF
    "ArtificialHead": False,
    "Compressed": False,
    "DyPTY": False,
    "EPG": None,
    "EON": [
        # can add more here
    ],
    "AS": [ # AS = Alternative Server
        # can add more server here
    ],
    "ContentInfo": {
        "Codec": "opus",
        "bitrate": 64000,
        "channel": 2,
        "samplerates": 48000
    },
    "images": {
        "logo": {
            "lazy": False,
            'contents': b'',
            "part": {
                "current": 0,
                "total": 0
            }
        }
    }
}

The lazy image is beta To use

sendimagelazy(encodelogoimage(r"image.jpeg", 25), 100, RDS, "logo")

Encoder.py

The Encoder.py file contains audio encoding configurations.

import pyaudio
import numpy as np

import RDS as _RDS

p = pyaudio.PyAudio()

streaminput = p.open(format=pyaudio.paInt16, channels=2, rate=48000, input=True)

channel1 = Queue()

def encode_audio():
    encoder = OpusBufferedEncoder()
    encoder.set_application("audio")
    encoder.set_sampling_frequency(_RDS.RDS["ContentInfo"]["samplerates"])
    encoder.set_channels(_RDS.RDS["ContentInfo"]["channel"])
    encoder.set_bitrates(_RDS.RDS["ContentInfo"]["bitrate"])
    encoder.set_frame_size(60)
    encoder.set_bitrate_mode("VBR")
    encoder.set_compresion_complex(10)

    while True:
        pcm = np.frombuffer(streaminput.read(1024, exception_on_overflow=False), dtype=np.int16)

        encoded_packets = encoder.buffered_encode(memoryview(bytearray(pcm)))
        for encoded_packet, _, _ in encoded_packets:
            # Put the encoded audio into the buffer

            channel1.put(encoded_packet.tobytes())

def StartEncoder():
    EncoderLog.info("Starting encoder")
    audio_thread = threading.Thread(target=encode_audio)

    audio_thread.start()

server.py

The server.py file handles the server's muxer configuration.

def Muxer():
    while True:
        # Get the encoded audio from the buffer
        ENchannel1 = Encoder.channel1.get()

        # encrypt data
        # ENC1encrypted, ENC1salt, ENC1iv = utils.encrypt_data(ENchannel1, "password") # if you want encryption

        # ENchannel1 = ENC1encrypted + b'|||||' + ENC1salt + b'|||||' + ENC1iv # to show client is this channel is encryption

        content = {
            "first": False,
            "mainchannel": 1, # set main channel on user connect to server
            "channel": {
                1: {
                    "Station": "Your Channel",
                    "StationDesc": "The best station in the world!",
                    "Encrypt": b'|||||' in ENchannel1,  # check if encrypt
                    "ContentSize": len(ENchannel1),
                    "Content": ENchannel1,
                    "RDS": _RDS.RDS
                }
                # you can add more station
            },
            "serverinfo": {
                "Listener": connected_users,
                "Startat": timestart,
                "RDS": _RDS.ServerRDS
            }
        }
        ThaiSDRDir.content = content # to upload to directory

        compressedcontent = zlib.compress(pickle.dumps(content), level=Settings.compression_level) # compress data

        Buffer.put(compressedcontent) # keep data to buffer