Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pvcraven/networking_down_under
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Feb 2, 2021
2 parents 3d2544c + 1e3b546 commit 9a3a7c6
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 65 deletions.
10 changes: 5 additions & 5 deletions SendData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
public class SendData {

public static void main(String[] args) throws Exception {

InetAddress serverAddress = InetAddress.getByName("127.0.0.1");
int serverPort = 10000;
String myData = "Hello world!";

System.out.println("Connecting...");
Socket socket = new Socket(serverAddress, serverPort);

System.out.println("Connected, sending data...");

String myData = "Hello world!";
boolean autoFlush = true;
PrintWriter out = new PrintWriter(socket.getOutputStream(), autoFlush);
out.print(myData);
out.flush();

System.out.println("Done");
socket.close();

System.out.println("Done sending message.");
}
}
57 changes: 26 additions & 31 deletions ascii_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
line_height = 7

# List of characters
letters = []
characters = []

letter = """
character = """
###
# #
# #
Expand All @@ -18,9 +18,9 @@
# #
###
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
#
##
#
Expand All @@ -29,9 +29,9 @@
#
###
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
###
# #
#
Expand All @@ -40,9 +40,9 @@
#
#####
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
###
# #
#
Expand All @@ -51,9 +51,9 @@
# #
###
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
# #
# #
# #
Expand All @@ -62,9 +62,9 @@
#
#
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
#####
#
#
Expand All @@ -73,9 +73,9 @@
#
####
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
###
# #
#
Expand All @@ -84,9 +84,9 @@
# #
###
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
#####
#
#
Expand All @@ -95,9 +95,9 @@
#
#
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
###
# #
# #
Expand All @@ -106,9 +106,9 @@
# #
###
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
###
# #
# #
Expand All @@ -117,9 +117,9 @@
# #
###
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

letter = """
character = """
Expand All @@ -128,11 +128,10 @@
##
##
"""
letters.append(letter.split("\n"))
characters.append(character.split("\n"))

# Create a mapping of character letters, to letters in our list
mapping_characters = "0123456789."
mapping_indexes = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10


def print_string(input_string: str):
Expand All @@ -144,18 +143,14 @@ def print_string(input_string: str):

# Create a list that, instead of the string, has the index locations
# of our banner characters. So instead of "1.2" we have [1, 10, 2]
index_locations = []
for character in input_string:
if character in mapping_characters:
my_index = mapping_characters.index(character)
index_locations.append(my_index)
index_locations = [mapping_characters.index(character) for character in input_string]

# Now loop through each line
for line_no in range(1, line_height + 1):
# Loop though each index location to print
for character in index_locations:
for index_location in index_locations:
# Print that line of the character
print(letters[character][line_no], end=" ")
print(characters[index_location][line_no], end=" ")
# Go to the next line
print()

Expand Down
32 changes: 32 additions & 0 deletions decode_message_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import time
import RPi.GPIO as GPIO

CLOCK_CHANNEL = 16
DATA_CHANNEL = 23

# This is a callback function that will be called whenever we have a high/low
# or low/high change in the signal.
def my_callback(channel):
result = GPIO.input(DATA_CHANNEL);
if result:
print("1")
else:
print("0")

# Set pin 12 up for input
GPIO.setmode(GPIO.BCM)
GPIO.setup(CLOCK_CHANNEL, GPIO.IN)
GPIO.setup(DATA_CHANNEL, GPIO.IN)

# Now we have to 'register' the callback function so that the GPIO library
# will call the function when the change occurs on pin 12.
# GPIO.BOTH means it is called on both rising and falling changes.
# Use GPIO.FALLING if you want it called for high to low
# Use GPIO.RISING if you want it called low to high
GPIO.add_event_detect(CLOCK_CHANNEL, GPIO.FALLING, callback=my_callback)

# Now just wait forever.
print("Running")
while True:
time.sleep(10)
print("Still running")
39 changes: 39 additions & 0 deletions decode_message_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import time
import RPi.GPIO as GPIO

CLOCK_CHANNEL = 16
DATA_CHANNEL = 23

# This is a callback function that will be called whenever we have a high/low
# or low/high change in the signal.
def my_callback(channel):
result = GPIO.input(DATA_CHANNEL);
if result:
print("1", end="")
else:
print("0", end="")

my_callback.counter += 1
if my_callback.counter > 7:
print()
my_callback.counter = 0

my_callback.counter = 0

# Set pin 12 up for input
GPIO.setmode(GPIO.BCM)
GPIO.setup(CLOCK_CHANNEL, GPIO.IN)
GPIO.setup(DATA_CHANNEL, GPIO.IN)

# Now we have to 'register' the callback function so that the GPIO library
# will call the function when the change occurs on pin 12.
# GPIO.BOTH means it is called on both rising and falling changes.
# Use GPIO.FALLING if you want it called for high to low
# Use GPIO.RISING if you want it called low to high
GPIO.add_event_detect(CLOCK_CHANNEL, GPIO.FALLING, callback=my_callback)

# Now just wait forever.
print("Running")
while True:
time.sleep(10)
print("Still running")
42 changes: 42 additions & 0 deletions decode_message_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import time
import RPi.GPIO as GPIO

CLOCK_CHANNEL = 16
DATA_CHANNEL = 23

# This is a callback function that will be called whenever we have a high/low
# or low/high change in the signal.
def my_callback(channel):
result = GPIO.input(DATA_CHANNEL);
if result:
print("1", end="")
my_callback.result_byte += 1 << (7 - my_callback.counter)
else:
print("0", end="")

my_callback.counter += 1
if my_callback.counter > 7:
print(" = {} = {}".format(my_callback.result_byte, chr(my_callback.result_byte)))
my_callback.counter = 0
my_callback.result_byte = 0

my_callback.counter = 0
my_callback.result_byte = 0

# Set pin 12 up for input
GPIO.setmode(GPIO.BCM)
GPIO.setup(CLOCK_CHANNEL, GPIO.IN)
GPIO.setup(DATA_CHANNEL, GPIO.IN)

# Now we have to 'register' the callback function so that the GPIO library
# will call the function when the change occurs on pin 12.
# GPIO.BOTH means it is called on both rising and falling changes.
# Use GPIO.FALLING if you want it called for high to low
# Use GPIO.RISING if you want it called low to high
GPIO.add_event_detect(CLOCK_CHANNEL, GPIO.FALLING, callback=my_callback)

# Now just wait forever.
print("Running")
while True:
time.sleep(60)
print("Still running")
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cherrypy
pillow
colorama
colorama
lxml
5 changes: 5 additions & 0 deletions send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
port = 465
server_name = "smtp.gmail.com"

# Setting the debug level to 1 will output everything that is sent to,
# or recevied from the server
debug_level = 1

username = input("Enter your username: ")
password = input("Type your password: ")
destination_address = input("Enter destination email address: ")
Expand All @@ -17,5 +21,6 @@
context = ssl.create_default_context()

with smtplib.SMTP_SSL(server_name, port, context=context) as server:
server.set_debuglevel(debug_level)
server.login(username, password)
server.sendmail(username, destination_address, message)
Loading

0 comments on commit 9a3a7c6

Please sign in to comment.