eSecretary

Presentation Pi:

pip3 install pygame
sudo nano number.txt
audio/... audio files
xvfb-run -a python3 welcome.py

welcome2.py
import RPi.GPIO as GPIO
import time
import pygame
import subprocess
import paramiko

# Initialize pygame for audio playback
pygame.init()
audnum = "audio/oneara.mp3"
audnum2 = "audio/oneeng.mp3"
scrnum = "wel_script/number1.sh"
digit=[1,1,1,1,1,1,0]
pi2_ip_address = "192.168.86.32"
private_key_path = "/home/pi/.ssh/sshkey"
passphrase = "sshkey"

try:
with open('number.txt', 'r') as file:
content = file.read()
number = int(content)
print(content)
except FileNotFoundError:
print("File not found.")


# Set up the GPIO pins
BUTTON_PIN = 12 # Change this to the pin you are using
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#setup output pins
GPIO.setup(36, GPIO.OUT)
GPIO.setup(38, GPIO.OUT)
GPIO.setup(29, GPIO.OUT)
GPIO.setup(31, GPIO.OUT)
GPIO.setup(33, GPIO.OUT)
GPIO.setup(35, GPIO.OUT)
GPIO.setup(37, GPIO.OUT)

#GPIO.setup(11, GPIO.OUT)
#GPIO.setup(13, GPIO.OUT)

#define 7 segment digits
digitclr=[0,0,0,0,0,0,0]
digit0=[1,1,1,1,1,1,0]
digit1=[0,1,1,0,0,0,0]
digit2=[1,1,0,1,1,0,1]
digit3=[1,1,1,1,0,0,1]
digit4=[0,1,1,0,0,1,1]
digit5=[1,0,1,1,0,1,1]
digit6=[1,0,1,1,1,1,1]
digit7=[1,1,1,0,0,0,0]
digit8=[1,1,1,1,1,1,1]
digit9=[1,1,1,0,0,1,1]
gpin=[36,38,29,31,33,35,37]


def turn_led_on():
try:
# Create an SSH client instance
ssh = paramiko.SSHClient()

# Automatically add the server's host key (insecure, use known_hosts fi$
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Load the private key and set the passphrase
private_key = paramiko.RSAKey.from_private_key_file(private_key_path, password=passphrase)

# Connect to Pi2 using the private key with passphrase
ssh.connect(pi2_ip_address, username="pi", pkey=private_key)

# Run the LED control code on Pi2
stdin, stdout, stderr = ssh.exec_command("python -c 'import RPi.GPIO as GPIO; from time import sleep; GPIO.setmode(GPIO.BOARD); GPIO.setup(16, GPIO.OUT); GPIO.output(16, GPIO.HIGH); sleep(2); GPIO.cleanup()'")

# Wait for the command to finish
stdout.channel.recv_exit_status()

# Close the SSH connection
ssh.close()
except Exception as e:
print(f"An error occurred: {e}")


#routine to clear and then write to display
def digdisp(digit):
for x in range (0,7):
GPIO.output(gpin[x], digitclr[x])
for x in range (0,7):
GPIO.output(gpin[x], digit[x])

# Function to play audio
def play_audio(file_path):
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
time.sleep(1)

# Main loop
try:
while True:
button_state = GPIO.input(BUTTON_PIN)
if number == 1:
audnum = "audio/oneara.mp3"
audnum2 = "audio/oneeng.mp3"
scrnum = "wel_scripts/number1.sh"
digit=[0,1,1,0,0,0,0]
if number == 2:
audnum = "audio/twoara.mp3"
audnum2 = "audio/twoeng.mp3"
scrnum = "wel_scripts/number2.sh"
digit=[1,1,0,1,1,0,1]
if number == 3:
audnum = "audio/threeara.mp3"
audnum2 = "audio/threeeng.mp3"
scrnum = "wel_scripts/number3.sh"
digit=[1,1,1,1,0,0,1]
if number == 4:
audnum = "audio/fourara.mp3"
audnum2 = "audio/foureng.mp3"
scrnum = "wel_scripts/number4.sh"
digit=[0,1,1,0,0,1,1]
if number == 5:
audnum = "audio/fiveara.mp3"
audnum2 = "audio/fiveeng.mp3"
scrnum = "wel_scripts/number5.sh"
digit=[1,0,1,1,0,1,1]
if number == 6:
audnum = "audio/sixara.mp3"
audnum2 = "audio/sixeng.mp3"
scrnum = "wel_scripts/number6.sh"
digit=[1,0,1,1,1,1,1]
if number == 7:
audnum = "audio/sevenara.mp3"
audnum2 = "audio/seveneng.mp3"
scrnum = "wel_scripts/number7.sh"
digit=[1,1,1,0,0,0,0]
if number == 8:
audnum = "audio/eightara.mp3"
audnum2 = "audio/eighteng.mp3"
scrnum = "wel_scripts/number8.sh"
digit=[1,1,1,1,1,1,1]
if number == 9:
audnum = "audio/nineara.mp3"
audnum2 = "audio/nineeng.mp3"
scrnum = "wel_scripts/number9.sh"
digit=[1,1,1,0,0,1,1]
if number == 10:
number = 1
audnum = "audio/oneara.mp3"
audnum2 = "audio/oneeng.mp3"
scrnum = "wel_scripts/number1.sh"
digit=[0,1,1,0,0,0,0]

