Compare commits
10 Commits
fffd62f219
...
beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf2775e395 | ||
|
|
894d83bcd6 | ||
|
|
87338d4db1 | ||
| 347bc54818 | |||
|
|
1f932b223b | ||
|
|
b3ade2db86 | ||
|
|
0654c19fac | ||
|
|
9cbbfc12bc | ||
| 1d7e56f837 | |||
|
|
d0fd9a0c94 |
74
.gitignore
vendored
Normal file
74
.gitignore
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### macOS Patch ###
|
||||
# iCloud generated files
|
||||
*.icloud
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
15
README.md
15
README.md
@@ -7,4 +7,17 @@
|
||||
- Raspian/Debian
|
||||
- Python 3
|
||||
- Python 3 Requets
|
||||
- Python 3 RPi.GPIO
|
||||
- Python 3 RPi.GPIO
|
||||
|
||||
## Install instructions
|
||||
|
||||
- Downloand script into /usr/local/bin/
|
||||
- Download rrcs-trigger file and place into /usr/local/bin/
|
||||
- Download rrcs-trigger.service and place it into /etc/systemd/system/
|
||||
- Run the follwoing commands to enable the service on boot. ```sudo systemctl enable rrcs-trigger.service``` and ```sudo systemctl start rrcs-trigger.service```
|
||||
- Run the following command to see how its booting up. ```watch systemctl status rrcs-triggers.service```
|
||||
|
||||
- Modify the script to have your RRCS Server IP address and port.
|
||||
|
||||
## Logging
|
||||
- All logs are printed to journalctl, this includes when the button is pressed.
|
||||
39
arduino/RRCS.h
Executable file
39
arduino/RRCS.h
Executable file
@@ -0,0 +1,39 @@
|
||||
const char Data_PressVirtKey1OnBench_P[] PROGMEM = "<?xml version=\"1.0\"?>\
|
||||
<methodCall>\
|
||||
<methodName>PressKeyEx</methodName>\
|
||||
<params>\
|
||||
<param><value><string>C0000000001</string></value></param>\
|
||||
<param><value><i4>64</i4></value></param>\
|
||||
<param><value><i4>46</i4></value></param>\
|
||||
<param><value><boolean>0</boolean></value></param>\
|
||||
<param><value><int>2</int></value></param>\
|
||||
<param><value><int>0</int></value></param>\
|
||||
<param><value><int>1</int></value></param>\
|
||||
<param><value><boolean>1</boolean></value></param>\
|
||||
<param><value><boolean>1</boolean></value></param>\
|
||||
<param><value><int>1</int></value></param>\
|
||||
</params>\
|
||||
</methodCall>\
|
||||
";
|
||||
|
||||
const char Data_ReleaseVirtKey1OnBench_P[] PROGMEM = "<?xml version=\"1.0\"?>\
|
||||
<methodCall>\
|
||||
<methodName>PressKeyEx</methodName>\
|
||||
<params>\
|
||||
<param><value><string>C0000000002</string></value></param>\
|
||||
<param><value><i4>64</i4></value></param>\
|
||||
<param><value><i4>46</i4></value></param>\
|
||||
<param><value><boolean>0</boolean></value></param>\
|
||||
<param><value><int>2</int></value></param>\
|
||||
<param><value><int>0</int></value></param>\
|
||||
<param><value><int>1</int></value></param>\
|
||||
<param><value><boolean>1</boolean></value></param>\
|
||||
<param><value><boolean>0</boolean></value></param>\
|
||||
<param><value><int>1</int></value></param>\
|
||||
</params>\
|
||||
</methodCall>\
|
||||
";
|
||||
|
||||
__FlashStringHelper* Data_PressVirtKey1OnBench = (__FlashStringHelper*)Data_PressVirtKey1OnBench_P;
|
||||
__FlashStringHelper* Data_ReleaseVirtKey1OnBench = (__FlashStringHelper*)Data_ReleaseVirtKey1OnBench_P;
|
||||
|
||||
210
arduino/TrafficQLXArduino.ino
Executable file
210
arduino/TrafficQLXArduino.ino
Executable file
@@ -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 <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
33
ras_pi_RRCS_BusyLight.py
Normal file → Executable file
33
ras_pi_RRCS_BusyLight.py
Normal file → Executable file
@@ -1,16 +1,18 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
os.environ['RPI_LGPIO_REVISION'] = "800012"
|
||||
|
||||
import time
|
||||
import requests
|
||||
import RPi.GPIO as GPIO
|
||||
import socket
|
||||
|
||||
|
||||
RED = "\033[91m"
|
||||
GREEN = "\033[92m"
|
||||
RESET = "\033[0m"
|
||||
|
||||
|
||||
BenBusyRRCSdataRising = '''<?xml version="1.0"?>
|
||||
PressVirtKey1OnBench = '''<?xml version="1.0"?>
|
||||
<methodCall>
|
||||
<methodName>PressKeyEx</methodName>
|
||||
<params>
|
||||
@@ -28,7 +30,7 @@ BenBusyRRCSdataRising = '''<?xml version="1.0"?>
|
||||
</methodCall>
|
||||
'''
|
||||
|
||||
BenBusyRRCSdataFalling = '''<?xml version="1.0"?>
|
||||
ReleasePressVirtKey1OnBench = '''<?xml version="1.0"?>
|
||||
<methodCall>
|
||||
<methodName>PressKeyEx</methodName>
|
||||
<params>
|
||||
@@ -49,26 +51,19 @@ BenBusyRRCSdataFalling = '''<?xml version="1.0"?>
|
||||
def button_callback(channel):
|
||||
if GPIO.input(channel):
|
||||
print(f"{RED}Button pressed{RESET}")
|
||||
r = requests.post(
|
||||
'http://10.75.120.229:8193',
|
||||
headers={'content-type': 'text/xml'},
|
||||
data=BenBusyRRCSdataRising
|
||||
)
|
||||
else:
|
||||
r = requests.post('http://10.75.120.229:8193',headers={'content-type': 'text/xml'},data=PressVirtKey1OnBench)
|
||||
time.sleep(0.05)
|
||||
print(f"{GREEN}Button released{RESET}")
|
||||
r = requests.post(
|
||||
'http://10.75.120.229:8193',
|
||||
headers={'content-type': 'text/xml'},
|
||||
data=BenBusyRRCSdataFalling
|
||||
)
|
||||
print(r.text)
|
||||
|
||||
r = requests.post('http://10.75.120.229:8193',headers={'content-type': 'text/xml'},data=ReleasePressVirtKey1OnBench)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
# One event detector, both edges:
|
||||
GPIO.add_event_detect(12, GPIO.BOTH, callback=button_callback, bouncetime=200)
|
||||
GPIO.add_event_detect(12, GPIO.RISING, callback=button_callback, bouncetime=200)
|
||||
|
||||
input("Press enter to quit\n\n")
|
||||
print("RRCS-Trigger ready for input")
|
||||
[sockA, sockB] = socket.socketpair()
|
||||
junk = sockA.recv(1) # will never return since sockA will never receive any data
|
||||
|
||||
print("This should never get printed")
|
||||
GPIO.cleanup()
|
||||
2
rrcs-trigger
Executable file
2
rrcs-trigger
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
exec /usr/bin/python3 /usr/local/bin/ras_pi_RRCS_BusyLight.py
|
||||
18
rrcs-trigger.service
Executable file
18
rrcs-trigger.service
Executable file
@@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=Runs the ras_pi_RRCS_BusyLight.py script at boot
|
||||
After=network.target
|
||||
#StartLimitIntervalSec=5
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/rrcs-trigger /usr/local/bin/ras_pi_RRCS_BusyLight.py
|
||||
WorkingDirectory=/tmp
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user