WT040
Published © GPL3+

Broadcast Radio/TV Connection Monitor

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

BeginnerShowcase (no instructions)2 hours2,152
Broadcast Radio/TV Connection Monitor

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
LED (generic)
LED (generic)
×3
PCB
×1
screw terminal 1.50mm, 6 way
×1
wire
×1
SparkFun RS232 Shifter - SMD
SparkFun RS232 Shifter - SMD
×1
Resistor 330 ohm
Resistor 330 ohm
×3
12v PSU
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

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

Code

StreamConnectionStateMonitor

Arduino
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);
}

Credits

WT040

WT040

2 projects • 11 followers

Comments