if button_state == True:
subprocess.Popen(["bash", scrnum])
digdisp(digit)
time.sleep(1)
for x in range (0,7):
GPIO.output(gpin[x], digitclr[x])
time.sleep(1)
digdisp(digit)

play_audio("audio/ticketara.mp3")
play_audio(audnum)
play_audio("audio/sitara.mp3")
play_audio("audio/ticketeng.mp3")
play_audio(audnum2)
play_audio("audio/siteng.mp3")
number = number + 1
strnum = str(number)
with open("number.txt", "w") as file:
file.write(strnum)
while pygame.mixer.music.get_busy(): # Wait for the audio to finish playing
time.sleep(1)
for x in range (0,7):
GPIO.output(gpin[x], digitclr[x])
time.sleep(1)
turn_led_on()

time.sleep(0.1) # Small delay to debounce the button

finally:
GPIO.cleanup()

guestenter.py

import RPi.GPIO as GPIO
import time
import pygame
import subprocess
import paramiko

# Initialize pygame for audio playback
pygame.init()
audnum = "audio/oneara.mp3"
audnum2 = "audio/oneeng.mp3"
scrnum = "wel_script/number1.sh"
digit=[1,1,1,1,1,1,0]
#pi2_ip_address = "192.168.86.32"
#private_key_path = "/home/pi/.ssh/sshkey"
#passphrase = "sshkey"

try:
with open('numero.txt', 'r') as file:
content = file.read()
number = int(content)
print(content)
except FileNotFoundError:
print("File not found.")


# Set up the GPIO pins
BUTTON_PIN = 12 # Change this to the pin you are using
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#setup output pins
GPIO.setup(36, GPIO.OUT)
GPIO.setup(38, GPIO.OUT)
GPIO.setup(29, GPIO.OUT)
GPIO.setup(31, GPIO.OUT)
GPIO.setup(33, GPIO.OUT)
GPIO.setup(35, GPIO.OUT)
GPIO.setup(37, GPIO.OUT)

#GPIO.setup(11, GPIO.OUT)
#GPIO.setup(13, GPIO.OUT)

#define 7 segment digits
digitclr=[0,0,0,0,0,0,0]
digit0=[1,1,1,1,1,1,0]
digit1=[0,1,1,0,0,0,0]
digit2=[1,1,0,1,1,0,1]
digit3=[1,1,1,1,0,0,1]
digit4=[0,1,1,0,0,1,1]
digit5=[1,0,1,1,0,1,1]
digit6=[1,0,1,1,1,1,1]
digit7=[1,1,1,0,0,0,0]
digit8=[1,1,1,1,1,1,1]
digit9=[1,1,1,0,0,1,1]
gpin=[36,38,29,31,33,35,37]


def turn_led_on():
try:
# Create an SSH client instance
ssh = paramiko.SSHClient()

# Automatically add the server's host key (insecure, use known_hosts fi$
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Load the private key and set the passphrase
private_key = paramiko.RSAKey.from_private_key_file(private_key_path, password=passphrase)

# Connect to Pi2 using the private key with passphrase
ssh.connect(pi2_ip_address, username="pi", pkey=private_key)

# Run the LED control code on Pi2
stdin, stdout, stderr = ssh.exec_command("python -c 'import RPi.GPIO as GPIO; from time import sleep; GPIO.setmode(GPIO.BOARD); GPIO.setup(16, GPIO.OUT); GPIO.output(16, GPIO.HIGH); sleep(2); GPIO.cleanup()'")

# Wait for the command to finish
stdout.channel.recv_exit_status()

# Close the SSH connection
ssh.close()
except Exception as e:
print(f"An error occurred: {e}")


