28 lines
627 B
Python
28 lines
627 B
Python
import socket
|
|
import time
|
|
import math as np
|
|
|
|
SERVER_IP = "pistudent7"
|
|
SERVER_PORT = 8080
|
|
|
|
|
|
def send_distance():
|
|
x = 0
|
|
while True:
|
|
try:
|
|
distance_cm = abs(np.sin(x)) * 100
|
|
message = f"DISTANCE:{distance_cm:.2f}cm"
|
|
with socket.socket() as sock:
|
|
sock.connect((SERVER_IP, SERVER_PORT))
|
|
sock.sendall(message.encode())
|
|
print(f"Sent: {message}")
|
|
|
|
time.sleep(1)
|
|
x = x + .1
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
time.sleep(5)
|
|
|
|
if __name__ == "__main__":
|
|
send_distance()
|