// This sketch is based on many examples, but is used to access the string from a RANE Halogen system and then feed particular outputs to RS232 commands to other components #include #include #include // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0x00, 0xDE, 0xAD, 0x12, 0x34, 0x56 }; IPAddress ip(172, 16, 50, 244); // Enter the IP address of the server you're connecting to: IPAddress server(172, 16, 50, 254); //IPAddress server(192, 168, 2, 174); test environment IPAddress HDMIMatrix(172, 16, 50, 249); //IPAddress HDMIMatrix(192, 168, 2, 185); test environment // Initialize the Ethernet client library with the IP address from above // since we are connecting to RANE Halogen, the port for that is 4996: EthernetClient client1; EthernetClient client2; // Store string and then process when completed String StringReceived = ""; char character; int HALloop = 1; String HALType = ""; String HALControl = ""; String HALValue = ""; void setup() { // You can use Ethernet.init(pin) to configure the CS pin //Ethernet.init(10); // Most Arduino shields //Ethernet.init(5); // MKR ETH shield //Ethernet.init(0); // Teensy 2.0 //Ethernet.init(20); // Teensy++ 2.0 //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet // Open serial communications and wait for port to open: Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // start the Ethernet connection: Serial.println("Attempting to obtain IP from DHCP, stand by..."); Ethernet.begin(mac); delay(3500); if (Ethernet.begin(mac) == 0) { // Failed to configure ethernet using DHCP, reverting to static IP Serial.println("Failed to obtain DHCP address, reverting to "); Serial.println(ip); Ethernet.begin(mac, ip); } else { // Obtained DHCP address Serial.println("Received IP: "); Serial.println(Ethernet.localIP()); } // Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } while (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); delay(500); } // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting to Halogen Server..."); RestartHalogen: // if you get a connection to the server, report back via serial: if (client1.connect(server, 4996)) { Serial.println("connected to Halogen Server."); } else { // if you didn't get a connection to the server: Serial.println("connection failed to Halogen Server"); delay(500); goto RestartHalogen; } // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting to HDMI Matrix..."); RestartHDMIMatrix: //if you get a connection to the server, report back via serial: if (client2.connect(HDMIMatrix, 4001)) { Serial.println("connected to HDMI Matrix."); } else { // if you didn't get a connection to the HDMI Matrix: Serial.println("connection failed to HDMI Matrix"); delay(500); goto RestartHDMIMatrix; } } void loop() { // if there are incoming bytes available // from the server, read them and print them: if (client1.available()) { char b = client1.read(); //Serial.print(b); if (b=='<') { // Start of new command from HAL, dump old string contents StringReceived = ""; HALType = ""; HALControl = ""; HALValue = ""; } if (b!='<' and b!='>') { // contents of HAL command stored if (b=='&' and HALloop==1) { HALType = StringReceived; HALloop = 2; StringReceived = ""; } if (b=='&' and HALloop==2) { HALControl = StringReceived; StringReceived = ""; } else { StringReceived.concat(b); } } if (b=='>') { HALValue = StringReceived; HALloop = 1; // End of HAL command reached, now time to process it switch (HALControl.toInt()) { case 62: // Window TV - Xfinity 1 Video selection client2.write("OUT01:01."); break; case 67: // Window TV - Xfinity 2 Video selection client2.write("OUT02:01."); break; case 68: // Window TV - Fire Stick Video selection client2.write("OUT03:01."); break; case 69: // Window TV - Chromecast Video selection client2.write("OUT04:01."); break; case 70: // Window TV - HDMI Desk Video selection client2.write("OUT05:01."); break; case 71: // Window TV - HDMI Counter Video selection client2.write("OUT06:01."); break; case 72: // Snack TV - Xfinity 1 Video selection client2.write("OUT01:02."); break; case 73: // Snack TV - Xfinity 2 Video selection client2.write("OUT02:02."); break; case 74: // Snack TV - Fire Stick Video selection client2.write("OUT03:02."); break; case 75: // Snack TV - Chromecast Video selection client2.write("OUT04:02."); break; case 76: // Snack TV - HDMI Desk Video selection client2.write("OUT05:02."); break; case 77: // Snack TV - HDMI Counter Video selection client2.write("OUT06:02."); break; case 78: // Projector - Xfinity 1 Video selection client2.write("OUT01:03."); break; case 79: // Projector - Xfinity 2 Video selection client2.write("OUT02:03."); break; case 80: // Projector - Fire Stick Video selection client2.write("OUT03:03."); break; case 81: // Projector - Chromecast Video selection client2.write("OUT04:03."); break; case 82: // Projector - HDMI Desk Video selection client2.write("OUT05:03."); break; case 83: // Projector - HDMI Counter Video selection client2.write("OUT06:03."); break; case 84: // Bar TV - Xfinity 1 Video selection client2.write("OUT01:04."); break; case 85: // Bar TV - Xfinity 2 Video selection client2.write("OUT02:04."); break; case 86: // Bar TV - Fire Stick Video selection client2.write("OUT03:04."); break; case 87: // Bar TV - Chromecast Video selection client2.write("OUT04:04."); break; case 88: // Bar TV - HDMI Desk Video selection client2.write("OUT05:04."); break; case 89: // Bar TV - HDMI Counter Video selection client2.write("OUT06:04."); break; case 90: // Window TV - Power On client2.write("CECO014004."); break; case 91: // Window TV - Power Off client2.write("CECO014036."); break; case 92: // Snack TV - Power On client2.write("CECO024004."); break; case 93: // Snack TV - Power Off client2.write("CECO024036."); break; case 94: // Projector - Power On client2.write("CECO034004."); break; case 95: // Projector - Power Off client2.write("CECO034036."); break; case 96: // Bar TV - Power On client2.write("CECO044004."); break; case 97: // Bar TV - Power Off client2.write("CECO044036."); break; case 98: // Omniarena TVs - Power On //SendCommand = "powering"; //SendTarget = "Omniarena TVs"; //SendValue = "on"; break; case 99: // Omniarena TVs - Power Off //SendCommand = "powering"; //SendTarget = "Omniarena TVs"; //SendValue = "off"; break; case 100: // Window TV - Volume Up client2.write("CECO01404441."); break; case 101: // Window TV - Volume Down client2.write("CECO01404442."); break; case 102: // Window TV - Volume Mute client2.write("CECO01404443."); break; case 103: // Snack TV - Volume Down client2.write("CECO02404442."); break; case 104: // Snack TV - Volume Up client2.write("CECO02404441."); break; case 105: // Window TV - Volume Mute client2.write("CECO02404443."); break; case 106: // Projector - Volume Up client2.write("CECO03404441."); break; case 107: // Projector - Volume Down client2.write("CECO03404442."); break; case 108: // Projector - Volume Mute client2.write("CECO03404443."); break; case 109: // Bar TV - Volume Up client2.write("CECO04404441."); break; case 110: // Bar TV - Volume Down client2.write("CECO04404442."); break; case 111: // Bar TV - Volume Mute client2.write("CECO04404443."); break; case 112: // HDMI Matrix, power on //client2.write("PowerON."); break; case 113: // HDMI Matrix, power off //client2.write("PowerOFF."); break; //default: // default case is to do nothing. } //Send commands if (HALType=="C" and HALValue=="0") { // Do Nothing, commmand buttons trigger twice. } else if (HALType=="C" and HALValue=="1"){ // Sending command button commands } else { // Noting all other type of commands Serial.println("HALType: " + HALType + " | HALControl: " + HALControl + " | HALValue: " + HALValue); } // End of processing } } // as long as there are bytes in the serial queue, // read them and send them out the socket if it's open: while (Serial.available() > 0) { char inChar = Serial.read(); if (client1.connected()) { client1.print(inChar); client1.print("received"); } } // if the server's disconnected, stop the client: if (!client1.connected()) { Serial.println(); Serial.println("disconnecting."); client1.stop(); // do nothing: while (true) { delay(1); } } }