#routine to clear and then write to display
def digdisp(digit):
for x in range (0,7):
GPIO.output(gpin[x], digitclr[x])
for x in range (0,7):
GPIO.output(gpin[x], digit[x])

# Function to play audio
def play_audio(file_path):
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
time.sleep(1)

# Main loop
try:
while True:
button_state = GPIO.input(BUTTON_PIN)
if number == 1:
audnum = "audio/oneara.mp3"
audnum2 = "audio/oneeng.mp3"
scrnum = "wel_scripts/number1.sh"
digit=[0,1,1,0,0,0,0]
if number == 2:
audnum = "audio/twoara.mp3"
audnum2 = "audio/twoeng.mp3"
scrnum = "wel_scripts/number2.sh"
digit=[1,1,0,1,1,0,1]
if number == 3:
audnum = "audio/threeara.mp3"
audnum2 = "audio/threeeng.mp3"
scrnum = "wel_scripts/number3.sh"
digit=[1,1,1,1,0,0,1]
if number == 4:
audnum = "audio/fourara.mp3"
audnum2 = "audio/foureng.mp3"
scrnum = "wel_scripts/number4.sh"
digit=[0,1,1,0,0,1,1]
if number == 5:
audnum = "audio/fiveara.mp3"
audnum2 = "audio/fiveeng.mp3"
scrnum = "wel_scripts/number5.sh"
digit=[1,0,1,1,0,1,1]
if number == 6:
audnum = "audio/sixara.mp3"
audnum2 = "audio/sixeng.mp3"
scrnum = "wel_scripts/number6.sh"
digit=[1,0,1,1,1,1,1]
if number == 7:
audnum = "audio/sevenara.mp3"
audnum2 = "audio/seveneng.mp3"
scrnum = "wel_scripts/number7.sh"
digit=[1,1,1,0,0,0,0]
if number == 8:
audnum = "audio/eightara.mp3"
audnum2 = "audio/eighteng.mp3"
scrnum = "wel_scripts/number8.sh"
digit=[1,1,1,1,1,1,1]
if number == 9:
audnum = "audio/nineara.mp3"
audnum2 = "audio/nineeng.mp3"
scrnum = "wel_scripts/number9.sh"
digit=[1,1,1,0,0,1,1]
if number == 10:
number = 1
audnum = "audio/oneara.mp3"
audnum2 = "audio/oneeng.mp3"
scrnum = "wel_scripts/number1.sh"
digit=[0,1,1,0,0,0,0]

if button_state == False:
subprocess.Popen(["bash", scrnum])
digdisp(digit)
time.sleep(1)
for x in range (0,7):
GPIO.output(gpin[x], digitclr[x])
time.sleep(1)
digdisp(digit)

play_audio("audio/guestara.mp3")
play_audio(audnum)
play_audio("audio/comeinara.mp3")
play_audio("audio/guesteng.mp3")
play_audio(audnum2)
play_audio("audio/comeineng.mp3")
number = number + 1
strnum = str(number)
with open("numero.txt", "w") as file:
file.write(strnum)
while pygame.mixer.music.get_busy(): # Wait for the audio to finish playing
time.sleep(1)
for x in range (0,7):
GPIO.output(gpin[x], digitclr[x])
time.sleep(1)
#turn_led_on()

time.sleep(0.1) # Small delay to debounce the button

finally:
GPIO.cleanup()

Office Pi:

comein.py
import RPi.GPIO as GPIO
import time
import subprocess
import paramiko

# Initialize pygame for audio playback
pi2_ip_address = "192.168.86.33"
private_key_path = "/home/pi/.ssh/ssh_key"
passphrase = "ssh_key"

# Set up the GPIO pins
BUTTON_PIN = 12 # Change this to the pin you are using
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def remote():
try:
# Create an SSH client instance
ssh = paramiko.SSHClient()

# Automatically add the server's host key (insecure, use known_hosts fi$
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Load the private key and set the passphrase
private_key = paramiko.RSAKey.from_private_key_file(private_key_path, password=passphrase)

# Connect to Pi2 using the private key with passphrase
ssh.connect(pi2_ip_address, username="pi", pkey=private_key)

# Run the LED control code on Pi2
stdin, stdout, stderr = ssh.exec_command("python3 /home/pi/guestenter.py")

# Wait for the command to finish
stdout.channel.recv_exit_status()

# Close the SSH connection
ssh.close()
except Exception as e:
print(f"An error occurred: {e}")



# Main loop
remote()
try:
while True:
button_state = GPIO.input(BUTTON_PIN)
if button_state == False:
remote()
time.sleep(0.1) # Small delay to debounce the button

finally:
GPIO.cleanup()