From 87338d4db1e88210e978ca07d0e5f5ee9a867ddc Mon Sep 17 00:00:00 2001 From: bsncubed Date: Sun, 30 Nov 2025 20:51:17 +1100 Subject: [PATCH] Created Arduino files for created a flashing light that also sends to RRCS --- arduino/RRCS.h | 39 +++++++ arduino/TrafficQLXArduino.ino | 210 ++++++++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+) create mode 100755 arduino/RRCS.h create mode 100755 arduino/TrafficQLXArduino.ino diff --git a/arduino/RRCS.h b/arduino/RRCS.h new file mode 100755 index 0000000..34bf9b8 --- /dev/null +++ b/arduino/RRCS.h @@ -0,0 +1,39 @@ +const char Data_PressVirtKey1OnBench_P[] PROGMEM = "\ +\ + PressKeyEx\ + \ + C0000000001\ + 64\ + 46\ + 0\ + 2\ + 0\ + 1\ + 1\ + 1\ + 1\ + \ +\ +"; + +const char Data_ReleaseVirtKey1OnBench_P[] PROGMEM = "\ +\ + PressKeyEx\ + \ + C0000000002\ + 64\ + 46\ + 0\ + 2\ + 0\ + 1\ + 1\ + 0\ + 1\ + \ +\ +"; + +__FlashStringHelper* Data_PressVirtKey1OnBench = (__FlashStringHelper*)Data_PressVirtKey1OnBench_P; +__FlashStringHelper* Data_ReleaseVirtKey1OnBench = (__FlashStringHelper*)Data_ReleaseVirtKey1OnBench_P; + diff --git a/arduino/TrafficQLXArduino.ino b/arduino/TrafficQLXArduino.ino new file mode 100755 index 0000000..75b695a --- /dev/null +++ b/arduino/TrafficQLXArduino.ino @@ -0,0 +1,210 @@ +/* + DHCP-based IP printer + + This sketch uses the DHCP extensions to the Ethernet library + to get an IP address via DHCP and print the address obtained. + using an Arduino WIZnet Ethernet shield. + + Circuit: + Ethernet shield attached to pins 10, 11, 12, 13 + + created 12 April 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include +#include "RRCS.h" + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; + +constexpr int PIN_BTN_MUTE = A2; +constexpr int PIN_LED_RED = A0; + +//const uint8_t RRCSServerIP[4] = {10,75,120,147}; // TRUNKNAV VM +//const uint8_t RRCSServerIP[4] = {192,168,192,247}; // Ben's laptop testing +const uint8_t RRCSServerIP[4] = {192,168,192,241}; // Ben's windows VM +const uint16_t RRCSServerPort = 8193; +const uint16_t BlinkMs = 1000; + +EthernetClient client; + +void ToggleVirtualKey() { + if (client.connect(RRCSServerIP, RRCSServerPort)) { + Serial.println("Connected."); + + client.println("POST / HTTP/1.1"); + client.print("Host: "); + client.print(RRCSServerIP[0]); client.print("."); + client.print(RRCSServerIP[1]); client.print("."); + client.print(RRCSServerIP[2]); client.print("."); + client.println(RRCSServerIP[3]); + client.println("Content-Type: text/xml"); // Or other content type like application/json + client.println("User-Agent: Ben's Silly Box"); + client.println("Connection: close"); + client.print("Content-Length: "); + client.println(strlen(Data_PressVirtKey1OnBench_P)); + client.println(); + client.println(Data_PressVirtKey1OnBench); + + client.println(); // End of request + + while(client.available()) { + Serial.write((char)client.read()); + } + delay(50); + client.stop(); + Serial.println(); + client.connect(RRCSServerIP, RRCSServerPort); + //delay(20); + + client.println("POST / HTTP/1.1"); + client.print("Host: "); + client.print(RRCSServerIP[0]); client.print("."); + client.print(RRCSServerIP[1]); client.print("."); + client.print(RRCSServerIP[2]); client.print("."); + client.println(RRCSServerIP[3]); + client.println("Content-Type: text/xml"); // Or other content type like application/json + client.println("User-Agent: Ben's Silly Box"); + client.println("Connection: close"); + client.print("Content-Length: "); + client.println(strlen(Data_ReleaseVirtKey1OnBench_P)); + client.println(); + client.println(Data_ReleaseVirtKey1OnBench); + + client.println(); // End of request + + while(client.available()) { + Serial.write((char)client.read()); + } + client.stop(); + Serial.println(); + + Serial.println("Sent."); + } else { + Serial.println("Couldn't reach RRCS Server!"); + } +} + + + + + +bool MuteState = false; +bool EthNoLink = true; + +void setup() { + + pinMode (PIN_BTN_MUTE, INPUT_PULLUP); + // Blink once on startup + pinMode(PIN_LED_RED, OUTPUT); + digitalWrite(PIN_LED_RED, HIGH); + delay(100); + digitalWrite(PIN_LED_RED, LOW); + + // 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(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + Serial.println("Failed Eth setup. Retrying later."); + } else { + EthNoLink = false; + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); +} + +void loop() { + digitalWrite(PIN_LED_RED, MuteState && ((millis() / BlinkMs) % 2)); + + + if (digitalRead(PIN_BTN_MUTE) == LOW) { + // Mute action. + MuteState = !MuteState; + + Serial.println(MuteState ? "Muted." : "Unmuted."); + + // Lazy debounce is best debounce + delay(50); + while (digitalRead(PIN_BTN_MUTE) == LOW) delay(100); + + ToggleVirtualKey(); + } + + if (EthNoLink) { + Serial.println("Retrying Eth Setup..."); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + Serial.println("Failed Eth Setup."); + } else { + EthNoLink = false; + } + } + + + switch (Ethernet.maintain()) { + case 1: + //renewed fail + Serial.println("Error: renewed fail"); + break; + + case 2: + //renewed success + Serial.println("Renewed success"); + //print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + digitalWrite(PIN_LED_RED, HIGH); + break; + + case 3: + //rebind fail + Serial.println("Error: rebind fail"); + break; + + case 4: + //rebind success + Serial.println("Rebind success"); + //print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + break; + + default: + //nothing happened + break; + } +}