Author |
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: October 24 2020 at 15:04 | IP Logged
|
|
|
Hi Dave,
It's good to be back with everyone.
So far, I have been communicating with my Raspberry pi/s by dropping files on the pi/s and/or PH. This mostly works, but it is quite clumsy and not very reliable.
I am seeking a more reliable communication method. So I thought to try socket comms.
I have tried the following code to test:
PH
--------------------------------------------------
Formula: ph_sendsocketdata('192.168.3.YYY', 8500,"Hello from PH_Server." )
Raspberry Pi :
--------------------------------------------------
#!/usr/bin/env python3
import socket
HOST = '192.168.3.XXX' # Address of PH
PORT = 8500 # Port of PH
client = socket.socket(soc ket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST,PORT))
from_server = client.recv(4096)
client.send("I am Pi")
print ("From Server: " + from_server)
client.close()
What happens with this test setup is that PH times out, and the pi crashes on client.recv(...). I'm guessing that the socket never gets created, thus any attempt to comm will fail.
I'd like to hear your thoughts.
Thanks,
P.S. I think I fixed my private email address.
gg
|
Back to Top |
|
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: December 14 2020 at 12:27 | IP Logged
|
|
|
Dave,
any thoughts on how to do socket comm?
Thanks.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 16 2020 at 22:34 | IP Logged
|
|
|
gg,
Im not completely up on Python on the Raspberry Pi but looking at the code you've pasted, it looks like you're trying to open socket client on
the Pi when you probably need to open a socket server. The ph_sendsocketdata from PowerHome is a client socket that needs to connect to a
socket that is listening for a connection.
The Raspberry Pi code socket is also trying to connect to a server. Typically, I would expect you to open a socket and then do a "Listen" vs a
connect.
Dave.
|
Back to Top |
|
|