Project showcase
Broadcast Radio/TV Connection Monitor

Broadcast Radio/TV Connection Monitor © GPL3+

A system to check if a remote broadcast system has connection with the studio (and shows us when we are on air).

  • 1,108 views
  • 0 comments
  • 1 respect

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
3drag
3D Printer (generic)

Apps and online services

About this project

A local radio station asked me to create a device, to monitor a IP-stream connection from a remote broadcast system to the studio.

The device has screw terminals for three leds. Those led's indicates several state's:

  • No connection with the studio.
  • Connection with the studio.
  • Connection with the studio and we are live on air!

The core consists of an Arduino nano. The arduino sends a serial string to the streaming device, every 10 seconds. Depending on the kinds of feedback string returned by the studio, we can monitor the connection.

Code

StreamConnectionStateMonitorArduino
Main code
/*
Code by WT040

History:
v1.0.0  11.02.2017 release version
*/

//Constants
#define LED_NOT_CONNECTED 2
#define LED_CONNECTED 3
#define LED_ON_AIR 4
#define POLLING_INTERVAL 10000  //10 seconds
#define CONNECTION_STATE_UNKNOWN  0
#define CONNECTION_STATE_NOT_CONNECTED  1
#define CONNECTION_STATE_CONNECTED  2
#define CONNECTION_STATE_ON_AIR 3
//

//Variables
unsigned long previousMillisPolling = 0;
bool waitingForRx = false;
int streamState = CONNECTION_STATE_UNKNOWN;

String inputString = "";
bool stringComplete = false;
//

void setup()
{
	// start serial port to show results
	Serial.begin(9600);
	inputString.reserve(200);
	//display_Running_Sketch();
	printProgramName();
	//init led pins
	pinMode(LED_NOT_CONNECTED, OUTPUT);
	pinMode(LED_CONNECTED, OUTPUT);
	pinMode(LED_ON_AIR, OUTPUT);
	digitalWrite(LED_NOT_CONNECTED, LOW);
	digitalWrite(LED_CONNECTED, LOW);
	digitalWrite(LED_ON_AIR, LOW);
	Serial.println("System initialized");
}

void loop()
{
	checkStreamState();
}

void checkStreamState() {
	unsigned long currentMillisPolling = millis();
	unsigned long currentMillisConnectionTimeout = millis();
	checkRx();
	if (previousMillisPolling == 0) {
		previousMillisPolling = currentMillisPolling;
		Serial.println("get connection state");
		waitingForRx = true;
	}

	if (currentMillisPolling - previousMillisPolling >= POLLING_INTERVAL) {
		if (waitingForRx) {
			setStreamState(CONNECTION_STATE_NOT_CONNECTED);
		}
		Serial.println("get connection state");
		previousMillisPolling = millis();
		waitingForRx = true;
	}
}


void checkRx() {
	while (Serial.available()) {
		// get the new byte:
		char inChar = (char)Serial.read();
		// add it to the inputString:
		inputString += inChar;
		// if the incoming character is a newline, set a flag
		// so the main loop can do something about it:
		if (inChar == '\r') {
			stringComplete = true;
			if (inputString == "fader not open\r") {
				setStreamState(CONNECTION_STATE_CONNECTED);
				waitingForRx = false;
			}
			else if (inputString == "fader open\r") {
				setStreamState(CONNECTION_STATE_ON_AIR);
				waitingForRx = false;
			}
			inputString = "";
		}
	}
}


void setStreamState(int state) {
	if (state == CONNECTION_STATE_UNKNOWN) {
		digitalWrite(LED_NOT_CONNECTED, LOW);
		digitalWrite(LED_CONNECTED, LOW);
		digitalWrite(LED_ON_AIR, LOW);
		streamState = state;
	}

	else if (state == CONNECTION_STATE_NOT_CONNECTED) {
		digitalWrite(LED_NOT_CONNECTED, HIGH);
		digitalWrite(LED_CONNECTED, LOW);
		digitalWrite(LED_ON_AIR, LOW);
		streamState = state;
	}

	else if (state == CONNECTION_STATE_CONNECTED) {
		digitalWrite(LED_NOT_CONNECTED, LOW);
		digitalWrite(LED_CONNECTED, HIGH);
		digitalWrite(LED_ON_AIR, LOW);
		streamState = state;
		waitingForRx = false;
	}

	else if (state == CONNECTION_STATE_ON_AIR) {
		digitalWrite(LED_NOT_CONNECTED, LOW);
		digitalWrite(LED_CONNECTED, LOW);
		digitalWrite(LED_ON_AIR, HIGH);
		streamState = state;
		waitingForRx = false;
	}
}

void printProgramName() {
	String path = __FILE__;
	int slash = path.lastIndexOf('\\');
	String programName = path.substring(slash + 1);
	int dot = programName.lastIndexOf('.');
	programName = programName.substring(0, dot);

	Serial.print("\nProgram version: ");
	Serial.println(programName);
}

Custom parts and enclosures

Case bottom
Case bottom
Case top
Case top
Case sub-d 9 mount
Case sub-d 9 mount

Schematics

basic schematic, without rs232 module
basic schematic, without rs232 module
Streamconnectionstatemonitor v1 schema uv0nwhph5j

Comments

Similar projects you might like

Marduino Party 1

Project tutorial by Arduino “having11” Guy

  • 1,127 views
  • 0 comments
  • 0 respects

DIY Portable Distance Detection Device

Project tutorial by Viktor S

  • 5,901 views
  • 5 comments
  • 16 respects

Multi Temperature Sensor

Project tutorial by Jochem Witteman

  • 3,980 views
  • 3 comments
  • 12 respects

3D Printer Filament Monitor for Arduino

Project showcase by Enrico Miglino

  • 2,429 views
  • 3 comments
  • 14 respects

Grill & Deck-Door Monitor

Project in progress by Tom Lewis

  • 915 views
  • 0 comments
  • 1 respect
Add projectSign up / Login