dumb question but I'm really stuck...
I can read localhost (ebusd) from shell with netcat command:
user@raspberrypi:~ $ echo r -c 700 AdaptHeatCurve | nc -q 1 127.0.0.1 8888
no
The response received "no" is correct.
But trying to do same thing from python - just returns empty string. And seems no connection errors. Here is code:
#function to read ebusd value
def readValue(circuit, field):
content = "read -c 700 AdaptHeatCurve"
print("debug1")
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
sock.connect(('127.0.0.1', 8888))
except socket.error as msge:
print ("connection failed error :", msge)
print("debug2" )
try:
sock.sendall(content.encode())
except socket.error as msge:
print ("sendall failed error :", msge)
print("debug3" )
time.sleep(5)
print("debug4" )
sock.shutdown(socket.SHUT_WR)
print("debug5" )
res = ""
while True:
data = sock.recv(1024)
if (not data):
break
print("readvalue: ",repr(data))
sock.close()
The output of above:
(myTestServer) user@raspberrypi:~ $ python3 myTestServer/testServer.py
debug1
debug2
debug3
debug4
debug5
readvalue: b''
Anybopdy could point what is wrong? ( I'm novice - dumb things possible)
I can read localhost (ebusd) from shell with netcat command:
user@raspberrypi:~ $ echo r -c 700 AdaptHeatCurve | nc -q 1 127.0.0.1 8888
no
The response received "no" is correct.
But trying to do same thing from python - just returns empty string. And seems no connection errors. Here is code:
#function to read ebusd value
def readValue(circuit, field):
content = "read -c 700 AdaptHeatCurve"
print("debug1")
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
sock.connect(('127.0.0.1', 8888))
except socket.error as msge:
print ("connection failed error :", msge)
print("debug2" )
try:
sock.sendall(content.encode())
except socket.error as msge:
print ("sendall failed error :", msge)
print("debug3" )
time.sleep(5)
print("debug4" )
sock.shutdown(socket.SHUT_WR)
print("debug5" )
res = ""
while True:
data = sock.recv(1024)
if (not data):
break
print("readvalue: ",repr(data))
sock.close()
The output of above:
(myTestServer) user@raspberrypi:~ $ python3 myTestServer/testServer.py
debug1
debug2
debug3
debug4
debug5
readvalue: b''
Anybopdy could point what is wrong? ( I'm novice - dumb things possible)
Statistics: Posted by karne — Tue Oct 08, 2024 8:18 am — Replies 2 — Views 50