Skip to content

Commit

Permalink
Add Documentation to WifiReader
Browse files Browse the repository at this point in the history
  • Loading branch information
harith-abeysinghe committed Sep 20, 2023
1 parent 51fe1cd commit 32c699a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Driver/src/WifiReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def __init__(self, host):
self.host = host

def scan(self):
"""
Scan and retrieve the IP address of the local machine.
Returns:
str: The IP address of the local machine.
"""
# Get the hostname of the local machine
hostname = socket.gethostname()

Expand All @@ -26,6 +32,12 @@ def scan(self):
return ip

def connect(self):
"""
Establish a socket server and listen for incoming connections.
Returns:
bool: True if the server is successfully started, False otherwise.
"""
try:
ip = self.scan()

Expand All @@ -46,6 +58,12 @@ def connect(self):
return False

def disconnect(self):
"""
Disconnect the client socket and close the server socket.
Returns:
bool: True if disconnection is successful, False otherwise.
"""
try:
if self.server:
self.clientsocket.close()
Expand All @@ -57,6 +75,12 @@ def disconnect(self):
return False

def read(self):
"""
Read data from the connected client socket.
Returns:
str or False: The read data as a string if available, or False if an error occurs.
"""
try:
self.clientsocket, self.clientip = self.server.accept()
data = self.clientsocket.recv(1)
Expand All @@ -65,4 +89,12 @@ def read(self):
return False
except Exception as e:
print(f"Error Reading: {str(e)}")
return False
return False

# Example usage:
# reader = ESPWifiReader("0.0.0.0")
# if reader.connect():
# data = reader.read()
# # Process the received data
# print(f"Received data: {data}")
# reader.disconnect()

0 comments on commit 32c699a

Please sign in to comment.