I put together a few scripts to enable Terminal functionality on P4wnP1.
For developing the script, I actually used a RaspberryPi Zero 2. But it should work on RPi Zero W as well.
Testing to be done soon on Pi Zero W.
- termwrap.py - Adapted from a code snippet found somewhere
- Launches the scripts that do the actual work:
- wifi-pw-skiptest.py - Adapted from key_demo.py in SH1106 demo files (but by now it's its own beast, pretty much)
- Displays the "Enter Command" screen and takes text input using Joystick & buttons on OLED screen
- terminal.py - Adapted from terminal.py in luma.examples
- Runs the command
- Prints the output onto the OLED screen
What is TermWrap.py?
- Launches the "wifi-pw-skiptest.py" script to get text input from joystick and buttons on OLED screen
- Then runs the "terminal.py" script to execute the text input (command)
What is wifi-pw-skiptest.py?
This script displays an "Enter command" screen on the SH1106 OLED display.
Then it waits for the user to press the joystick to change characters (using the Left and Right joystick buttons).
Pressing the "Center" joystick button adds the current character to the line.
KEY1 (font-awesome keyboard icon) switches keyboard layouts:
-  The default layout is uppercase alphabet (A-Z)
-  Next is 0-9
-  Then the special characters (./!@#$%^&* etc)
- The SPACE character is currently located in this character set
-  Finally, we have lowercase alphabet (a-z)
KEY2 ("X") is the backspace key.
KEY3 (">") is the GO button.
What is terminal.py?
Terminal.py is an adaptation of the terminal.py script found in luma.examples repo.
The terminal.py from luma.examples utilizes a LOOP to display "lines" of text on the OLED screen.
But the text it displays is static - it's generated by simple code (resulting in "Line 1, Line 2, Line 3..").
So I simply replaced that part of the code to display lines of text from a TEXT FILE. This was way more interesting than just displaying lines being generated by code.
Now that we got the (excellent) terminal.py (from luma.examples) script to display dynamic content, we're ready to take the command input from the user and send it to terminal.py.
1. Take terminal.py from luma.examples
2. Find the loop that displays "Line 1, Line 2, Line 3"
3. Replace it with a loop to read lines from a text file
The result from changing this code was significant:
- The terminal.py script now shows output from any program - as long as that program is outputting to a text file.
Since getting programs to output to text in Linux is pretty easy, we can now display pretty much any program's output on our OLED screen.
Local file locations:
The following list of files are required to run P4wn-Term.
- wifi-pw-skiptest.py (to be renamed)
These files are in the main working folder (~/BeBoXGui/)
Disk image file:
P4wnP1 OLED Terminal Crontab Entry
@reboot cd /home/pi/BeBoXGui/ && /usr/bin/python3 /home/pi/BeBoXGui/termwrap.py
- Changes folders into the main working folder using crontab
- Then runs the P4wnP1 OLED Terminal wrapper
Current working directory:
pi@raspberrypi:~/BeBoXGui $ python3 wifi-pw-skiptest.py
Need to get termwrap and terminal2.py working in the same folder
Then get terminal2.py to read from text file
Then use that as the command to run in the terminal
Other file locations:
- Add space character (" ") between A and Z in A-Z uppercase AND lowercase charsets
- Add space character to 0-9 charset ?
- Thinking of a typical command (ping -c2 google.com), the spaces are after the A-Z and Numerical characters
- Move command-entry area to very bottom of screen
- (Priority #1) Have the script continue to read lines of text even after the last line was read (until the "X" key is pressed)
- (Priority #2) Have the command-entry area re-appear after no new lines in text file have been read for 2 or 3 seconds
- The purpose of this is to enable the user to input more text when a program pauses and asks for user input (such as Wifite and many other hacking programs for Linux)
- Optional cool add-on: Show a countdown / progress bar/line that fills from top of screen to bottom, to meet the command-entry area when it appears after X seconds of no more text output
- Add a few useful aliases
Aliases to Add
Side project idea - PiPod Shuffle:
Use a quick alias to play MP3 files randomly to mimic and iPod shuffle.
mplayer -loop 0 -shuffle $(cat your_playlist.m3u)
alias music='mplayer --shuffle *
- Mimic an iPod shuffle using this command:
Find a File
I can never remember the syntax for this command. So why not make an alias for it.
find /home -name *.jpg
Modify ping Behavior
I don't know why I'd do this, but I might:
# Stop after sending count ECHO_REQUEST packets #
alias ping='ping -c 5'
# Do not wait interval 1 second, go fast #
alias fastping='ping -c 100 -s.2'