I have a normal TCP client connection which I use to retrieve data from a climate sensor (SCD30). In theory, it does what it is supposed to do, but I always get different numbers of bytes.
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as tcp:
try:
tcp.settimeout(self.timeout)
tcp.connect((self.ip, self.port))
tcp.settimeout(None)
tcp.sendall(b"\x61\x03\x00\x20\x00\x01\x8c\x60")
data = tcp.recv(self.bytes)
tcp.close()
The correct response is:
b'a\x03\x02\x03B\xb8\x8d'
Bytes: 7
what else I received:
b'a'
Bytes: 1
b'a\x03'
Bytes: 2
b'\x02\x03B\xb8\x8da\x03\x02\x03B\xb8\x8d'
Bytes: 12
b'\x03\x02\x03B\xb8\x8d'
Bytes: 6