Skip to content

Commit

Permalink
edited main.py with tcp
Browse files Browse the repository at this point in the history
  • Loading branch information
aspothuri committed Apr 24, 2024
1 parent 818c7f7 commit 698d3d0
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cv2
import serial
import socket
import cv2

"""
camera
Expand All @@ -8,23 +9,45 @@
navigation algorithm
"""

# def main():
# ser = serial.Serial('/dev/ttyUSB0', 9600)
#
# try:
# distance = True
# while True:
# data = ser.readline().decode().strip()
# if distance:
# print("Distance:", data)
# distance = not distance
# else:
# print("Strength:", data)
# distance = not distance
# except KeyboardInterrupt:
# ser.close()




HOST = "10.138.148.113"
PORT = 65432

def main():
ser = serial.Serial('/dev/ttyUSB0', 9600)

try:
data = ser.readline().decode().strip()
distance = True
while True:
data = ser.readline().decode().strip()
if distance:
print("Distance:", data)
distance = not distance
else:
print("Strength:", data)
distance = not distance
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
message = f"{data},{distance}"
s.sendall(message.encode())
distance = not distance
data = s.recv(1024)
except KeyboardInterrupt:
ser.close()

print(f"Received {data!r}")


if __name__ == "__main__":
main()

0 comments on commit 698d3d0

Please sign in to comment.