can't convert socket received data to float

Viewed 50

I have a socket client sending some values ​​to my raspberry pi robot but when I receive them I can print the value in the console but I cant convert it to a float. Transmitted data example: -0.47 or 0.23

raspberry pi code:

import socket

serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
serverSocket.bind(("192.168.1.182",9090));
serverSocket.listen();

def main():
    
    (clientConnected, clientAddress) = serverSocket.accept();
    dataFromClient = clientConnected.recv(1024)
    data = dataFromClient.decode()
    curve = float(data)
    print(curve)


if __name__ == '__main__':
    while True:
        main()

client code:

import socket

clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
clientSocket.connect(("192.168.1.182", 9090));
clientSocket.send(bytes(curve, "utf-8"));
print(curve)

The curve value is a float between 1.00 and -1.00

The error of the server code is: ValueError: could not convert string to float:

examples for curve value: -0.33 0.75 0.25 -0.58

0 Answers
Related