Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Socket comm with a Raspberry Pi Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: October 24 2020 at 15:04 | IP Logged Quote gg102

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 View gg102's Profile Search for other posts by gg102
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: December 14 2020 at 12:27 | IP Logged Quote gg102

Dave,
any thoughts on how to do socket comm?

Thanks.
Back to Top View gg102's Profile Search for other posts by gg102
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 16 2020 at 22:34 | IP Logged Quote dhoward

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 View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum